Serial

Serial

Module that allows communication through the serial port.

Properties

ReceiveMode SerialReceiveMode

Determines the type of data received by the SerialReceiveEvent event.
The BinaryData option passes binary data into the event's Data property.
The Lines option splits the received data into lines using the \n character as a separator, writing the result inside the event's Lines property.

Port number

Serial COM port number.

IsActive boolean read only

Indicates if the serial connection on the specified port is active.

BaudRate number

The serial connection baud rate.

DataBits number

The standard length of data bits per byte.
The value must be between 5 and 8 inclusive.

Parity SerialParity

The serial connection parity-checking protocol.

StopBits SerialStopBits

The number of stopbits per byte.

Methods

WriteInt8( value number )

Writes an 8-bit integer to the serial port.

WriteUInt8( value number )

Writes an 8-bit unsigned integer to the serial port.

WriteInt16( value number )

Writes a 16-bit integer to the serial port.

WriteUInt16( value number )

Writes a 16-bit unsigned integer to the serial port.

WriteInt32( value number )

Writes a 32-bit integer to the serial port.

WriteUInt32( value number )

Writes a 32-bit unsigned integer to the serial port.

WriteFloat32( value number )

Writes a 32-bit float to the serial port.

WriteFloat64( value number )

Writes a 64-bit float to the serial port.

Write( data string )

Writes a byte array to the serial port.

Print( text string )

Write a utf8 string to the serial port.

Println( text string )

Writes a string with a \n (new line) added at the end to the serial port.

GetAvailablePorts( ) number[]

Returns an array containing the available serial COM port numbers.

Events

SerialIsActiveEvent : { IsActive boolean, Type string }

Sent when the serial IsActive state change.
* IsActive indicates if the serial connection on the specified port is active.
* Type is "SerialIsActiveEvent".

SerialReceiveEvent : { Lines {}, Data string, Type string }

Sent when data is received from a Serial module.
The module's ReceiveMode property determines the type of data received by the event.
* The SerialReceiveMode.BinaryData option passes binary data into the Data property.
* The SerialReceiveMode.Lines option splits the received data into lines using the \n character as a separator, writing the result inside the Lines property.
* Type is "SerialReceiveEvent".

Receive modes

There are two valid values for a SerialReceiveMode:

  • BinaryData
  • Lines

The BinaryData option passes binary data into the event's Data property, the Lines option splits the received data into lines using the \n character as a separator, writing the result inside the event's Lines property.

Parity

SerialParity specifies the parity bit mode:

  • None No parity check occurs.
  • Odd Sets the parity bit so that the count of bits set is an odd number.
  • Even Sets the parity bit so that the count of bits set is an even number.
  • Mark Leaves the parity bit set to 1.
  • Space Leaves the parity bit set to 0.

Stop bits

SerialStopBits Specifies the number of stop bits.

  • One One stop bit is used.
  • OnePointFive 1.5 stop bits are used.
  • Two Two stop bits are used.