Expand description
The C ABI for a Modbus client on a serial port, and the devices it polls.
A client runs each transaction to the Modbus over Serial Line specification over a
PamojaSerialPort: the kernel’s serial device on a Linux board, or a port whose far end
is a PamojaModbusLine of simulated devices. A device is a PamojaModbusServer, a unit
address and the four tables it serves, which also answers a single frame on its own. The
program keeps its handle to each device after putting it on a line, so it can look at what
a write did.
A failed transaction returns a status with the reason in the last error message, and fills
a PamojaModbusClientError when the caller passes one, so a program can tell a device’s
exception from a timeout without reading the message.
Structs§
- Pamoja
Modbus Client - A Modbus RTU client on a serial port. Opaque; release it with
pamoja_modbus_client_free. - Pamoja
Modbus Client Error - Why a client call failed, for a program that branches on it.
- Pamoja
Modbus Line - Several devices on one simulated line. Opaque; release it with
pamoja_modbus_line_free. A port made from it keeps its own share of it. - Pamoja
Modbus Server - A Modbus device: a unit address and the four tables it serves. Opaque; release it with
pamoja_modbus_server_free. A line it is on keeps its own share of it.
Constants§
- PAMOJA_
MODBUS_ CLIENT_ BROADCAST_ READ - A client error kind: a read was addressed to the broadcast address, which no device answers.
- PAMOJA_
MODBUS_ CLIENT_ EXCEPTION - A client error kind: the device refused the request with an exception.
- PAMOJA_
MODBUS_ CLIENT_ FRAME - A client error kind: the reply failed its CRC or is not the shape its function gives.
- PAMOJA_
MODBUS_ CLIENT_ MISMATCH - A client error kind: a well-formed reply that does not answer the request.
- PAMOJA_
MODBUS_ CLIENT_ OK - A client error kind: the call succeeded.
- PAMOJA_
MODBUS_ CLIENT_ PORT - A client error kind: the serial port failed.
- PAMOJA_
MODBUS_ CLIENT_ REQUEST - A client error kind: the request could not be built, from a quantity outside what one request carries.
- PAMOJA_
MODBUS_ CLIENT_ TIMEOUT - A client error kind: no complete reply arrived within the response timeout.
- PAMOJA_
MODBUS_ CLIENT_ WRONG_ FUNCTION - A client error kind: a reply answered another function.
- PAMOJA_
MODBUS_ CLIENT_ WRONG_ UNIT - A client error kind: a reply came back from another unit.
Functions§
- pamoja_
modbus_ ⚠client_ free - Releases a client. Its port stays open while another holder has it. A null pointer is ignored.
- pamoja_
modbus_ ⚠client_ new - Makes a client on a port, with a one-second response timeout and a 100 ms turnaround.
- pamoja_
modbus_ ⚠client_ read_ coils - Reads coils, function
0x01. - pamoja_
modbus_ ⚠client_ read_ discrete_ inputs - Reads discrete inputs, function
0x02. - pamoja_
modbus_ ⚠client_ read_ holding_ registers - Reads holding registers, function
0x03. - pamoja_
modbus_ ⚠client_ read_ input_ registers - Reads input registers, function
0x04. - pamoja_
modbus_ ⚠client_ response_ timeout_ micros - Returns a client’s response timeout, in microseconds, or 0 for a null handle.
- pamoja_
modbus_ ⚠client_ set_ response_ timeout - Sets how long a client waits for a whole reply once a request has gone out.
- pamoja_
modbus_ ⚠client_ set_ turnaround - Sets how long a client leaves the line quiet after a broadcast.
- pamoja_
modbus_ ⚠client_ turnaround_ micros - Returns a client’s turnaround delay, in microseconds, or 0 for a null handle.
- pamoja_
modbus_ ⚠client_ write_ multiple_ coils - Writes a run of coils, function
0x0F. - pamoja_
modbus_ ⚠client_ write_ multiple_ registers - Writes a run of holding registers, function
0x10. - pamoja_
modbus_ ⚠client_ write_ single_ coil - Writes one coil, function
0x05. - pamoja_
modbus_ ⚠client_ write_ single_ register - Writes one holding register, function
0x06. - pamoja_
modbus_ ⚠frame_ gap_ nanos - Returns the silence that separates two frames at a line’s speed and format: 3.5 characters, and a fixed 1750 microseconds above 19200 baud.
- pamoja_
modbus_ ⚠line_ attach - Puts a device on a line. The line shares the device, so the caller’s handle still reads and changes it.
- pamoja_
modbus_ ⚠line_ free - Releases the caller’s handle to a line. A port made from it keeps its own share. A null pointer is ignored.
- pamoja_
modbus_ ⚠line_ len - Returns how many devices are on a line, or 0 for a null handle.
- pamoja_
modbus_ line_ new - Makes a line with no devices on it.
- pamoja_
modbus_ ⚠line_ port - Makes a serial port with a line on its far end: every frame written reaches each device, and whatever they answer waits to be read.
- pamoja_
modbus_ ⚠server_ answer - Answers one RTU frame, as the device on the line does.
- pamoja_
modbus_ ⚠server_ coil - Reads a coil.
- pamoja_
modbus_ ⚠server_ discrete_ input - Reads a discrete input.
- pamoja_
modbus_ ⚠server_ free - Releases the caller’s handle to a device. A line it is on keeps its own share. A null pointer is ignored.
- pamoja_
modbus_ ⚠server_ holding_ register - Reads a holding register.
- pamoja_
modbus_ ⚠server_ input_ register - Reads an input register.
- pamoja_
modbus_ ⚠server_ new - Makes a device at a unit address, with every table empty.
- pamoja_
modbus_ ⚠server_ served - Returns how many requests a device has carried out, broadcasts included and refusals not, or 0 for a null handle.
- pamoja_
modbus_ ⚠server_ set_ coils - Sets coils from an address on, adding any the device did not have.
- pamoja_
modbus_ ⚠server_ set_ discrete_ inputs - Sets discrete inputs from an address on, adding any the device did not have.
- pamoja_
modbus_ ⚠server_ set_ holding_ registers - Sets holding registers from an address on, adding any the device did not have.
- pamoja_
modbus_ ⚠server_ set_ input_ registers - Sets input registers from an address on, adding any the device did not have.
- pamoja_
modbus_ ⚠server_ unit - Returns a device’s unit address, or 0 for a null handle.