
QD1 IO Expansion Module User Manual
46 Document Version V3.0 (2020-08-18)
Example:
uint16_t regs[MAX_IO] = {0};
ret=modbus_read_input_registers(ctx,MODBUS_INPUT_ADDR,M
ODBUS_INPUT_LEN, regs);
if (ret < 0)
{ fprintf(stderr, “%s\n”, modbus_strerror(errno)); }
int modbus_write_bit(modbus_t *ctx, int addr, int status);
Write single IO/coil with function code of 0x05. This function can be used to perform
write operations to QD1 slave stations. This function returns 0 on success and -1 on
failure.
Example:
ret = modbus_write_bit(ctx, 5, TRUE);
if (ret < 0)
{ fprintf(stderr,
“%s\n”, modbus_strerror(errno)); }
int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t
*src);
Write multiple coils with function code of 0x0F. Write the array pointed to by src into
the nb status bits at the beginning of addr. The function returns 0 on success and -1 on
failure.
Example:
bits[1] = TRUE;
bits[2] = FALSE;
ret = modbus_write_bits(ctx, 1, 2, &bits[1]); if (ret < 0)
{ fprintf(stderr, “%s\n”, modbus_strerror(errno));}
int modbus_write_register(modbus_t *ctx, int addr, int value);
Write 16 IOs with function code of 0x06. Registers are addressed from 0, so register
numbered 1 is addressed as 0. This function can be used for initialization. This function
returns 1 on success and -1 on failure.