Skip to main content

Module port

Module port 

Source
Expand description

The C ABI for one serial port that a program and every driver on it share.

A port is the kernel’s serial device on a Linux board, a line looped back on itself, one end of a null-modem pair, or a script of what a driver is expected to write, and the same calls work on each: a write, and a read that waits up to a timeout for the first byte. On anything but the kernel’s device a read never waits; the time it would have waited is counted instead, so a test of a device that never answers runs at once.

A port holds its line in shared hands. pamoja_serial_port_clone gives another holder, such as a thread that reads, the same port, and the line closes when the last holder lets go. A script is built here and copied onto a port, so its handle stays the caller’s to free. A failed read or write returns PamojaStatus::Io with the reason in the last error message.

Structs§

PamojaSerialPort
One serial port, shared with every holder of it. Opaque; release it with pamoja_serial_port_free.
PamojaSerialScript
The writes a driver is expected to make and the bytes the far end sends, in order. Opaque; release it with pamoja_serial_script_free.
PamojaSerialSettings
A port’s speed and character format: eight data bits, with the parity and stop bits given.

Constants§

PAMOJA_PARITY_EVEN
A parity bit that makes the count of ones even, what Modbus RTU asks for by default.
PAMOJA_PARITY_NONE
No parity bit.
PAMOJA_PARITY_ODD
A parity bit that makes the count of ones odd.
PAMOJA_SERIAL_PORT_DEVICE
A port kind: the kernel’s serial device, with a real line on the other end.
PAMOJA_SERIAL_PORT_LOOPED
A port kind: the port’s own output, looped back to its input.
PAMOJA_SERIAL_PORT_PAIRED
A port kind: the other end of a null-modem pair.
PAMOJA_SERIAL_PORT_SCRIPTED
A port kind: a script of the writes a driver is expected to make.
PAMOJA_SERIAL_PORT_SIMULATED
A port kind: a simulated device that answers each write.

Functions§

pamoja_serial_port_clone⚠
Gives another holder the same port, such as a thread that reads while the caller writes.
pamoja_serial_port_discard_input⚠
Drops whatever has arrived and not been read, as a client does before a request so a stale reply cannot be taken for the new one.
pamoja_serial_port_free⚠
Releases a holder’s share of a port. The line closes when no holder has it. A null pointer is ignored.
pamoja_serial_port_kind⚠
Returns what is on the other end of a port.
pamoja_serial_port_looped
Creates a line looped back on itself: every byte written is waiting to be read, as with TX wired to RX.
pamoja_serial_port_open⚠
Opens the kernel’s serial device raw, at a speed and a character format. Whatever the device received before it was opened is dropped.
pamoja_serial_port_pair⚠
Creates the two ends of a null-modem pair: what one end writes, the other reads.
pamoja_serial_port_read⚠
Reads what has arrived, waiting up to a timeout for the first byte when nothing has. On any port but the kernel’s device the read does not wait, and the timeout is counted instead.
pamoja_serial_port_received⚠
Returns how many bytes have been read through a port and every holder of it.
pamoja_serial_port_remaining⚠
Reports how many steps a scripted port has left.
pamoja_serial_port_scripted⚠
Creates a port that plays a script: each write has to be the one the script expects next, and the bytes the far end sends become readable as the script reaches them.
pamoja_serial_port_settings⚠
Returns the speed and format a port runs at.
pamoja_serial_port_wait⚠
Waits, as a protocol does to leave the line silent between frames: the process sleeps on the kernel’s device, and anywhere else the wait is only counted.
pamoja_serial_port_waited_micros⚠
Returns how long reads have waited without an answer, and waits have waited, in microseconds, whether or not the process slept through it.
pamoja_serial_port_write⚠
Writes bytes, and on the kernel’s device waits until they have left the UART.
pamoja_serial_port_written⚠
Returns how many bytes have been written through a port and every holder of it.
pamoja_serial_script_free⚠
Releases a script. A null pointer is ignored.
pamoja_serial_script_len⚠
Returns how many steps a script holds.
pamoja_serial_script_new
Creates an empty script.
pamoja_serial_script_read⚠
Adds bytes the far end sends, readable once every step before them has happened.
pamoja_serial_script_write⚠
Adds a write the program is expected to make, in one call.
pamoja_serial_settings
Returns the format most devices start in: eight data bits, no parity, one stop bit.
pamoja_serial_settings_bits_per_character
Returns the bits one character takes on the wire: a start bit, eight data bits, the parity bit if there is one, and the stop bits.
pamoja_serial_settings_character_nanos
Returns how long one character takes on the wire.