ERROR connection timeout (RS485)

508 views
Skip to first unread message

Andrey Strunin

unread,
Sep 18, 2013, 8:06:40 AM9/18/13
to libm...@googlegroups.com
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...

giorgio foga

unread,
Oct 4, 2013, 8:11:16 AM10/4/13
to libm...@googlegroups.com
Hy I have the same result ..... every 10'' at the start of my pc ..... 30min after everything is resolved and working properly. You've solved somehow?

Jesse Stone

unread,
Jan 6, 2017, 4:37:03 AM1/6/17
to libmodbus
i meet this problem too.
i test one side is ubuntu 14.4 PC unit-test-client another side is android dev board. unit-test-server

in client
    rc = modbus_write_bit(ctx, UT_BITS_ADDRESS, ON);
    printf("1/2 modbus_write_bit: ");
    ASSERT_TRUE(rc == 1, "");
    rc = modbus_write_bit(ctx, UT_BITS_ADDRESS, ON); //add this to test

in server
  do {
            rc = modbus_receive(ctx, query);
            /* Filtered queries return 0 */
        } while (rc == 0);

then server only receive once...


finally i change hardware and use the usb to rs485 serial on both side
Bus 003 Device 010: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
test all pass



giorgio foga於 2013年10月4日星期五 UTC+8下午8時11分16秒寫道:
Reply all
Reply to author
Forward
0 new messages