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.

Input

Data required for connection:

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

Output


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
WriteIntegerArrayToBuffer Converts an array of integer values into specified binary representation and writes it to a byte buffer.
ChooseByPredicate E.g. to choose GREEN color to visualize correct objects or RED to visualize defective ones.
LastMultipleObjects Returns an array of most recent objects.
ConcatenateStrings_OfArray Joins multiple strings into a single one.
SerialPort_WriteBuffer Writes raw binary data from a byte buffer to serial port.
SerialPort_WriteString Writes string characters to serial port.
FormatIntegerToString Useful for preparing a number for display or communication with specific number of digits, sign etc.
ReadIntegerArrayFromBuffer Reads an array of integer values in specified binary format from a byte buffer.
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.
ParseInteger Returns the integer number represented by a string.
SerialPort_Config Configures the serial port.
ConcatenateStrings Joins two or more strings into a single one.
Loop Put this filter into a task that should have a loop, but does not have any other loop generators (e.g. GrabImage).
SerialPort_ReadBuffer Reads raw binary data from serial port.

Further Readings

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