Recent

Author Topic: Modbus on Raspberry Pi  (Read 5535 times)

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1405
Re: Modbus on Raspberry Pi
« Reply #15 on: November 05, 2019, 01:48:03 pm »
I have Scada running on my RPi2. With FPC/Laz trunk.
See screenshot.

Could this be of any help ?

korba812

  • Full Member
  • ***
  • Posts: 151
Re: Modbus on Raspberry Pi
« Reply #16 on: November 05, 2019, 04:02:15 pm »
There is another library for modbus:
https://sourceforge.net/projects/mbutils/

Thaddy

  • Hero Member
  • *****
  • Posts: 10705
Re: Modbus on Raspberry Pi
« Reply #17 on: November 05, 2019, 04:40:58 pm »
I have Scada running on my RPi2. With FPC/Laz trunk.
See screenshot.

Could this be of any help ?
Yes! Before I could not get it to work. If it works on 2 it should work on 3 and 4.

af0815

  • Hero Member
  • *****
  • Posts: 638
Re: Modbus on Raspberry Pi
« Reply #18 on: November 05, 2019, 06:05:10 pm »
Also if your OS is windows you can create a virtual com port by com0com project http://com0com.sourceforge.net/
IMHO not working on an actual Win10/64 because the drivers are not (correct)signed. My windows refused it.
« Last Edit: November 05, 2019, 06:07:36 pm by af0815 »
regards
Andreas

jdp

  • Full Member
  • ***
  • Posts: 123
Re: Modbus on Raspberry Pi
« Reply #19 on: November 06, 2019, 08:15:26 am »
I have Scada running on my RPi2. With FPC/Laz trunk.
See screenshot.

Could this be of any help ?

Alfred my old friend yes that would be super. If you can let us know what you did to get it installed it would be great.

jdp

  • Full Member
  • ***
  • Posts: 123
Re: Modbus on Raspberry Pi
« Reply #20 on: November 06, 2019, 08:16:54 am »
There is another library for modbus:
https://sourceforge.net/projects/mbutils/

This looks like what I need. I only need a simple modbus lib as my code does not have any GUI items. I see it was last updated in 2010, just hope it works with the current FPC.
I will give it a go later today.

avra

  • Hero Member
  • *****
  • Posts: 2112
    • Additional info
Re: Modbus on Raspberry Pi
« Reply #21 on: November 06, 2019, 12:38:29 pm »
Do you know a good emulator? (I know there is one from Siemens but that feels uncomfortable - and is not free!)
For Siemens Simatic S7 you can download archive from https://sourceforge.net/projects/snap7/files/1.4.1/ and use serverdemo. It does not emulate full PLC, just S7 protocol and DB1, DB2 and DB3. That is enough for most of the tests. You will find there raspberry binaries too, and even clientdemo whis is really, really good and useful.
Both applications have Lazarus sources 8-), and of course Pasettimino works with this S7 server.

For MODBUS slave simulators I do not use free ones since there were not very good ones at the time when I needed them. I guess that situation is now much better, so take a look at these:
http://tdogan.net/mss.html
https://unserver.xyz/products/modbus-slave-simulator/
http://modbuspal.sourceforge.net/
http://www.plcsimulator.org/
https://sourceforge.net/projects/modrssim2/
https://sourceforge.net/projects/pymodslave/
https://www.support-omron.fr/details/logiciel.php?id=2017-07-28 - 15-42-06 - 2107046460

For MODBUS free masters you can try these ones:
http://en.radzio.dxp.pl/modbus-master-simulator/
http://www.ozm.cz/ivobauer/modlink/files/modlink-2.56-demo.zip
https://www.se.com/us/en/faqs/FA180037/
https://sourceforge.net/projects/qmodmaster/
https://store.chipkin.com/products/tools/cas-modbus-scanner
https://www.modbusdriver.com/modpoll.html

Here is a pure MODBUS TCP package for Lazarus:
https://sourceforge.net/projects/delphimodbus/files/DelphiModbus-stable/1.6.3/

I have Scada running on my RPi2. With FPC/Laz trunk.
How did you install PascalSCADA and BGRA dependencies? Via FpcUpDeluxe or via OPM? Was it a smooth install or you had to solve some issues first?
« Last Edit: November 06, 2019, 12:45:30 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Thaddy

  • Hero Member
  • *****
  • Posts: 10705
Re: Modbus on Raspberry Pi
« Reply #22 on: November 06, 2019, 12:46:25 pm »
@Avra
Thanks for the extensive links.
My idea is to rewrite some of the code to use the fp* libraries, so it becomes native.
I haven't got acces to the real hardware anymore, so hence I need a good emulator.
Your links are really helpful.

jdp

  • Full Member
  • ***
  • Posts: 123
Re: Modbus on Raspberry Pi
« Reply #23 on: November 06, 2019, 06:57:16 pm »
Thaddy it would be great if you could build a Modbus library without the dependancy on GUI elements.
If you look at the Python lib Minimalmodbus it has all the functions you need.

In my case I need to get floating point values back from a VSD

watts = vsd.read_float(0x000C  , functioncode=4 ,  number_of_registers=2)

I can test it for you if you want.


This library seems to only handle integer values. https://sourceforge.net/projects/mbutils/



