Commit 862af10b9864a896bbf81850d794ee514f9c0d1c
1 parent
e4fb46fe
Change arg value from int to const uint16_t in modbus_write_register
Closes #461
Showing
3 changed files
with
5 additions
and
5 deletions
doc/modbus_write_register.txt
| @@ -9,7 +9,7 @@ modbus_write_register - write a single register | @@ -9,7 +9,7 @@ modbus_write_register - write a single register | ||
| 9 | 9 | ||
| 10 | SYNOPSIS | 10 | SYNOPSIS |
| 11 | -------- | 11 | -------- |
| 12 | -*int modbus_write_register(modbus_t *'ctx', int 'addr', int 'value');* | 12 | +*int modbus_write_register(modbus_t *'ctx', int 'addr', const uint16_t 'value');* |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | DESCRIPTION | 15 | DESCRIPTION |
src/modbus.c
| @@ -1238,7 +1238,7 @@ int modbus_read_input_registers(modbus_t *ctx, int addr, int nb, | @@ -1238,7 +1238,7 @@ int modbus_read_input_registers(modbus_t *ctx, int addr, int nb, | ||
| 1238 | 1238 | ||
| 1239 | /* Write a value to the specified register of the remote device. | 1239 | /* Write a value to the specified register of the remote device. |
| 1240 | Used by write_bit and write_register */ | 1240 | Used by write_bit and write_register */ |
| 1241 | -static int write_single(modbus_t *ctx, int function, int addr, int value) | 1241 | +static int write_single(modbus_t *ctx, int function, int addr, const uint16_t value) |
| 1242 | { | 1242 | { |
| 1243 | int rc; | 1243 | int rc; |
| 1244 | int req_length; | 1244 | int req_length; |
| @@ -1249,7 +1249,7 @@ static int write_single(modbus_t *ctx, int function, int addr, int value) | @@ -1249,7 +1249,7 @@ static int write_single(modbus_t *ctx, int function, int addr, int value) | ||
| 1249 | return -1; | 1249 | return -1; |
| 1250 | } | 1250 | } |
| 1251 | 1251 | ||
| 1252 | - req_length = ctx->backend->build_request_basis(ctx, function, addr, value, req); | 1252 | + req_length = ctx->backend->build_request_basis(ctx, function, addr, (int) value, req); |
| 1253 | 1253 | ||
| 1254 | rc = send_msg(ctx, req, req_length); | 1254 | rc = send_msg(ctx, req, req_length); |
| 1255 | if (rc > 0) { | 1255 | if (rc > 0) { |
| @@ -1279,7 +1279,7 @@ int modbus_write_bit(modbus_t *ctx, int addr, int status) | @@ -1279,7 +1279,7 @@ int modbus_write_bit(modbus_t *ctx, int addr, int status) | ||
| 1279 | } | 1279 | } |
| 1280 | 1280 | ||
| 1281 | /* Writes a value in one register of the remote device */ | 1281 | /* Writes a value in one register of the remote device */ |
| 1282 | -int modbus_write_register(modbus_t *ctx, int addr, int value) | 1282 | +int modbus_write_register(modbus_t *ctx, int addr, const uint16_t value) |
| 1283 | { | 1283 | { |
| 1284 | if (ctx == NULL) { | 1284 | if (ctx == NULL) { |
| 1285 | errno = EINVAL; | 1285 | errno = EINVAL; |
src/modbus.h
| @@ -208,7 +208,7 @@ MODBUS_API int modbus_read_input_bits(modbus_t *ctx, int addr, int nb, uint8_t * | @@ -208,7 +208,7 @@ MODBUS_API int modbus_read_input_bits(modbus_t *ctx, int addr, int nb, uint8_t * | ||
| 208 | MODBUS_API int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest); | 208 | MODBUS_API int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest); |
| 209 | MODBUS_API int modbus_read_input_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest); | 209 | MODBUS_API int modbus_read_input_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest); |
| 210 | MODBUS_API int modbus_write_bit(modbus_t *ctx, int coil_addr, int status); | 210 | MODBUS_API int modbus_write_bit(modbus_t *ctx, int coil_addr, int status); |
| 211 | -MODBUS_API int modbus_write_register(modbus_t *ctx, int reg_addr, int value); | 211 | +MODBUS_API int modbus_write_register(modbus_t *ctx, int reg_addr, const uint16_t value); |
| 212 | MODBUS_API int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *data); | 212 | MODBUS_API int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *data); |
| 213 | MODBUS_API int modbus_write_registers(modbus_t *ctx, int addr, int nb, const uint16_t *data); | 213 | MODBUS_API int modbus_write_registers(modbus_t *ctx, int addr, int nb, const uint16_t *data); |
| 214 | MODBUS_API int modbus_mask_write_register(modbus_t *ctx, int addr, uint16_t and_mask, uint16_t or_mask); | 214 | MODBUS_API int modbus_mask_write_register(modbus_t *ctx, int addr, uint16_t and_mask, uint16_t or_mask); |