local port =


new() → serial_port

new()                    (1)
new(fd: file_descriptor) (2)
1 Default constructor.
2 Converts a file descriptor into a serial_port object.

ptypair() → serial_port, file_descriptor

Open a pair of connected pseudoterminal devices. Returns the master and the slave ends, respectively.

The flag O_NOCTTY will be used to open the slave end so it doesn’t accidentally become the controlling terminal for the session of the calling process.
Use the returned file_descriptor object in system.spawn()'s set_ctty.

open(self, device: string)

Open the serial port using the specified device name.

device is something like "COM1" on Windows, and "/dev/ttyS0" on POSIX platforms.


Close the port.

Any asynchronous read or write operations will be cancelled immediately, and will complete with the boost::asio::error::operation_aborted error.


Cancel all asynchronous operations associated with the acceptor.

This function causes all outstanding asynchronous read or write operations to finish immediately, and the handlers for cancelled operations will be passed the boost::asio::error::operation_aborted error.

assign(self, fd: file_descriptor)

Assign an existing native port to self.

release(self) → file_descriptor

Release ownership of the native descriptor implementation.


Send a break sequence to the serial port.

This function causes a break sequence of platform-specific duration to be sent out the serial port.

read_some(self, buffer: byte_span) → integer

Read data from the port and blocks current fiber until it completes or errs.

Returns the number of bytes read.

write_some(self, buffer: byte_span) → integer

Write data to the port and blocks current fiber until it completes or errs.

Returns the number of bytes written.

isatty(self) → boolean

See isatty(3).

tcgetpgrp(self) → integer

See tcgetpgrp(3).

tcsetpgrp(self, pgid_id: integer)

See tcsetpgrp(3).


is_open: boolean

Whether the port is open.

baud_rate: integer

Read or write current baud rate setting.

flow_control: "software"|"hardware"|nil

Read or write current flow control setting.

parity: "odd"|"even"|nil

Read or write current parity setting.

stop_bits: string

Read or write current stop bit width setting.

It can be one of:

  • "one".

  • "one_point_five".

  • "two".

character_size: integer

Read or write current character size setting.