Player APIs (BrightScript & Ja...
...
Object Reference
Input/Output Objects

roSerialPort

18min
this object controls the serial port on the player, allowing you to transmit and receive serial data the javascript equivalent is bsserialport docid\ zmqun8zm06aosrid6esfb if the serial with telnet registry key is set to 1, serial communication via roserialport in scripts will be highly unreliable see brightsign registry keys docid 8luj1vpf ftlcbisbqbvz for more information about serial with telnet 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 hardware interfaces docid\ pfx3zfroowim0gpelvl68 ) enumerate on port 0, though port 1 may be available on the gpio connector on some models if enabled see rocontrolport docid 8exdhgmohqig7j uvfce1 if more than one usb serial device is attached then the first one will be port 2, the second will be port 3, etc 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>" ) this value corresponds to the \<fid> value returned by the rodeviceinfo docid\ utkdmpos1ulxaoylx1ns6 method the 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 are not 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 functions docid\ nsjxffr7olfgdwgjfebme 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 sets the message port that rostreamlineevent events will be posted to setbyteeventport(port as object) as void sets the message port that rostreambyteevent events will be posted to setbytearrayeventport(port as object) as void this method works like setbyteeventport but causes rostreambytearrayevent messages to be posted to the message port when data is received for some object types (for example, rotcpstream ), this can be much more efficient since data no longer needs to be delivered to brightscript a byte at a time, but since serial ports are comparatively slow it's possible that each event will still contain only a single character setreceiveeol(eol sequence as string) sets the sequence that will signify the end of line and cause a rostreamlineevent to be delivered to the message port set by setlineeventport if you need to set this value to a non printing character, use the chr() global functions docid\ nsjxffr7olfgdwgjfebme or an robytearray if the sequence contains nul bytes it must be passed as an robytearray since strings may not contain nul bytes to use a nul byte as a line terminator eol = createobject("robytearray") eol push(0) mp = createobject("romessageport") client = createobject("roserialport", 0, 115200) client setreceiveeol(eol) client setlineeventport(mp) 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(enable 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 de 9 (more commonly referred to as db 9) 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 example 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