Copy of roSerialPort

ON THIS PAGE


This object controls the serial port on the player, allowing you to transmit and receive serial data.

Object Creation: The roSerialPort object is created with two parameters.

CreateObject("roSerialPort", port As Dynamic, baud_rate As Integer)
  • port As Integer: The port enumeration of the serial device:
    • Most standard serial devices (including the USB-serial port on the LS424) enumerate on port 0.
    • To communicate with the serial port of an OPS display (i.e. with the HO523), use port 1.
    • To communicate with a USB-serial device (such as a GPS receiver), use port 2.
  • port As String: If multiple USB-serial devices are connected to the player, the device can be specified with a friendly name ("USB:<friendly_name>"). These values correspond to the <fid> values returned by the roDeviceInfo.GetUSBTopology() methodThe BrightSign shell usblist command can be used to discover friendly names. Note that RAW names are not guaranteed to stay the same between products or OS versions, so they aren't recommended.
  • baud_rate As Integer: The baud rate for serial communication. The serial port supports the following baud rates: 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400.
Example
serial1 = CreateObject("roSerialPort", 0, 115200)
serial2 = CreateObject("roSerialPort", "USB:A/1", 57600) 


The roSerialPort object sends the following event types:

  • roStreamLineEvent: The line event is generated whenever the end of line string set using SetEol is found and contains a string for the whole line. This object implements the ifString and ifUserData interfaces.
  • roStreamByteEvent: The byte event is generated on every byte received. This object implements the ifInt and ifUserData interfaces.

ifStreamSend

SetSendEol(eol_sequence As String) As Void

Sets the EOL sequence when writing to the stream. The default value is CR (ASCII value 13). If you need to set this value to a non-printing character, use the chr() global function.

SendByte(byte As Integer) As Void

Writes the specified byte to the stream.

SendLine(string As String) As Void

Writes the specified characters to the stream followed by the current EOL sequence.

SendBlock(a As Dynamic) As Void

Writes the specified characters to the stream. This method can support either a string or an roByteArray. If the block is a string, any null bytes will terminate the block.

Flush()

ifStreamReceive

SetLineEventPort(port As Object) As Void
 
SetByteEventPort(port As Object) As Void
 
SetReceiveEol(eol_sequence As String)

Sets the EOL sequence to detect when receiving the stream. The default value is CR (ASCII value 13). If you need to set this value to a non-printing character, use the chr() global function.

SetMatcher(matcher As Object) As Boolean

Instructs the stream to use the specified matcher. This method returns True if successful. Pass Invalid to this method to stop using the specified matcher.

ifSerialControl

SetBaudRate(baud_rate As Integer) As Boolean

Sets the baud rate of the device. The supported baud rates are as follows: 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400.

SetMode(mode As String) As Boolean

Sets the serial mode in "8N1" syntax. The first character is the number of data bits. It can be either 5, 6, 7, or 8. The second number is the parity. It can be "N"one, "O"dd, or "E"ven. The third is the number of stop bits. It can be 1 or 2.

SetEcho(enable As Boolean) As Boolean

Enables or disables serial echo. It returns True on success and False on failure.

SetEol(a As String)
 
SetFlowControl(enalbe As Boolean) As Boolean

Enables or disable RTS/CTS handshaking over the serial port. This feature is currently only available on 4Kx42, XDx32, and HDx22 models.

SetInverted(inverted As Boolean) As Boolean

Inverts the TX/RX signal levels on the serial port. This allows the player to communicate with devices that use -12V to 12V signaling. Inversion is supported on the DE9 and USB ports only. Passing True to the method enables inversion, whereas passing False disables it.

SendBreak(duration_in_ms As Integer) as Boolean

Sends a serial break or sets the serial break condition. This method returns True upon success and False upon failure.

  • duration_in_ms = -1: Sends a continuous break.
  • duration_in_ms = 0: Clears the break state.
  • duration_in_ms >= 100: Sets the break condition for the specified period of milliseconds (note that this integer is only accurate to the tenth of a second).

ifUserData

SetUserData(user_data As Object)

Sets the user data that will be returned when events are raised.

GetUserData() As Object

Returns the user data that has previously been set via SetUserData(). It will return Invalid if no data has been set.




This example script waits for a serial event and echoes the input received on the serial port to the shell:


serial = CreateObject("roSerialPort", 0, 9600)
p = CreateObject("roMessagePort")
serial.SetLineEventPort(p)

serial_only:
msg = Wait(0,p) ' Wait forever for a message.
if(type(msg) <> "roStreamLineEvent") goto serial_only 'Accept serial messages only.
serial.SendLine(msg) ' Echo the message back to serial.