stephane / libmodbus

A Modbus library for Linux, Mac OS, FreeBSD and Windows
http://libmodbus.org
GNU Lesser General Public License v2.1
3.46k stars 1.75k forks source link

error timed out when using Unit-test client and server example (RTU over RS-485) #161

Closed ghost closed 10 years ago

ghost commented 10 years ago

I'm using version 3.1.1 and my two devices are two Linux systems running Centos OS. the physical connection is 2 wire half-duplex RS-485 connection, using modpoll i could get response using same parameters, but with libmodbus i cannot

So the code is basically the same as the Unit-test example. except i added

if (use_backend == RTU) { modbus_set_slave(ctx, SERVER_ID); modbus_rtu_set_serial_mode(ctx, MODBUS_RTU_RS485); modbus_rtu_set_rts(ctx, MODBUS_RTU_RTS_UP); }

to both the client and the server...

this is the error i got from writing single coil..

Opening /dev/ttyS2 at 9600 bauds (N, 8, 1) \ UNIT TESTING **

TEST WRITE/READ: [11][05][01][30][FF][00][8F][59] Sending request using RTS signal Waiting for a confirmation... ERROR Connection timed out: select Bytes flushed (0) 1/2 modbus_write_bit: FAILED [root@localhost tests]# ./unit-test-client

does anyone know what i did wrong?

thanks very much

stephane commented 10 years ago

The RS485 mode of Linux kernel is certainly misleading and it was finally not a good thing to support this Linux kernel option because it seems only one device in the world support it! You must certainly remove modbus_rtu_set_serial_mode(ctx, MODBUS_RTU_RS485); and adjust the response timeout (see Web doc or manual pages).

Please, could you ask you question on mailing list? Issue tracker is reserved for bug reports.

ghost commented 10 years ago

Thank you Stephane for replying,

but my Serial Port is using data + and data - lines sending data differentially, why is it misleading to have RS-485 mode for Linux Kernel?

i don't understand.

thank you very much

On Wed, Nov 13, 2013 at 3:38 PM, Stéphane Raimbault < notifications@github.com> wrote:

The RS485 mode of Linux kernel is certainly misleading and it was finally not a good thing to support this Linux kernel option because it seems only one device in the world support it! You must certainly remove modbus_rtu_set_serial_mode(ctx, MODBUS_RTU_RS485); and adjust the response timeout (see Web doc or manual pages).

Please, could you ask you question on mailing list? Issue tracker is reserved for bug reports.

— Reply to this email directly or view it on GitHubhttps://github.com/stephane/libmodbus/issues/161#issuecomment-28445607 .

ghost commented 10 years ago

so even after remove RS485 mode and i set the response timeout to 10 seconds, 100 seconds, 5 seconds,, or 1 second.. still giving me the same error.

is there something else that might be wrong?

thank you very much Stephane.

On Wed, Nov 13, 2013 at 3:38 PM, Stéphane Raimbault < notifications@github.com> wrote:

The RS485 mode of Linux kernel is certainly misleading and it was finally not a good thing to support this Linux kernel option because it seems only one device in the world support it! You must certainly remove modbus_rtu_set_serial_mode(ctx, MODBUS_RTU_RS485); and adjust the response timeout (see Web doc or manual pages).

Please, could you ask you question on mailing list? Issue tracker is reserved for bug reports.

— Reply to this email directly or view it on GitHubhttps://github.com/stephane/libmodbus/issues/161#issuecomment-28445607 .

ghost commented 10 years ago

Hi

how do i adjust when the RTS is on or off?. is it just default to 1ms on and then 1ms off?.

thank you

On Wed, Nov 13, 2013 at 3:38 PM, Stéphane Raimbault < notifications@github.com> wrote:

The RS485 mode of Linux kernel is certainly misleading and it was finally not a good thing to support this Linux kernel option because it seems only one device in the world support it! You must certainly remove modbus_rtu_set_serial_mode(ctx, MODBUS_RTU_RS485); and adjust the response timeout (see Web doc or manual pages).

Please, could you ask you question on mailing list? Issue tracker is reserved for bug reports.

— Reply to this email directly or view it on GitHubhttps://github.com/stephane/libmodbus/issues/161#issuecomment-28445607 .

fatalfeel commented 7 years ago

i test one side is ubuntu 14.4 PC unit-test-client another side is android dev board. unit-test-server i meet this problem too. 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

adgnaf commented 3 years ago

@fatalfeel Thank you for sharing experience. But the origin purpose is to communicate over native rs485 port instead of a usb-rs485 adapter.