|
Creating and Detecting Inter-Character Delays (Scripting) |
|
|
Some applications, especially microcontroller applications without a dedicated serial data buffer, require an extra delay between individual characters to avoid buffer overflows and allow the microcontroller to execute other code.
In Docklight Scripting you can implement inter-character delays by inserting one or several Function Characters '&' (F9 key) in your Send Sequence data, followed by a character specifying the desired delay time from 0.01 seconds to 2.55 seconds.
You can also use the '&' delay character inside a Receive Sequence to specify a minimum silent time where no further characters should be received. This is useful for detecting pauses in the data stream that indicate the beginning/end of a telegram, especially for protocols where there is no dedicated start or end character.
Preconditions
Sending Data With Inter-Character Delays
As an example, we use a microcontroller application which understands a "get" command. In ASCII Mode, the Send Sequence would be: g | e | t | r ("r" is a terminating <CR> Carriage Return character)
The following steps describe how to add an additional delay of 20 milliseconds between each character and avoid buffer overflows on the microcontroller side.
A) Modifying the existing Send Sequence
103 | 101 | 116 | 013
103 | & | 101 | 116 | 013
103 | & | 002 | 101 | 116 | 013
103 | & | 002 | 101 | & | 002 | 116 | & | 002 | 013 Or back in ASCII Mode: g | & | o | e | & | o | t | & | o | r
NOTE: To distinguish a '&' delay character from a regular ampersand ASCII character (decimal code 38), the delay function character is shown on a different background color by the sequence editor.
NOTE: The character after a delay function character is interpreted as the delay time and is not sent to the serial device.
B) Sending the command to the microcontroller application
Docklight will send out the same data as before, but leave additional timing gaps as specified by the delay characters. The communication display will show the same communication data as without the delays.
NOTE: Docklight's accuracy for delay timing is limited because it has no control over the UART's internal TX FiFo buffer. The specified delay times for the '&' delay function character are minimum values. Measured delay values are significantly higher, because Docklight always waits a minimum time to ensure the UART TX FiFo buffer is empty. Also, the display format and the additional performance settings affects the timing. If you have more specific requirements on Send Sequence timing and need to control the Docklight "wait time" as well as your UART FiFo settings, please contact our e-mail support.
TIP: If you require the same delay between each character of the transmitted data, have a look at the SendByteTiming.pts sample script (see the folder Extras\SendByteTiming in your Script Samples directory). This script will automatically slice your Send Sequences into individual characters and send the data "byte-by-byte", using a predefined inter-character delay.
Pause detection using a Receive Sequence
Docklight already offers the Pause detection... display option to insert additional time stamps or line breaks after communication pauses.
If you require not only visual formatting, but need to define actions after a minimum pause, or simply make sure the Receive Sequence detection algorithm starts anew after a pause, you can add the delay function character to your Receive Sequence definition.
In most applications the best place for the delay function character will be at the beginning of the Receive Sequence, before the actual receive data characters.You can also create a Receive Sequence that contains a delay/pause definition only, and no actual serial data. This can be very useful for implementing timing constraints, e.g. resetting the telegram detection after a pause occurred.
TIP: See the LineParser.ptp / LineParser.pts project and script file (folder Extras\LineParser in your Script Samples directory) for a sample application. |