Hello,
I'm creating a modus TCP server on a linux OS by following code,
modbus_t *ctx = modbus_new_tcp('127.0.0.1', 1502);
uint8_t *query = new uint8_t[MODBUS_TCP_MAX_ADU_LENGTH];
log(QString("create modbus mapping"));
modbus_mapping_t *mb_mapping = modbus_mapping_new(0,0,32000,0);
if (mb_mapping == NULL){
log(QString("failed to create modbus mapping"));
modbus->close();
return;
}
log(QString("start to listen..."));
int s = modbus_tcp_listen(ctx, 1);
log(QString("accept connection..."));
modbus_tcp_accept(ctx, &s);
int rc = 0;
log(QString("request receiving..."));
rc = modbus_receive(ctx, query); --> Seg Fault here!
log(QString("modbus tcp request received."));
this->arm(mb_mapping);
rc = modbus_reply(ctx, query, rc, mb_mapping);
log(QString("modbus tcp response send."));
This is just a simple test, what I want is just to open the port and handle a single connection.
In my test, I can create the connection, but I always got Segment Fault when I send request like '00 00 00 00 00 06 01 03 00 00 00 01'.
And here are the logs, apperently, the modbus_reply methods trigger the Segment Fault.
2018-03-27 00:43:31 create modbus mapping 2018-03-27 00:43:31 start to listen... 2018-03-27 00:43:31 accept connection... 2018-03-27 00:43:45 request receiving...
|
I'm using libmodbus 3.1.4
Do you have some clue or suggest on this issue? Thanks!
BR,
Jipeng