Page History: COM Port Element
Compare Page Revisions
Page Revision: 2011/11/13 17:02
|
COM Port Element
|
Info |
Category: |
Communications |
|
AddIn: |
Base Elements |
Creator: |
OkazoLab Team |
|
Scope: |
Parent Event |
Owns Snippets: |
no |
|
Usage: |
Runtime Screen,Snippets |
Serial port is an element that provides bidirectional data exchange through the serial computer ports.
Description
COM port is an element that provides bidirectional data exchange through the serial computer ports: COM ports and USB ports (with special drivers). Using the COM port element is very easy: you simply chose one of the existing serial ports on a computer, set up a few port settings and select the element working mode. The element supports four working modes that cover most of the typical usage scenarios in experiments.
Snapshots
Snapshot 1
| Snapshot 2 |
Practical Use
Manual Output
In this mode the serial port element can be used for sending data through the serial port at any chosen moment of time. You have to control this process manually in your code snippets in two steps. First, you should settle some data in an output buffer by assigning a string value to the [Output Buffer] property of the element. Then, the output buffer can be sent to the port immediately after you set the [Send now] property of the element to true (initiating the runtime action). You can perform these steps multiple times while your experiment is running (it not necessary to have the parent event active in this working mode).
Auto Output
In this mode the serial port element can be used for sending data through the serial port synchronously with activation of the parent event. Before the activation or in the design time you should settle data in an output buffer by a string value to the [Output Buffer] property of the element. Immediately after activation of the parent event the output buffer will be sent automatically through the serial port. The output buffer can be changed at the runtime at any time but each new sending will require reactivation of the parent event.
Input Trigger
In this working mode the serial port element monitors all input coming through the serial port in order to detect a moment when the specific string value, the trigger string, arrives. The sought value is defined by the [Trigger String] property of the element. The serial port element signals the arrival moment by switching to the triggered state. Such triggering is always accompanied with recording of the exact trigger time and executing of the dedicated code snippet (if present). Thus, you can use the specific port input for controlling a flow of your experiment, performing custom actions and collecting accurate input timing. Notice that the element in this working mode has an action scope - the input monitoring and element triggering are possible only while the parent event is active.
You can share the same port input among several serial port elements with each element seeking for its own trigger string. The elements also can be set to have multiple triggering in case in the port input may contains multiple occurrences of the trigger string (by default, in this working mode the element is triggered only once on the first trigger string arrival).
Listener
In this working mode the serial port element simply collects all port input coming through the serial port while the parent event is active. The coming input is placed into the input buffer which can be accessed at runtime by reading the [Input Buffer] property of the element in code snippets. The input buffer is designed to be forcibly refreshed on every Running Cycle of the parent event. If you want to avoid data losses, you should take into account the expected input intensity and provide continuous reading of the input buffer. The best strategy is to read the input buffer in OnRunning snippet of the parent event (a fresh data is guaranteed) and set the size of the input buffer to be always sufficient to store all input coming between two Running cycles.
Testing the serial port element
You can test a work of the serial port element with its current settings at designtime by initiating either of two design-time actions: [Test Output] and [Test Input]. EventIDE will try to simulate element's runtime behavior for a short time, while it can be checked with an external hardware or software. [TestOutput] action initiates a single transfer of the current output buffer through the port. [TestInput] action calls a text window that, while open, shows the coming port input.
Notes
- For better synchronization of output transfers (in AutoOutput mode), move the Serial Port element at the top of the elements list in the parent event. The elements in the list are activated one by one, as soon as the parent event is activated, so the top position in the list decreases possible time delays.
- The serial port element always operates with input and output port data in the string format, performing string-binary conversion automatically. For the desired adequacy of this conversion the appropriate encoding has to be selected in the element port settings.
- You can use multiple serial port elements that share the same serial port. However, in this case you should take in account possible performance issues, which are likely, for example, in cases of the intensive port input.
Properties
Generic Properties
Name | Description | Attributes | Value Type | Proxy Reflex |
---|
Port Settings |
Port name | The system name of the used serial port. The typical names are COM1, COM2 and so on. | | String |
Baud Rate | The data rate in bits per second (bauds). The typical rates 4800, 9600 and so on. | | Int32 |
Stop bits | Number of the stop bits per transferred byte. One of the options- None, One, Two or 1.5 can be chosen. | | List |
Parity | Parity-checking protocol. One of the options- None, Odd, Even, Mark, Space can be chosen.. | | List |
Data bits number | The number of data bits in each transferred byte. The typical values are either 8 or 7. | | Int32 |
+=== Properties inherited from clSerialPortElement ===
Inherited properties of clSerialPort
Name | Description | Constraints | Value Type | Upon Runtime Change |
---|
Settings |
Working Mode | Defines a working mode for the element. Select 'Auto Output' mode for sending data synchronously with an onset of the parent event, 'Input Detection' mode for catching the particular pattern in port input and 'Manual Output'/'Input Listener' modes for custom writing/reading scenarios controlled via snippets. | | Struct,Int32 |
Encoding | The encoding method that is used to convert raw port bytes into text strings and vice verse. The default encoding is ByteChar which converts each byte of data to a single char. | | Struct,Int32 |
Buffer Size | Size of the input circular buffer (in bytes) that stores all incoming port data, when the element works in the 'Input Listener' mode. If the buffer is small, a part of the data can be lost before it is read by the program. | | Int32 |
Output |
Test Output | Initiates a single output transfer through the port by sending the current content of the Output Buffer property | |
Output Buffer | Text buffer that accumulates data meant to be sent through the port. | | String |
Send Now | Runtime action that initiates an instant transfer of the current output value through the port. Manual runtime calls of this action are required if the element works in the Manual Output mode. | | Boolean | Assigning "true" to the linked Proxy in snippets initiates a single action call |
Input |
Test Input | Start a dialog window that monitors arriving port input in realtime. Useп for verification of the selected port settings and encoding method. | |
Input | Returns the most recent content of the circular input buffer, when the element works in the Input Listener. The property is refreshed automatically on each OnRunning cycle, therefore, a property value should be read in the Running snippet. | | String |
Triggering Input | When the element works in the 'Input Detection' mode, the value of this property defines the 'catching' input string. If such string is detected an incoming input at some moment, the element registers the detection time and becomes triggered. This property is essential for time-accurate registration of the specific input, e.g button press, coming out of a external device. | | String |
Trigger Once | Defines whether the element can be triggered multiple times, while the parent event is active. If the property value is 'true', only the first triggering is registered. Triggering can occur only in the 'Input Detection' working mode | | Boolean |
Runtime Status |
Is Input Lost | Indicates that a part of the input has been lost due to large amount of incoming data at runtime or due to an insufficient size of the input buffer. Try to increase the buffer size or reduce a processing load when the element is active. | | Boolean |
Is Triggered | Indicates whether the element has been triggered at least once, since activation of the parent event. Triggering can occur only in the 'Input Detection' working mode | | Boolean |
Trigger Time | Indicates the local event time of the last element triggering. Triggering can occur only in the 'Input Detection' working mode. | | UInt64 |
+=== Properties inherited from clElement ===
Inherited properties of clElement
Name | Description | Constraints | Value Type | Upon Change |
---|
Control |
Is Enabled | If set to false the element is completely omitted when the experiment is run. | | Boolean |
|
Title | Title of the element. | | String |
|