stephane / libmodbus

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

serial RTU slave - can't set serial_mode #196

Closed gregorvilkner closed 10 years ago

gregorvilkner commented 10 years ago

Hi there, I am running version 3.1.1 on a raspberry pi with debian. i am trying to implement a slave to read registers from a master via rtu rs485 through a usb adapter. the connection works (i have some good results using python code) and i successfully tested the random client and server demo programs and also successfully completed the unit-test-server and client. Here's my problem: I can not set the serial_mode to rs485 (1). modbus_rtu_set_serial_mode(ctx, 1) or modbus_rtu_set_serial_mode(ctx, MODBUS_RTU_RS485) returns -1. modbus_rtu_get_serial_mode(ctx) returns 0, which means rs323, correct? Spent a lot of time on this - running out of steam and ideas... Any help would be appreciated? Cheers, and kind regards, Gregor

stephane commented 10 years ago

It's better to use mailing list for such question, that's said, is your slave connected to an USB adapter (if so don't care about RS485)?

stephane commented 10 years ago

It's better to use mailing list for such question, that's said, is your slave connected to an USB adapter (if so don't care about RS485)?

gregorvilkner commented 10 years ago

Thanks for the response. we are trying to read registers from an industrial controller, that acts as a modbus master (there are other clients devices in the mix). the raspberry pi is a slave for data logging purposes. Yes, we connect the rs485 to a usb adapter. so you're saying the serial mode doesn't matter in this case? whatever it is we're reading, it's all over the place. responses range from the client id not matching (Request for slave xxx isn't the requested slave y), to crc's not matching up (CRC received XYZ# != CRC calculated ASDF), to message lengths not corresponding (9 !=7). pretty random stuff. any advice? Thanks again, Gregor

stephane commented 10 years ago

I don't understand, you can't read from a Modbus master! Do you run libmodbus on the Raspberry Pi? RPi is a special beast (see archives on the mailing and pull requests on the subject).

Could you continue to talk on mailing list, please? Try to describe clearly your use case...

DanielVerkerk commented 10 years ago

Hello, Gregor Vilkner

I am trying to do the same thing with a Omron sysmac CP1L-E (master) and the raspberry pi (slave) This is the first time i am working with the Rpi so till learning python,

I am trying to make the raspberry log data from the plc true modbus (RS485) conetion and usb on the Rpi

Have you been able to get you setup working ? and do you have some pointers on what to watch out for? Also if you have gotten it to work, are you willing to share your script and how you done it?

Here 2 pic's of my setup imag0505 imag0517