Libraries.System.Serial Documentation

The Serial class is used to connect to and communicate over a serial connection. Communication includes reading and writing to a specified serial port. Connections using Serial can only be made over serial connections (e.g. Standard Serial over Bluetooth Link with paired Bluetooth devices or USB Serial Device). A Serial object is initialized with no assigned serial port when instantiated. Assigning a serial port to a Serial object can be done with the action Connect. Reading and writing to the serial connection can be handled by the actions Read and Send, respectively. Connections should be closed with the action Close when no longer in use.

Example Code

use Libraries.System.Serial

//This was tested using virtual serial ports with pseudo terminals on Linux:
//  socat -d -d pty,raw,echo=0 pty,raw,echo=0
//Then, using the two ports returned by that command (e.g /dev/pts/1 and /dev/pts/2)
//as the ports for Connect with two separate instances of this program, both instances
//sent and received the hello message.

class Main
action Main
    //Open a serial connection on a specific port
    //On Windows, the port name can be found in:
    //  Control Panel > Searching "bluetooth" in the search bar > Change Bluetooth Settings > COM Ports
    //On MacOS:
    //  Settings > Bluetooth > Devices > Edit Serial Ports
    //On Linux:
    //  Typically, serial ports are "/dev/ttySx", where x is a number for a specific port
    //  Details can be found using dmesg | grep ttyS
    Serial mySerial
    text port = input("Port: ")
    mySerial.Connect(port)

    mySerial.Write("Hello, World!")

    text inMsg = mySerial.Read()
    output inMsg
    
    mySerial.Close()
end

Inherits from: Libraries.Language.Object

Actions Documentation

Close()

Closes a connection

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Connect(text port)

Establishes a connection with a given port name, returns true if the port was successfully opened, or returns false if port is still closed.

Parameters

  • text port

Return

boolean:

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

FindPort(text name)

This action searches through all available ports via the name provided and compares it to the description. These descrptions are often more human readable, mentioning words like bluetooth, spike, or other product names directly. If the port could not be found, this returns undefined.

Parameters

  • text name

Return

Libraries.System.SerialPort:

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetPort(text name)

This action returns a port from the raw name, which you need to know ahead of time. These names can be esoteric, like long lists of numbers. To obtain them, you can get all the ports and iterate over them, for your particular system.

Parameters

  • text name

Return

Libraries.System.SerialPort:

GetPorts()

Returns an array of the available ports on the system.

Return

Libraries.Containers.Array:

Read()

Returns a decoded text string read from the serial connection. This works for the default port opened in Connect.

Return

text:

Write(text message)

Sends a text string as bytes over the connection to a default port opened in Connect.

Parameters

  • text message