stephane / libmodbus

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

Reading coils or inputs #124

Closed adrianbica closed 11 years ago

adrianbica commented 11 years ago

I'm using libmodbus v3.1.0 on ARM 9 processor. According to the modbus standard "If the returned input quantity is not a multiple of eight, the remaining bits in the final data byte will be padded with zeros (toward the high order end of the byte)". See page 13 of MODBUS Application Protocol Specification V1.1b3 However, if I put 0xAA in the first byte of tab_bits or tab_input_bits, and I read 4 inputs, I would expect to get 0x0A, but instead I'm getting 0xAA. Am I doing something wrong or the libmodbus doesn't completely follow the standard?

Thanks, Adrian

stephane commented 11 years ago

The Modbus standard defines the protocol. The Modbus protocol is different from libmodbus API!

As stated in documentation http://libmodbus.org/site_media/html/modbus_write_bits.html, you must use boolean values.

stephane commented 11 years ago

A protocol must be implementation independant!

2013/6/4 adrianbica notifications@github.com

So, this works only if both client and server are using libmodbus library. If I am using any other 3rd party Modbus client, it will not work correctly, right?

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

adrianbica commented 11 years ago

I figured out that you use one byte to store each bit, so I removed my last comment. What confused me was the fact that when I put 0xAA in first byte (representing a bit) I got 0xAA for the first 8 bits. The only values supported by the storage bytes are 0 and 1, any other value will give unexpected results. I think this shouldn't happen.

Regards, Adrian


From: Stéphane Raimbault notifications@github.com To: stephane/libmodbus libmodbus@noreply.github.com Cc: adrianbica adrianbica@yahoo.com Sent: Tuesday, June 4, 2013 5:31 PM Subject: Re: [libmodbus] Reading coils or inputs (#124)

A protocol must be implementation independant!

2013/6/4 adrianbica notifications@github.com

So, this works only if both client and server are using libmodbus library. If I am using any other 3rd party Modbus client, it will not work correctly, right?

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

— Reply to this email directly or view it on GitHub.