I try to use libmodbus with RS485
I have problem...
Master must send right modbus packet, but i see timeout error
alltime
My code:
struct timeval response_timeout;
response_timeout.tv_sec = 0;
response_timeout.tv_usec = 99999;
uint16_t tab_reg[32]={0};
modbus_t* ctx = modbus_new_rtu("/dev/serusb2", 115200, 'N',
8, 2);
if (ctx==NULL)std::cout<<"Unable init modbus context
\n";
modbus_set_slave(ctx,0x0B);
modbus_connect(ctx);
modbus_set_response_timeout(ctx,&response_timeout);
modbus_set_debug(ctx, TRUE);
modbus_read_registers(ctx, 0, 5, tab_reg);
for(int i=0;i<5;i++)
{
printf(" %d",tab_reg[i]);
}
modbus_flush(ctx);
modbus_close(ctx);
modbus_free(ctx);
Debug info:
[0B][03][00][00][00][05][85][63]
Waiting for a confirmation...(Timeout is very long.
The slave
responds, and
only then the program goes on. )
ERROR Connection timed out: select
<0B><03><10><10><01><10><01><10><01><10><01><10><01><F2><3D>
0 0 0 0 00 bytes flushed
<0B><03><10><10><01><10><01><10><01><10><01><10><01><F2><3D>
- it's right packet...