Port
#struct PortAn open or failed serial port. Pass it by value to the I/O functions; only Close takes it by reference.
| Name | Type | Description |
|---|---|---|
path | str = "" | The device path or COM name the port was opened with. |
handle | i64 = -1 | The file descriptor (Linux, macOS, BSD) or the Windows handle, or -1 when the port is not open. |
ok | bool = false | True when the port opened and is not closed. IsOpen returns this value. |
baud | int = 0 | The speed in bits per second that was asked for. |
import hw.serial
func main:
mut p := serial.Open("/dev/does-not-exist", 9600)
println serial.IsOpen(p), p.ok, p.path, p.baud, p.handle
serial.Close(p)
q := serial.OpenFormat("/dev/does-not-exist", 19200, 7, serial.PARITY_ODD, 2)
println serial.IsOpen(q), q.baud
r := serial.OpenFormat("/dev/ttyUSB0", 9600, 9, serial.PARITY_NONE, 1)
println serial.IsOpen(r), r.baud
endfalse false /dev/does-not-exist 9600 -1 false 19200 false 9600