Regular API function

simSerialRead / sim.serialRead

Description Lua only. Reads from a previously opened serial port (RS-232). The C version of the function cannot be blocking. See also sim.serialCheck and sim.serialSend.
C/C++
synopsis
simInt simSerialRead(simInt portHandle,simChar* buffer,simInt dataLengthToRead)
C/C++
parameters
portHandle: the handle returned by the simSerialOpen function
buffer: a buffer that will be filled with read data
dataLengthToRead: the maximum data length that should be read
C/C++
return value
-1 if operation was not successful, otherwise the effective data length that was read
Lua
synopsis
string data=sim.serialRead(int portHandle,int dataLengthToRead,bool blockingOperation,string closingString='',float timeout=0)
Lua
parameters
portHandle: the handle returned by the sim.serialOpen function
dataLengthToRead: the maximum data length that should be read
blockingOperation: if true and the calling script is running in a thread, then the function only returns when the desired data length was read (or if the closingString was met, or if there was a timeout (see next arguments)
closingString: a string (containing any byte value) can be specified, that will break from the blocking operation if a match was found in the incoming data. Useful when you know that a data packet is always ended with a given signature. Can be an empty string for default operation.
timeout: duration after which the blocking operation will be aborted, or 0 if the timeout is infinite.
Lua
return values
data: a string containing read data (excluding the closingString if it was specified and found)
Python
synopsis