System.SerialPort

From Xojo Documentation

Method

System.SerialPort(Index as Integer) As SerialPort

Supported for all project types and targets.

Gets the serial port by its index.


Method

System.SerialPort(Path as String) As SerialPort

Supported for all project types and targets.

Gets the serial port by its path.

Notes

On macOS and Linux, the path is the path to the device file corresponding to the serial device (e.g., /dev/ttyS0). On Windows, this can be the COM port you want to open, e.g.,

Serial1.SerialPort = System.SerialPort("/dev/ttyS0") // macOS and Linux
Serial1.SerialPort = System.SerialPort("COM1") // Windows

Examples

You get the values of SerialPort properties by accessing the properties of the System module:

TextField1.Text = System.SerialPort(0).InputDriverName

The following displays the names of the serial ports on the computer:

For i As Integer = 0 To System.SerialPortCount - 1
MsgBox(System.SerialPort(i).Name)
Next