Welcome Guest, you are in: Login

ScrewTurn Wiki



Search the wiki


Element Icon COM Port Element
Category: Communications AddIn: Base Elements
Creator: OkazoLab Team Scope: Parent Event
Owns Snippets: no Usage: Runtime Screen,Snippets

Synchronized Internal Actions

ModeExperiment StartParent Event OnsetStatus change between Onset/OffsetParent Event OffsetExperiment End
Manual (output) Becomes ready for output. If sentNow = True, then at this moment the output value is transmitted via the port. Deactivates
Output on event Onset Transfers output values over the ports.
Triggering on specific Input Starts to listen to the input ports. By default, the element listens to any signal and gets triggered as soon as it receives a signal. If a mask is set via the triggering input property, then the element gets triggered upon receiving the desired input signal (as defined by mask). Stops listening.
Manual Input Listening Starts to listen to the input ports. Stops listening.


Generic Properties

NameDescriptionConstraintsValue TypeUpon Change
Port Settings
Port name The system name of the used serial port. The typical names are COM1, COM2 and so forth. You may either type it in or select it from the drop down list. String
Baud RateThe data rate in bits per second (bauds). The typical rates 4800, 9600 and so forth.Int32
Stop bitsNumber of the stop bits per transferred byte. One of the options: None, One, Two or 1.5 can be chosen.List
ParityParity-checking protocol. One of the options: None, Odd, Even, Mark, Space can be chosen..List
Data bits numberThe 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
NameDescriptionConstraintsValue TypeUpon Runtime Change
Working ModeDefines 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
EncodingThe 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 SizeSize 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
Test OutputInitiates a single output transfer through the port by sending the current content of the Output Buffer property
Output BufferText buffer that accumulates data meant to be sent through the port. String
Send NowRuntime 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.BooleanAssigning "true" to the linked Proxy in snippets initiates a single action call
Test InputStart a dialog window that monitors arriving port input in realtime. Useп for verification of the selected port settings and encoding method.
InputReturns 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 InputWhen 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 OnceDefines 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 modeBoolean
Runtime Status
Is Input LostIndicates 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 TriggeredIndicates whether the element has been triggered at least once, since activation of the parent event. Triggering can occur only in the 'Input Detection' working modeBoolean
Trigger TimeIndicates 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
NameDescriptionConstraintsValue TypeUpon Change
Is EnabledIf set to false the element is completely omitted when the experiment is run.Boolean
TitleTitle of the element.String

Serial port is an element that provides bidirectional data exchange through the serial computer ports.


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.



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.


  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
- SerialPort.png 575.29 KB
- SerialPort_sm.jpg 58.98 KB

ScrewTurn Wiki version Some of the icons created by FamFamFam.