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

Summary

Actions Summary Table

ActionsDescription
Close()Closes a connection
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
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.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetHashCode()This action gets the hash code for an object.
GetPort(text name)Returns a single port, not opened, for use.
GetPorts()Returns an array of the available ports on the system.
Read()Returns a decoded text string read from the serial connection.
Write(text message)Sends a text string as bytes over the connection to a default port opened in Connect.

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.

Example Code

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

Parameters

Return

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

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

Return

boolean:

Equals(Libraries.Language.Object object)

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

Example Code

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

Parameters

Return

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

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

GetPort(text name)

Returns a single port, not opened, for use.

Parameters

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