Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions nanomodbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1520,10 +1520,6 @@ static nmbs_error handle_write_file_record(nmbs_t* nmbs) {

if (!nmbs->msg.broadcast) {
// The normal response to 'Write File' is an echo of the request.
// We can restore buffer index and response msg.
nmbs->msg.buf_idx = msg_buf_idx;
discard_n(nmbs, request_size);

err = send_msg(nmbs);
if (err != NMBS_ERROR_NONE)
return err;
Expand Down Expand Up @@ -1700,7 +1696,7 @@ static nmbs_error handle_read_device_identification(nmbs_t* nmbs) {
put_1(nmbs, 1); // Number of objects

str[0] = 0;
err = nmbs->callbacks.read_device_identification(object_id, str);
err = nmbs->callbacks.read_device_identification(object_id, str, nmbs->callbacks.arg);
if (err != NMBS_ERROR_NONE) {
if (nmbs_error_is_exception(err))
return send_exception_msg(nmbs, err);
Expand Down Expand Up @@ -1741,12 +1737,12 @@ static nmbs_error handle_read_device_identification(nmbs_t* nmbs) {
last_id = 0x02;
break;
case 2:
if (object_id < 0x03 || object_id > 0x06)
if (object_id > 0x07)
return send_exception_msg(nmbs, NMBS_EXCEPTION_ILLEGAL_DATA_ADDRESS);
last_id = 0x06;
break;
case 3:
if (object_id < 0x80)
if (object_id > 0x07 && object_id < 0x80)
return send_exception_msg(nmbs, NMBS_EXCEPTION_ILLEGAL_DATA_ADDRESS);
last_id = 0xFF;
break;
Expand All @@ -1763,7 +1759,7 @@ static nmbs_error handle_read_device_identification(nmbs_t* nmbs) {
}

str[0] = 0;
err = nmbs->callbacks.read_device_identification((uint8_t) id, str);
err = nmbs->callbacks.read_device_identification((uint8_t) id, str, nmbs->callbacks.arg);
if (err != NMBS_ERROR_NONE) {
if (nmbs_error_is_exception(err))
return send_exception_msg(nmbs, err);
Expand Down
2 changes: 1 addition & 1 deletion nanomodbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ typedef struct nmbs_callbacks {

#ifndef NMBS_SERVER_READ_DEVICE_IDENTIFICATION_DISABLED
#define NMBS_DEVICE_IDENTIFICATION_STRING_LENGTH 128
nmbs_error (*read_device_identification)(uint8_t object_id, char buffer[NMBS_DEVICE_IDENTIFICATION_STRING_LENGTH]);
nmbs_error (*read_device_identification)(uint8_t object_id, char buffer[NMBS_DEVICE_IDENTIFICATION_STRING_LENGTH], void* arg);
nmbs_error (*read_device_identification_map)(nmbs_bitfield_256 map);
#endif
#endif
Expand Down