Skip to main content

Module modbus_client

Module modbus_client 

Source
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§

PamojaModbusClient
A Modbus RTU client on a serial port. Opaque; release it with pamoja_modbus_client_free.
PamojaModbusClientError
Why a client call failed, for a program that branches on it.
PamojaModbusLine
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.
PamojaModbusServer
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.