Welcome Guest, you are in: Login

EventIDE Wiki

RSSRSS

Navigation




Search the wiki


PoweredBy

Summary

Element Icon COM Port
Info
Category: Communication AddIn: Base Elements
Creator: OkazoLab Scope: Parent event
Owns Snippets: None Usage: Snippets

Properties

NameDescription                              ConstraintsTypeOn
runtime
change
Port Settings
Port Name        Defines the selected serial port by its name in the system. The name can be selected from the dropdown list, which queries the available serial ports.                String         
Baud Rate        Defines the serial baud rate                Int32         
Stop Bits        Defines a number of stopbits per transferred byte                StopBi..         
Parity        Defines the parity-checking protocol                Parity         
Data Bits Number        Defines the number of data bits in each transferred byte                Int32         
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.                stSeri..         
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.                stSeri..         
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         
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.                Boolean         
Input        Returns a string containing the most recent port input, when the element works in the input modes. The property value is refreshed on each Control Loop step, therefore, it should be read in the Control Loop snippet.                String         
Triggering Input        When the element works in the 'Input Detection' mode, a 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 a 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 'Triggering on specific input' working mode                Boolean         
Output
Output Buffer        Text buffer that accumulates data meant to be sent through the port.                String         
Send Now        Runtime command sending the current output value through the port. The command is enabled, when the element works in the Manual Output mode.                Boolean         
Runtime Status
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         
Triggering Time        Returns a local event time of the last triggering on the element. Triggering can occur only in the 'Triggering on specific input' working mode.                clTime         
Control
Is Enabled        If set to false the element is completely omitted when the experiment is run                Boolean         
Title        Title of the element                String         

COM Port Element provides bidirectional data exchange through the serial port (COM) on a PC computer. The element can be used for sending digital codes that are synchronized with events in your experiment. Also, the serial port element can be used for asynchronous data transfers to the external devices.


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

Image
Image

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).

Output on event Onset

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.

Triggering on specific Input

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. This means 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).

Manual Input Listening

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 the 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

  1. 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.
  2. 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.
  3. 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.

  Name Size
- COM-Port-Element-Icon.png 3.19 KB
- SerialPort.png 575.29 KB
- SerialPort_sm.jpg 58.98 KB

ScrewTurn Wiki version 5.2.0.8. Some of the icons created by FamFamFam.