[id] = OpenSerialPort(id, portname$[, table])
portname$and assign the identifier
idto the connection. If you pass Nil in
OpenSerialPort()will automatically choose a vacant identifier and return it.
The name you pass in
portname$ depends on the platform your script is running on.
On Windows it could be
COM1, on Linux and macOS it could be
/dev/ttyUSB0 in case you're using a USB adapter. On AmigaOS you have to
pass the serial.device unit you want to open in
portname$ and on Android it is
assumed that there is only one port so
portname$ is ignored.
Starting with Hollywood 9.0,
portname$ can also be a string in the format "<devicename>:<port>" now
on AmigaOS and compatibles. This is useful in case you want
OpenSerialPort() to open an alternative
serial device instead of AmigaOS's standard
serial.device. For example, passing "serialpl2303.device:0"
portname$ will try to open
serialpl2303.device on port 0.
Additionally, you can pass an optional table argument allowing you to set the parameters for the serial port connection. The following fields are currently recognized:
As you can see above, the default configuration used by
OpenSerialPort() is 9600/8-N-1,
i.e. 9600 bps, 8 data bits, no parity bit, 1 stop bit. This is the most common configuration
and should work on every platform.
OpenSerialPort(1, "COM1") WriteSerialData(1, "Hello World!") CloseSerialPort(1)The code above opens the serial port COM1 on Windows, sends the string "Hello World!" to the receiver and closes the serial port connection. Note that there is no guarantee that all 12 bytes could be sent to the serial port. In stable code, you would have to check the return value of WriteSerialData() and call it again if necessary to send the remaining bytes.