Receive Serial Data
Receives data from a serial port with the specified name.
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=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|
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.
Troi Serial Plug-in 5.0
FileMaker Pro 16 to 18
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.
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 ) = "$$" ] Beep If [ $TempResultReceived = "$$-28" ] Show Message [ Open the port first ] Else If [ $TempResultReceived = "$$-207" ] Show Message [ Buffer overflow error ] Else Show Message [ An error occurred! ] End If End If Halt Script Else # 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 ]
Related script steps
|Open Serial Port|
|Send Serial Data|