You are here: Start » Program Examples » IO Serial Port Communicator

IO Serial Port Communicator

Aim

The task is to create a demonstrative version of a program, that is responsible for connecting to the serial port with provided parameters, send new data (binary or text), have the option to see the last message and have the ability to safely disconnect.

Data required for connection:

  • Port Name
  • Baud Rate
  • Parity
  • Data Bits
  • Flow Control
  • Stop Bits

Hints

You can use help of that article:Programming Finite State Machines, when it comes to deciding on the structure of the program. You can also read more on Macrofilters

Macrofilter Main

Macrofilter StateMachine(CONNECTED)

Macrofilter StateMachine(DISCONNECT)

Macrofilter StateMachine(SEND_BYTES)

Macrofilter StateMachine(SEND_TEXT)

Macrofilter StateMachine(SETUP_CONNECTION)

Macrofilter StateMachine(WAIT_FOR_KEY)

Macrofilter CreateTextForConsole

Used Filters

Icon Name Description
ConcatenateStrings_OfArray Joins multiple strings into a single one.
ParseInteger Returns the integer number represented by a string.
ReadIntegerArrayFromBuffer Reads an array of integer values in specified binary format from a byte buffer.
ChooseByPredicate E.g. to choose GREEN color to visualize correct objects or RED to visualize defective ones.
SerialPort_ReadBuffer Reads raw binary data from serial port.
WriteIntegerArrayToBuffer Converts an array of integer values into specified binary representation and writes it to a byte buffer.
FormatIntegerToString Useful for preparing a number for display or communication with specific number of digits, sign etc.
SerialPort_Config Configures the serial port.
SerialPort_WriteBuffer Writes raw binary data from a byte buffer to serial port.
RemoveNils This filter is useful e.g. when inspecting multiple objects while some of the inspections may fail (Nil result). RemoveNils is used to ignore the failed cases in the final result.
SplitString Divides the input string into an array of strings using the specified delimiters.
ConcatenateStrings Joins two or more strings into a single one.
SerialPort_WriteString Writes string characters to serial port.
Loop Put this filter into a task that should have a loop, but does not have any other loop generators (e.g. GrabImage).
LastMultipleObjects Returns an array of most recent objects.

Further Readings

  • Array Transforms - List of filters performing operations on arrays.
  • Serial Port - List of filters performing operations on Serial Ports.