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§
- Pamoja
Serial Port - One serial port, shared with every holder of it. Opaque; release it with
pamoja_serial_port_free. - Pamoja
Serial Script - 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. - Pamoja
Serial Settings - 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.