Skip to main content

Receive Serial Data (script step reference)

By July 1, 2023July 17th, 2023Online Help, Troi Serial Plug-in
Troi Serial Plug-in for FileMaker Pro

Receive Serial Data

Receives data from a serial port with the specified name.

SyntaxScript step badge

Receive Serial Data [ Select ; Result (error) ; Port name ; Encoding ;
                      Get last match ; Switches ]


Select entire contents replaces the entire contents of a field with the result. If not checked the result replaces the currently selected portion of the field
Result data the data received
Port name the name of the port to receive data from
Encoding the desired character encoding like UTF-8, or "Convert bytes to numbers" which converts all received bytes to their numeric value, with a space as separator
Get last match get the last string of text that matches the match string
Switches (optional) specifies how this function receives the data


The optional Switches parameter takes precedence over the other parameters. Switches can be:

-GetLastMatch get the last string of text that matches the match string

You can also add one of these encoding switches, which determine how the incoming bytes are interpreted.

-Encoding=ASCII_Windows (Windows ANSI)
-Encoding=ASCII_Mac (Mac Roman)
-Encoding=ISO_8859_1 (Windows Latin-1)
-Encoding=BytesOnly returns all received bytes as the same Unicode byte values (Unicode 0 to 255)
-ConvertBytesToNumbers converts all received bytes to their numeric value, with space as separator

Returned Result

Data type returned



The returned result is the data received or an error code. An error always starts with 2 dollars, followed by the error code. You should always check for errors when receiving, by testing if the first two characters are dollars. Returned error codes can be:

$$-28 notOpenErr the port is not open
$$-108 memFullErr ran out of memory
$$-50 paramErr there was an error with the parameter
$$-4210 portDoesNotExistErr port with this name is not available on this computer
$$-4211 allPortsNullErr no serial ports are available on this computer
$$-207 notEnoughBufferSpace the input buffer is full

Other errors may be returned.

Originated in

Troi Serial Plug-in 5.0


FileMaker Pro 16 to FileMaker Pro 2023


The port needs to be opened first (see Open Serial Port).
If no data is available an empty string is returned.
The plug-in will get any data that is received at the time the function is called. This might not be all data coming in. You might need to wait and append new data coming in at a later time.

When you use the “Get last match” option the last matching string of text is returned. Older text is discarded.

Please be aware that only the ASCII characters 0…255 will be received, as a serial port uses 8 bit characters. If the serial device is encoding the bytes as UTF-8 you can receive any Unicode character. In this case specify as Encoding UTF-8.

When using the encoding “Convert bytes to numbers” all received bytes are converted to their numeric value. It will for example return “65 66 67 “, when receiving the bytes “ABC”. Note that each number is followed by a space, as separator, including after the last number.


Receive Serial Data [ Select ; $Result ; "SerialPort1" ]

This will receive data from the SerialPort1. It might return “All the world is a sta”. If you call it again later new data may have come in and the result might be “ge and we are merely players.” It is best to concatenate the data coming in.

Example 2

Below you find a “Receive Data” script for receiving data into a variable $TempResultReceived. The script tests for errors.

We assume that $PortName contains the name of the previously opened port.

Add the following script steps:

Receive Serial Data [ Select ; $TempResultReceived ; $PortName ]
If [ Left ( $TempResultReceived ; 2 ) = "$$" ]
	If [ $TempResultReceived = "$$-28" ]
		Show Message [ Open the port first ]
		If [ $TempResultReceived = "$$-207" ]
			Show Message [ Buffer overflow error ]
			Show Message [ An error occurred! ]
		End If
	End If
Halt Script
	# No error, so concatenate the data and do your stuff:
	Set Variable [ $TotalResult ; $TotalResult & $TempResultReceived ]
	#  .... add your own steps here ...
End If
Set Field [ gTotalResult ; $TotalResult // also save into a global field ]

Used in example file


Related script stepsScript step badge

Open Serial Port
Send Serial Data

Related functionsFunction badge


Related topics

Troi Serial Plug-in online help (overview)

Online Help Page for Troi Serial Plug-in for 16 to 2023 –> Receive Serial Data (serip7806) 2023-0717 13:12:34