Does anyone use libmodbus on raspberry pi ?

2,320 views
Skip to first unread message

m k

unread,
Mar 13, 2014, 4:01:48 AM3/13/14
to libm...@googlegroups.com
Hi,
 
I'm trying to use libmodbus to communicate via rs485 with many arduinos. I have a simple modbus library on arduino, downloaded from https://code.google.com/p/simple-modbus/.
 
When I'm using libmodbus on my local PC (x64) all modbus packages are sent, received properly but when I move the same source code from PC to raspberry pi more than half of all sent package are missed and there was a timeout.
 
If someone is able to help or more interested in I will provide more details/screens etc.
 
Maybe I should compile libmodbus for ARM architecture and not for x86/x64?
 
Regards
Marcin   

Julien Blanc

unread,
Mar 13, 2014, 4:16:18 AM3/13/14
to libm...@googlegroups.com
A binary compiled for x86/x64 will definitely not work on a raspberry
pi. It won’t even launch, so probably there’s another issue. Which
distribution are you using with your raspberry ? IIRC raspbian should
include libmodbus, i don’t know for other distributions.

For information, i’m using libmodbus on an armv7l device, without any
arm-specific issue. The pi is only armv6l, but i don’t see why this
would cause any issue.

Regards,

Julien Blanc

Giampaolo Bellini

unread,
Mar 13, 2014, 4:20:05 AM3/13/14
to libm...@googlegroups.com
Hello Marcin

  I had no problem with libmodbus on my raspbian and an USB/RS485 converter.
  of course... you cannot use x86/64 package.

         Giampaolo



--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "libmodbus".
Pour vous désabonner de ce groupe et ne plus en recevoir les messages, envoyez un e-mail à l'adresse libmodbus+...@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

m k

unread,
Mar 13, 2014, 4:33:45 AM3/13/14
to libm...@googlegroups.com
I expected that library compiled on x86 will not even launch but it does,
in my console application i'm  executing the following scenario 250 times
1) send package  "wrtie multiple registers" to the slave
2) get response from slave
3) send package "read from multiple registers" to the slave
4) get response from slave.
 
and on raspberry pi I have almost 110 timeouts between step 3rd and 4th.
 
On raspberry i have the latest wheezy and the latest libmodbus collected via git.
 
Regards
Marcin


--
Vous recevez ce message car vous êtes abonné à un sujet dans le groupe Google Groupes "libmodbus".
Pour vous désabonner de ce sujet, visitez le site https://groups.google.com/d/topic/libmodbus/XcPNp5Qa4g0/unsubscribe.

Pour vous désabonner de ce groupe et de tous ses sujets, envoyez un e-mail à l'adresse libmodbus+unsubscribe@googlegroups.com.
Pour plus d'options, visitez le site https://groups.google.com/d/optout .



--
Pozdrawiam
Marcin Kowal

m k

unread,
Mar 13, 2014, 4:35:15 AM3/13/14
to libm...@googlegroups.com
Could you help mi with building libmodbus on raspberry?


--
Vous recevez ce message, car vous êtes abonné à un sujet dans le groupe Google Groupes "libmodbus".
Pour vous désabonner de ce sujet, consultez la page https://groups.google.com/d/topic/libmodbus/XcPNp5Qa4g0/unsubscribe.
Pour vous désabonner de ce groupe et de tous ses sujets, envoyez un e-mail à l'adresse libmodbus+...@googlegroups.com.

Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.



--
Pozdrawiam
Marcin Kowal

Julien Blanc

unread,
Mar 13, 2014, 4:38:16 AM3/13/14
to libm...@googlegroups.com
On 13/03/2014 09:33, m k wrote:
> I expected that library compiled on x86 will not even launch but it does,
> in my console application i'm executing the following scenario 250 times
> 1) send package "wrtie multiple registers" to the slave
> 2) get response from slave
> 3) send package "read from multiple registers" to the slave
> 4) get response from slave.
> and on raspberry pi I have almost 110 timeouts between step 3rd and 4th.
> On raspberry i have the latest wheezy and the latest libmodbus
> collected via git.

Do you mean you compile your executable on your desktop, and then copy
it to the raspberry, and then launch it ? I’m pretty surprised this does
not result in an « invalid executable format » and does anything at all.

For simplicity, i would suggest that you do the following, unless there
are good reasons not to (such as needing a feature that is only in
latest libmodbus) :
- use the libmodbus provided by wheezy (install package libmodbus1 and
libmodbus-dev)
- do all compilation on the pi itself (cross-compiling can be a real pain)

Regards,

Julien Blanc

Giampaolo Bellini

unread,
Mar 13, 2014, 4:40:16 AM3/13/14
to libm...@googlegroups.com
Hello Marcin

  I don't remember it there was an already-done package for raspbian

  try "apt-cache search libmodbus" and then "apt-get install XXX"

  you can also download the source code and compile it as normal with "./configure" "make" "make install"

           Giampaolo

m k

unread,
Mar 13, 2014, 4:50:58 AM3/13/14
to libm...@googlegroups.com
I will compile on raspberry pi from the source code the latest version of libmodbus,
 
and let you know.
 
Thank you for your help
Regards
 

Phil Whorton

unread,
Mar 13, 2014, 4:54:57 AM3/13/14
to libm...@googlegroups.com

