Hello everyone,
hope you're all doing as good as possible during these times...
I'm using the library ArduinoModbus to communicate with an Accelerometer.
I've used it before with another sensor and it worked without any problem. However, the response is quite different now and given that I'm getting an error message I'm debugging it and reached a problem that I can't understand what is going on.
Problem
While debugging, I found that the problem is with an if condition that returns -1:
And when I went to check the pre_check_confirmation
I found that it is a struct item and that is it... I couldn't find what it defines. Looks like a function, but I don't know what happens within the ctx->backend->pre_check_confirmation
or ctx->backend->pre_check_confirmation(ctx, req, rsp, rsp_length)
.
typedef struct _modbus_backend {
unsigned int backend_type;
unsigned int header_length;
unsigned int checksum_length;
unsigned int max_adu_length;
int (*set_slave) (modbus_t *ctx, int slave);
int (*build_request_basis) (modbus_t *ctx, int function, int addr,
int nb, uint8_t *req);
int (*build_response_basis) (sft_t *sft, uint8_t *rsp);
int (*prepare_response_tid) (const uint8_t *req, int *req_length);
int (*send_msg_pre) (uint8_t *req, int req_length);
ssize_t (*send) (modbus_t *ctx, const uint8_t *req, int req_length);
int (*receive) (modbus_t *ctx, uint8_t *req);
ssize_t (*recv) (modbus_t *ctx, uint8_t *rsp, int rsp_length);
int (*check_integrity) (modbus_t *ctx, uint8_t *msg,
const int msg_length);
int (*pre_check_confirmation) (modbus_t *ctx, const uint8_t *req,
const uint8_t *rsp, int rsp_length);
int (*connect) (modbus_t *ctx);
void (*close) (modbus_t *ctx);
int (*flush) (modbus_t *ctx);
int (*select) (modbus_t *ctx, fd_set *rset, struct timeval *tv, int msg_length);
void (*free) (modbus_t *ctx);
} modbus_backend_t;
struct _modbus {
/* Slave address */
int slave;
/* Socket or file descriptor */
int s;
int debug;
int error_recovery;
struct timeval response_timeout;
struct timeval byte_timeout;
const modbus_backend_t *backend;
void *backend_data;
};
In the struct above, we can see the int (*pre_check_confirmation) (modbus_t *ctx, const uint8_t *req, const uint8_t *rsp, int rsp_length);
but as shown in the picture below, there is no definition of what happens here... I'm missing something.
Arduino Monitor
Reading Input Register values ... 010300020004E5C9
Received: 010309905F01925F017963010EBA
Restante Length: 0
offset: 1
Function: 3
rc==-1
failed! Invalid data
Packages
Here, I show you the packages sent and received that I tested here and also the datasheet example. With this, at least in my opinion, it is pretty clear that the communication is working.
Real
Send: 01 03 00 02 00 04 E5 C9
Received: 01 03 09 91 5F 01 94 5F 01 78 63 01 52 8C