avra

  • Hero Member
  • *****
  • Posts: 2112
    • Additional info
Re: Modbus on Raspberry Pi
« Reply #24 on: November 07, 2019, 09:19:16 am »
Thaddy it would be great if you could build a Modbus library without the dependancy on GUI elements.
What GUI dependency are you talking about? Delphi ModBus TCP library depends on Indy, and mbutils depends on Synapse and even comes with console demo application. As I understood Thaddy, he mentioned elimination of 3rd party communication lib dependencies.

Your links are really helpful.
I am really glad I was of some help. Happy coding!  O:-)
« Last Edit: November 07, 2019, 09:24:47 am by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

white_zombie

  • New Member
  • *
  • Posts: 12
Re: Modbus on Raspberry Pi
« Reply #25 on: November 07, 2019, 09:35:11 am »
This library seems to only handle integer values. https://sourceforge.net/projects/mbutils/

The Modbus protocol can only transmit words (16 bits) or in some functions bits, this does not mean you can not get a float or a string even, you just need to know the size and the address of the data you want to read and then type casting to the value of your internal format, for example a type single is 32 bit, so you need to read 2 words.

Thaddy

  • Hero Member
  • *****
  • Posts: 10705
Re: Modbus on Raspberry Pi
« Reply #26 on: November 07, 2019, 10:21:04 am »
The Modbus protocol can only transmit words (16 bits) or in some functions bits, this does not mean you can not get a float or a string even, you just need to know the size and the address of the data you want to read and then type casting to the value of your internal format, for example a type single is 32 bit, so you need to read 2 words.
Actually you can, because the protocol should be interpreted as bit patterns. So consequently 16 bit float values are possible. If you really need that is another matter. Same goes for - 2 char - string encodings: as long as you encode to a bitpattern you have 2 chars. And indeed: casting will suffice to get back and forth. (one of the reasons I wrote some helper functions for sysutils, a bit simpler than Avra's bit manipulation library. Both are on this forum, both are written with hardware control in mind)
Basically any type that can be expressed as a 16 bit value or less can - of course - be used. It is up to the programmer to interpret such encoding.
« Last Edit: November 07, 2019, 10:27:18 am by Thaddy »

white_zombie

  • New Member
  • *
  • Posts: 12
Re: Modbus on Raspberry Pi
« Reply #27 on: November 07, 2019, 10:54:00 am »
Actually you can, because the protocol should be interpreted as bit patterns. So consequently 16 bit float values are possible. If you really need that is another matter. Same goes for - 2 char - string encodings: as long as you encode to a bitpattern you have 2 chars. And indeed: casting will suffice to get back and forth. (one of the reasons I wrote some helper functions for sysutils, a bit simpler than Avra's bit manipulation library. Both are on this forum, both are written with hardware control in mind)
Basically any type that can be expressed as a 16 bit value or less can - of course - be used. It is up to the programmer to interpret such encoding.
Thaddy, you are saying the same I remark, the protocol itself is made to transmit 16 bit integer, but no one stop you to handle those 16 bit with the format you want.

What I want to tell to "jdp" is that if the functions in the library only handle integers, there is no problem, just type casting those bits (16, 32 or whatever size) to the format you want.

I never use third-party modbus libraries because I wrote my own modbus library over the freepascal sockets (no indy or synapse in the middle), and I use this library every day in my work to read every kind of data form PLC (integer, floats, null terminated string, datetimes, etc).

Thaddy

  • Hero Member
  • *****
  • Posts: 10705
Re: Modbus on Raspberry Pi
« Reply #28 on: November 07, 2019, 12:16:58 pm »
Note that there is a catch: FPC actually interprets an integer to float cast and the reverse differently than e.g. C and C like languages. So you need a pointer cast and de-reference to obtain the raw value. Simple casts are NOT simply bit patterns in Freepascal.
https://wiki.freepascal.org/User_Changes_3.0#Casting_integer_variables_to_floating_point

white_zombie

  • New Member
  • *
  • Posts: 12
Re: Modbus on Raspberry Pi
« Reply #29 on: November 07, 2019, 12:53:33 pm »
Thanks Thaddy, I was not aware of that change.

In the cases I use float with modbus, the server usually compliance the 32 Bit IEEE format, so I use absolute directive instead of type casting.

Code: Pascal  [Select][+][-]
  1. var
  2.   lDword: Dword;
  3.   lSingle: Single absolute lDword;  
  4.  

To be honest, I don't use the absolute directive but instead a record with variant parts.

Code: Pascal  [Select][+][-]
  1. TMbRecord=record
  2.     Case Integer Of
  3.     0 : (DWordSigned:  LongInt);
  4.     1 : (DWordUnsigned:LongWord);
  5.     2 : (Single:       Single);
  6.     3 : (WordSigned:   Array [0..1] of SmallInt);
  7.     4 : (WordUnsigned: Array [0..1] of Word);
  8.     5 : (ByteSigned:   Array [0..3] of ShortInt);
  9.     6 : (ByteUnsigned: Array [0..3] of Byte);
  10.     7 : (Bits :        bitpacked Array [0..31] of boolean);
  11.   End;
  12.  

 

TinyPortal © 2005-2018