Manipulating a RS232 Data Stream - Sample Script: CharacterManipulation.pts

<< Click to Display Table of Contents >>

Navigation:  Examples and Tutorials (Scripting) >

Manipulating a RS232 Data Stream - Sample Script: CharacterManipulation.pts

The Docklight script CharacterManipulation.pts demonstrates how to manipulate a RS232 data stream using the DL_OnReceive() event procedure. All data received on the RX line is sent out again on the TX line, but with some of the characters replaced.


Getting started


Open the project file CharacterManipulationPrj.ptp (using the OPEN Open Project ... menu) and the script file CharacterManipulation.pts (using the Open Script ... menu). The files are located in the \ScriptSamples folder.

Go to the PROPERTIES Project Settings... dialog and choose a COM port.

Press the Startscript_new Run Script button in the toolbar.

Start a second instance of Docklight and open the project file CharacterManipulationTest.ptp.

Choose a different COM port for this second Docklight instance (or even use another computer).

Connect the two COM ports using a simple null modem cable. Or use a virtual null modem instead.

Use the Pt_Send_Button Send button on the second instance of Docklight to send the test sentence.


The communication display of the second instance of Docklight should look similar to this:


2/21/2009 11:56:57.343 [TX] - This is a test for the character manipulation sample script

2/21/2009 11:56:57.502 [RX] - Dhis is a desd for dhe characder manibuladion samble scribd


Each "T" is replaced by a "D", and each "P" is replaced by a "B". (Visitors to the Nuremberg area, where our company is located, might notice that dialect speakers here do something similar...)


Further Information


The sample uses the DL_OnReceive() event procedure to perform additional operations each time a new character is received. See Evaluating Receive Sequence Data for more details.

The performance of a character-by-character processor in Docklight Scripting is quite limited. You can easily overload it by sending a constant flow of data. Docklight will display a comment in the communication window in this case, e.g.

DOCKLIGHT reports: Input buffer overflow on COM1

For performance reasons, all TX and RX data display is disabled in CharacterManipulationPrj.ptp

If you are thinking of writing a manipulator for your own protocol, consider a packet-based approach, where one Receive Sequence can detect a whole packet or command from your protocol. This will allow higher data rates than the character-based approach presented here.