libsigrok
0.4.0
sigrok hardware access and backend library
|
#include <config.h>
#include <glib.h>
#include <string.h>
#include <libsigrok/libsigrok.h>
#include "libsigrok-internal.h"
Go to the source code of this file.
Macros | |
#define | LOG_PREFIX "modbus" |
Enumerations | |
enum | { MODBUS_READ_COILS = 0x01, MODBUS_READ_HOLDING_REGISTERS = 0x03, MODBUS_WRITE_COIL = 0x05, MODBUS_WRITE_MULTIPLE_REGISTERS = 0x10 } |
Functions | |
SR_PRIV GSList * | sr_modbus_scan (struct drv_context *drvc, GSList *options, struct sr_dev_inst *(*probe_device)(struct sr_modbus_dev_inst *modbus)) |
Scan for Modbus devices which match a probing function. More... | |
SR_PRIV struct sr_modbus_dev_inst * | modbus_dev_inst_new (const char *resource, const char *serialcomm, int modbusaddr) |
Allocate and initialize a struct for a Modbus device instance. More... | |
SR_PRIV int | sr_modbus_open (struct sr_modbus_dev_inst *modbus) |
Open the specified Modbus device. More... | |
SR_PRIV int | sr_modbus_source_add (struct sr_session *session, struct sr_modbus_dev_inst *modbus, int events, int timeout, sr_receive_data_callback cb, void *cb_data) |
Add an event source for a Modbus device. More... | |
SR_PRIV int | sr_modbus_source_remove (struct sr_session *session, struct sr_modbus_dev_inst *modbus) |
Remove event source for a Modbus device. More... | |
SR_PRIV int | sr_modbus_request (struct sr_modbus_dev_inst *modbus, uint8_t *request, int request_size) |
Send a Modbus command. More... | |
SR_PRIV int | sr_modbus_reply (struct sr_modbus_dev_inst *modbus, uint8_t *reply, int reply_size) |
Receive a Modbus reply. More... | |
SR_PRIV int | sr_modbus_request_reply (struct sr_modbus_dev_inst *modbus, uint8_t *request, int request_size, uint8_t *reply, int reply_size) |
Send a Modbus command and receive the corresponding reply. More... | |
SR_PRIV int | sr_modbus_read_coils (struct sr_modbus_dev_inst *modbus, int address, int nb_coils, uint8_t *coils) |
Send a Modbus read coils command and receive the corresponding coils values. More... | |
SR_PRIV int | sr_modbus_read_holding_registers (struct sr_modbus_dev_inst *modbus, int address, int nb_registers, uint16_t *registers) |
Send a Modbus read holding registers command and receive the corresponding registers values. More... | |
SR_PRIV int | sr_modbus_write_coil (struct sr_modbus_dev_inst *modbus, int address, int value) |
Send a Modbus write coil command. More... | |
SR_PRIV int | sr_modbus_write_multiple_registers (struct sr_modbus_dev_inst *modbus, int address, int nb_registers, uint16_t *registers) |
Send a Modbus write multiple registers command. More... | |
SR_PRIV int | sr_modbus_close (struct sr_modbus_dev_inst *modbus) |
Close Modbus device. More... | |
SR_PRIV void | sr_modbus_free (struct sr_modbus_dev_inst *modbus) |
Free Modbus device. More... | |
Variables | |
SR_PRIV const struct sr_modbus_dev_inst | modbus_serial_rtu_dev |
anonymous enum |
SR_PRIV struct sr_modbus_dev_inst* modbus_dev_inst_new | ( | const char * | resource, |
const char * | serialcomm, | ||
int | modbusaddr | ||
) |
Allocate and initialize a struct for a Modbus device instance.
resource | The resource description string. |
serialcomm | Additionnal parameters for serial port resources. |
Definition at line 141 of file modbus.c.
References sr_modbus_free(), and SR_OK.
SR_PRIV int sr_modbus_close | ( | struct sr_modbus_dev_inst * | modbus | ) |
SR_PRIV void sr_modbus_free | ( | struct sr_modbus_dev_inst * | modbus | ) |
Free Modbus device.
modbus | Previously initialized Modbus device structure. |
Definition at line 573 of file modbus.c.
Referenced by modbus_dev_inst_new().
SR_PRIV int sr_modbus_open | ( | struct sr_modbus_dev_inst * | modbus | ) |
SR_PRIV int sr_modbus_read_coils | ( | struct sr_modbus_dev_inst * | modbus, |
int | address, | ||
int | nb_coils, | ||
uint8_t * | coils | ||
) |
Send a Modbus read coils command and receive the corresponding coils values.
modbus | Previously initialized Modbus device structure. |
address | The Modbus address of the first coil to read, or -1 to read the reply of a previouly sent read coils command. |
nb_coils | The number of coils to read. |
coils | Buffer to store all the received coils values (1 bit per coil), or NULL to send the read coil command without reading the reply. |
Definition at line 398 of file modbus.c.
References MODBUS_READ_COILS, SR_ERR_ARG, SR_ERR_DATA, sr_modbus_reply(), sr_modbus_request(), and SR_OK.
SR_PRIV int sr_modbus_read_holding_registers | ( | struct sr_modbus_dev_inst * | modbus, |
int | address, | ||
int | nb_registers, | ||
uint16_t * | registers | ||
) |
Send a Modbus read holding registers command and receive the corresponding registers values.
modbus | Previously initialized Modbus device structure. |
address | The Modbus address of the first register to read, or -1 to read the reply of a previouly sent read registers command. |
nb_registers | The number of registers to read. |
registers | Buffer to store all the received registers values, or NULL to send the read holding registers command without reading the reply. |
Definition at line 446 of file modbus.c.
References MODBUS_READ_HOLDING_REGISTERS, SR_ERR_ARG, SR_ERR_DATA, sr_modbus_reply(), sr_modbus_request(), and SR_OK.
SR_PRIV int sr_modbus_reply | ( | struct sr_modbus_dev_inst * | modbus, |
uint8_t * | reply, | ||
int | reply_size | ||
) |
Receive a Modbus reply.
modbus | Previously initialized Modbus device structure. |
reply | Buffer to store the received Modbus reply. |
reply_size | The size of the reply buffer. |
Definition at line 248 of file modbus.c.
References SR_ERR, SR_ERR_ARG, and SR_OK.
Referenced by sr_modbus_read_coils(), sr_modbus_read_holding_registers(), and sr_modbus_request_reply().
SR_PRIV int sr_modbus_request | ( | struct sr_modbus_dev_inst * | modbus, |
uint8_t * | request, | ||
int | request_size | ||
) |
Send a Modbus command.
modbus | Previously initialized Modbus device structure. |
request | Buffer containing the Modbus command to send. |
request_size | The size of the request buffer. |
Definition at line 229 of file modbus.c.
References SR_ERR_ARG.
Referenced by sr_modbus_read_coils(), sr_modbus_read_holding_registers(), and sr_modbus_request_reply().
SR_PRIV int sr_modbus_request_reply | ( | struct sr_modbus_dev_inst * | modbus, |
uint8_t * | request, | ||
int | request_size, | ||
uint8_t * | reply, | ||
int | reply_size | ||
) |
Send a Modbus command and receive the corresponding reply.
modbus | Previously initialized Modbus device structure. |
request | Buffer containing the Modbus command to send. |
request_size | The size of the request buffer. |
reply | Buffer to store the received Modbus reply. |
reply_size | The size of the reply buffer. |
Definition at line 305 of file modbus.c.
References sr_modbus_reply(), sr_modbus_request(), and SR_OK.
Referenced by sr_modbus_write_coil(), and sr_modbus_write_multiple_registers().
SR_PRIV GSList* sr_modbus_scan | ( | struct drv_context * | drvc, |
GSList * | options, | ||
struct sr_dev_inst *(*)(struct sr_modbus_dev_inst *modbus) | probe_device | ||
) |
Scan for Modbus devices which match a probing function.
drvc | The driver context doing the scan. |
options | The scan options to find devies. |
probe_device | The callback function that will be called for each found device to validate whether this device matches what we are scanning for. |
Definition at line 74 of file modbus.c.
References sr_config::data, sr_config::key, SR_CONF_CONN, SR_CONF_MODBUSADDR, and SR_CONF_SERIALCOMM.
SR_PRIV int sr_modbus_source_add | ( | struct sr_session * | session, |
struct sr_modbus_dev_inst * | modbus, | ||
int | events, | ||
int | timeout, | ||
sr_receive_data_callback | cb, | ||
void * | cb_data | ||
) |
Add an event source for a Modbus device.
session | The session to add the event source to. |
modbus | Previously initialized Modbus device structure. |
events | Events to check for. |
timeout | Max time to wait before the callback is called, ignored if 0. |
cb | Callback function to add. Must not be NULL. |
cb_data | Data for the callback function. Can be NULL. |
SR_PRIV int sr_modbus_source_remove | ( | struct sr_session * | session, |
struct sr_modbus_dev_inst * | modbus | ||
) |
Remove event source for a Modbus device.
session | The session to remove the event source from. |
modbus | Previously initialized Modbus device structure. |
SR_PRIV int sr_modbus_write_coil | ( | struct sr_modbus_dev_inst * | modbus, |
int | address, | ||
int | value | ||
) |
Send a Modbus write coil command.
modbus | Previously initialized Modbus device structure. |
address | The Modbus address of the coil to write. |
value | The new value to assign to this coil. |
Definition at line 490 of file modbus.c.
References MODBUS_WRITE_COIL, SR_ERR_ARG, SR_ERR_DATA, sr_modbus_request_reply(), and SR_OK.
SR_PRIV int sr_modbus_write_multiple_registers | ( | struct sr_modbus_dev_inst * | modbus, |
int | address, | ||
int | nb_registers, | ||
uint16_t * | registers | ||
) |
Send a Modbus write multiple registers command.
modbus | Previously initialized Modbus device structure. |
address | The Modbus address of the first register to write. |
nb_registers | The number of registers to write. |
registers | Buffer holding all the registers values to write. |
Definition at line 526 of file modbus.c.
References MODBUS_WRITE_MULTIPLE_REGISTERS, SR_ERR_ARG, SR_ERR_DATA, sr_modbus_request_reply(), and SR_OK.
SR_PRIV const struct sr_modbus_dev_inst modbus_serial_rtu_dev |
Definition at line 194 of file modbus_serial_rtu.c.