Port:write(data) method

Writes data to the serial communication Port.

Parameters

data

A Buffer or a string containing the data to be written. If another type of variable is used, it is internaly converted to a string before sending.

Return value

Returns a Task object to perform the write operation asynchronously.
Once the Task has terminated, it will return the number of bytes written, or false in case of error.

Example

local serial = require "serial" local COM1 = serial.Port("COM1") if COM1:open() then print("COM1 serial port is now open") if COM1:write("First message"):wait() then print("Data successfully written") else print("Write error") end else print("Failed to open COM1 serial port") end