Hi Marcin,
I did some work on this last year.
I just wrote a simple C program based on the excellent examples and compiled it on the  Pi and it worked a treat.
I don't have access to the code at present but could send it to you at the weekend if you wish.
It's very rough and ready as I ran out of time...
Cheers
Phil

--

m k

unread,
Mar 13, 2014, 2:46:50 PM3/13/14
to libm...@googlegroups.com
Ok Guys,
I have started everything one more time from the scratch.
Uninstalled libmodbus and removed source code, then did all the steps listed below:

1. git clone https://github.com/stephane/libmodbus.git --depth=1
2. cd libmodbus
3. sudo ./autogen.sh
4. sudo ./configure --host=arm-none-linux-gnueabi --prefix=/usr/
5. sudo make & make install

Everything seems to be installed properly so I'm launching my C program to test modbus communication between arduino and raspberry pi.
I'm sending 250 packets to the arduino slave to force writing to multiple registers and then 250 packets to the same slave to force reading from multiple registers
Finally I'm measuring errors related with the read function and separatly related with the write function.

The result is still the same almost 105 errors with the read and 125 errors with the write.
Please tell me what and where I'm doing wrong, because the same source code compiled on two operating systems on x86 works properly without any errors. I've tested on ubuntu as well as win7.

Maybe my test program is a crap.I have attached it. please take a look.

Regards
Marcin



--
Vous recevez ce message, car vous êtes abonné à un sujet dans le groupe Google Groupes "libmodbus".
Pour vous désabonner de ce sujet, consultez la page https://groups.google.com/d/topic/libmodbus/XcPNp5Qa4g0/unsubscribe.
Pour vous désabonner de ce groupe et de tous ses sujets, envoyez un e-mail à l'adresse libmodbus+...@googlegroups.com.

Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.



--
Pozdrawiam
Marcin Kowal
arduino.c

Chuck Watson

unread,
Mar 13, 2014, 2:59:43 PM3/13/14
to libm...@googlegroups.com

Have you tried setting timeouts? Some operations work so the code must be correct in some ways but there may be a possible race condition so some operations fail on timeouts.

 

What about putting a delay between operations? Are you overloading the slave devices? This may be related to the issue above.

 

Are you using the same USB RS485 cabling on both the X86 and Pi? Is it a cabling issue?

 

Chuck Watson BS, CEM, CMVP
Direct USA 724-799-1529
www.EnergyChaser.com


Phil Whorton

unread,
Mar 13, 2014, 3:08:39 PM3/13/14
to libm...@googlegroups.com

Chuck raised a good point here! I used both an USB to rs485 converter and the built in UART via a max Chip and both worked fine. I had to add biasing resistors to the max to get it to work with all slaves. My guess is that you're using the same wiring and 485 convertor though?
I'll take a look at the weekend and see if I can see anything.

m k

unread,
Mar 13, 2014, 3:09:08 PM3/13/14
to libm...@googlegroups.com
on both environments I'm using the same equipement. usb -> rs485 converter and the same utp cable connected to arduino.
Currently im testing code with 10s delay between sending each read and write packets.
and its working without any erros at the moment

Phil Whorton

unread,
Mar 13, 2014, 3:11:42 PM3/13/14
to libm...@googlegroups.com

Sounds like a good start.
I was reading and writing to some automation gear and was at around 5ms for 20 registers so the 10s is very slow. What Baudrate etc are you using?

Chuck Watson

unread,
Mar 13, 2014, 3:12:52 PM3/13/14
to libm...@googlegroups.com

You probably only need 1 second or less but I don’t know anything about arduinos.

m k

unread,
Mar 13, 2014, 3:13:15 PM3/13/14
to libm...@googlegroups.com
on both sides arduino and rpi i have the same settings 9600, 'N', 8, 2

Phil Whorton

unread,
Mar 13, 2014, 3:19:56 PM3/13/14
to libm...@googlegroups.com

I normally just send the request (read or write),  evaluate the response then carry on with the next request. Anything in the range of 1s is very slow.

m k

unread,
Mar 13, 2014, 3:22:58 PM3/13/14
to libm...@googlegroups.com
1s delay between read and write is enough, without delay packets are missed.

m k

unread,
Mar 13, 2014, 3:48:07 PM3/13/14
to libm...@googlegroups.com
Guys,
Thank you all very mych for help.

Regards
Marcin
--
Pozdrawiam
Marcin Kowal

amol chaudhari

unread,
Mar 20, 2015, 10:37:37 PM3/20/15
to libm...@googlegroups.com
I had to execute the command below to get the correct linker lib.

sudo CC="arm-linux-gnueabi-gcc" ./configure --host=arm-none-linux-gnueabi --prefix=/usr/

Visalakshi Sankaran

unread,
Apr 23, 2015, 1:25:47 AM4/23/15
to libm...@googlegroups.com

Hi, 

I am running libmodbus( libmodbus-3.1.2) modbus rtu slave code in my Raspberrypi and modbus master simulator running in my windows pc. I have connected two pc via usb to rs232 converter cable.When i send request from the master simulator(running on windows) the slave code receives it wrongly.
i.e.
i am sending 01 03 00 00 00 0A C5 CD
but i am receiving it as 01 03 00 00 00 0A 05 1E

I also tried changing the values at the sender side and verify, what i found is that if i give value below 1F it is received properly at the slave side and any value above 1F is coming wrongly. Please help

Reply all
Reply to author
Forward
Message has been deleted
0 new messages