Lazarus

Programming => General => Topic started by: jdp on November 02, 2019, 08:21:46 pm

Title: Modbus on Raspberry Pi
Post by: jdp on November 02, 2019, 08:21:46 pm
Hi.

What should I use to get Modbus Serial working on Raspberry Pi. I have it all working in Python but would like to get it working in Lazarus as well.

I tried to install Pascal Scada on the Pi but it wont compile as I am using to new FPC and Lazarus.
Title: Re: Modbus on Raspberry Pi
Post by: af0815 on November 03, 2019, 08:39:46 am
Pascal Scada is working here on Win32/64, Raspian (as well Jessie,Buster), Debian -Linux 64,... out of the box. Sometimes there are issues with the trunk of fpc, because of changes in the fcl. I use actual fixes of fpc and fixes of Lazarus for production enviroment.

This version works too (need Indy) https://github.com/coassoftwaresystems/delphi-modbus - can master and slave, but is a little tricky to understand. On my git i have an older version frozen for my Lazarus/FPC version with a special version of Indy of mine.
Title: Re: Modbus on Raspberry Pi
Post by: Thaddy on November 03, 2019, 08:49:49 am
I tried to install Pascal Scada on the Pi but it wont compile as I am using to new FPC and Lazarus.
What does the compiler say? "won't compile" without any other information isn't helpful...

I suppose the bottlenecks are Bgracontrols and  Bgrabitmap, that currently do not compile for arm (fpc 3.2 and fpc trunk 43374 + ).
Title: Re: Modbus on Raspberry Pi
Post by: jdp on November 04, 2019, 07:46:01 am
I tried to install Pascal Scada on the Pi but it wont compile as I am using to new FPC and Lazarus.
What does the compiler say? "won't compile" without any other information isn't helpful...

I suppose the bottlenecks are Bgracontrols and  Bgrabitmap, that currently do not compile for arm (fpc 3.2 and fpc trunk 43374 + ).

Yes, Thaddy you are correct. It does not compile when I try to install from the online lib manager and it breaks when it wants to install those components.
I did not add the errors for it as I asked what the best Modbus module is.  Is Pascal Scada the best Modbus library for Lazarus?

Regards.
Title: Re: Modbus on Raspberry Pi
Post by: jdp on November 04, 2019, 11:43:39 am
Should I use a older version of Lazarus so Pascal Scada compiles? If so what version will work on the Raspberry Pi.
Title: Re: Modbus on Raspberry Pi
Post by: Thaddy on November 04, 2019, 12:09:24 pm
I don't know where it got broken for arm but it is quite some time ago - years -. Better to ask the maintainers of BGRA* to fix the regression than to install an old and un-maintained Lazarus....

Note it is possible to compile just the modbus units for console I believe, and those units all compile (but I did not test them). It is pure the BGRA libraries that fail.
Title: Re: Modbus on Raspberry Pi
Post by: jdp on November 04, 2019, 12:39:29 pm
Yes I only want the cli modbus parts anyway. What modules should I compile to get that working? Can you point me in a direction.
Title: Re: Modbus on Raspberry Pi
Post by: avra on November 05, 2019, 10:18:02 am
It does not compile when I try to install from the online lib manager and it breaks when it wants to install those components.
Try to just download PascalSCADA and install packages manually with opening each package and deleting dependencies to BGRA packages. Then report if that helped.
http://www.pascalscada.com/how-install-pascalscada/
Title: Re: Modbus on Raspberry Pi
Post by: Thaddy on November 05, 2019, 10:40:36 am
@Avra
Do you know a good emulator? (I know there is one from Siemens but that feels uncomfortable - and is not free!)
Your answer was basically what I did, and factored out some code from the GUI: PascalScada is a bit of a mess in the sense that it has no good separation between functionality and user interface.
It would be great if we had something like that for our Raspberry Pi's
Title: Re: Modbus on Raspberry Pi
Post by: tr_escape on November 05, 2019, 11:26:40 am
There some instructions by qemu on windows like as below link but not tested:

https://projects-raspberry.com/simulation-raspberry-pi-emulator-for-windows-10-using-qemu/ (https://projects-raspberry.com/simulation-raspberry-pi-emulator-for-windows-10-using-qemu/)
Title: Re: Modbus on Raspberry Pi
Post by: Thaddy on November 05, 2019, 11:31:02 am
There some instructions by qemu on windows like as below link but not tested:

https://projects-raspberry.com/simulation-raspberry-pi-emulator-for-windows-10-using-qemu/ (https://projects-raspberry.com/simulation-raspberry-pi-emulator-for-windows-10-using-qemu/)
No, I mean a simulator for hardware. Not the OS. Avra knows what I mean.
Title: Re: Modbus on Raspberry Pi
Post by: tr_escape on November 05, 2019, 11:56:14 am
Ok.

As I know only modbus simulator for windows that name is modrsim2

https://sourceforge.net/projects/modrssim2/ (https://sourceforge.net/projects/modrssim2/)

Title: Re: Modbus on Raspberry Pi
Post by: Thaddy on November 05, 2019, 12:32:46 pm
Yes, something like that (at first glance) tnx!
Title: Re: Modbus on Raspberry Pi
Post by: tr_escape on November 05, 2019, 01:24:30 pm
Yes, something like that (at first glance) tnx!

Also if your OS is windows you can create a virtual com port by com0com project http://com0com.sourceforge.net/ (http://com0com.sourceforge.net/)

Create two virtual com port as figured this link https://mehmetulukaya.files.wordpress.com/2016/12/com0com.png (https://mehmetulukaya.files.wordpress.com/2016/12/com0com.png)

Set your modrsim2 com port to the one of virtual com and connect by pascalscada (or whatever your software) to other virtual com port (com15 for modrsim2 and com16 for your software).

com0com will be create a pipe between two software like as nearly real com port.

Title: Re: Modbus on Raspberry Pi
Post by: mig-31 on November 05, 2019, 01:38:35 pm
PascalScada consist of  5 packages (lpk files). I have not tested the newest version. In version 7.3 only pascalscada-HMI depends on BRGABitmap. For ModBus TCP or RTU(RS-232) only pascalscada and  pascalscada-common are needed. I did this a year ago and it worked. I had same problem with BRGABitmap and PascalScada on CentOS 7 x86-64.
Title: Re: Modbus on Raspberry Pi
Post by: DonAlfredo 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 ?
Title: Re: Modbus on Raspberry Pi
Post by: korba812 on November 05, 2019, 04:02:15 pm
There is another library for modbus:
https://sourceforge.net/projects/mbutils/ (https://sourceforge.net/projects/mbutils/)
Title: Re: Modbus on Raspberry Pi
Post by: Thaddy 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.
Title: Re: Modbus on Raspberry Pi
Post by: af0815 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/ (http://com0com.sourceforge.net/)
IMHO not working on an actual Win10/64 because the drivers are not (correct)signed. My windows refused it.
Title: Re: Modbus on Raspberry Pi
Post by: jdp 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.
Title: Re: Modbus on Raspberry Pi
Post by: jdp on November 06, 2019, 08:16:54 am
There is another library for modbus:
https://sourceforge.net/projects/mbutils/ (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.
Title: Re: Modbus on Raspberry Pi
Post by: avra 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 (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?
Title: Re: Modbus on Raspberry Pi
Post by: Thaddy 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.
Title: Re: Modbus on Raspberry Pi
Post by: jdp 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/


Title: Re: Modbus on Raspberry Pi
Post by: avra 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:-)
Title: Re: Modbus on Raspberry Pi
Post by: white_zombie 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.
Title: Re: Modbus on Raspberry Pi
Post by: Thaddy 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.
Title: Re: Modbus on Raspberry Pi
Post by: white_zombie 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).
Title: Re: Modbus on Raspberry Pi
Post by: Thaddy 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
Title: Re: Modbus on Raspberry Pi
Post by: white_zombie 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.  
Title: Re: Modbus on Raspberry Pi
Post by: Thaddy on November 07, 2019, 12:56:44 pm
Absolute will do indeed, since that is basically a pointer de-referenced with a specific type. I would not recommend it in most cases, but here it is a good solution.
Title: Re: Modbus on Raspberry Pi
Post by: cgd on November 07, 2019, 09:34:55 pm
I made my own routines to Communicate Raspberry PI3B/3B+ with PLCs by Modbus ASCII (using TSdpoSerial component) and Modbus TCP (using TIdTCPClient component)... Just in case, let me know if you need any help.
Title: Re: Modbus on Raspberry Pi
Post by: avra on November 08, 2019, 09:07:08 am
I don't use the absolute directive but instead a record with variant parts.
Then you will probably like BitHelpers from my signature  ;)
Title: Re: Modbus on Raspberry Pi
Post by: jdp on November 08, 2019, 09:09:46 am
I got PascalScada modbus installed. fabio who developes it helped me to get it installed. Now I need to figure out how it works to read a normal regitser using it. Who knows how it works? I have it working in Python using minimalmodbus. I now want the same in Lazarus usinf PascalScada.


Code: Pascal  [Select][+][-]
  1. import minimalmodbus
  2.  
  3. vsd = minimalmodbus.Instrument('/dev/ttymeter', 1 , 'rtu')
  4. vsd.serial.parity = serial.PARITY_NONE
  5. vsd.serial.baudrate = 9600
  6. vsd.serial.timeout = 1    
  7. vsd.serial.flushInput()
  8.  
  9.  
  10. watts = vsd.read_float(0x000C  , functioncode=4 ,  number_of_registers=2)
  11.  
  12.  
Title: Re: Modbus on Raspberry Pi
Post by: jdp on November 08, 2019, 09:12:12 am
I started with a simple test program but I am not sure what all the steps should be.
Code: Pascal  [Select][+][-]
  1. program mbustest;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}
  7.   cthreads,
  8.   {$ENDIF}
  9.   Classes,
  10.   ModBusSerial,
  11.   SerialPort,
  12.   PLCTagNumber;
  13.  
  14.  
  15. var
  16.  
  17.   spd        : TSerialPortDriver;
  18.   mbd        : TModBusRTUDriver;
  19.   watts_tag  : TPLCTagNumber;
  20.  
  21.  
  22.  
  23.   watts  : Double;
  24.  
  25. begin
  26.  
  27.  
  28.  
  29.      //Set the comport properties
  30.      spd.COMPort := '/dev/ttymeter';
  31.      spd.BaudRate := br9600;
  32.      spd.Timeout := 1;
  33.      spd.Paridade := spNone;
  34.  
  35.  
  36.  
  37.      //Set the Modbus properties
  38.      mbd.CommunicationPort := spd;
  39.      //mbd.
  40.  
  41.  
  42.      //Set the tag properties
  43.      watts_tag.PLCStation := 1;
  44.  
  45.  
  46.  
  47.      //Read the regitsers
  48.  
  49.  
  50.  
  51.      //Print the values
  52.      write('Meter Watss : ');
  53.      writeln(watts);
  54.  
  55.  
  56. end.
Title: Re: Modbus on Raspberry Pi
Post by: Thaddy on November 08, 2019, 09:36:13 am
I don't use the absolute directive but instead a record with variant parts.
Then you will probably like BitHelpers from my signature  ;)
@Avra
Aside: Maybe we should integrate each others code for my suggested patch (there is a willingness to accept it for sysutils helpers from devel's)
Maybe we can work together and  use some of your code for the helpers? My code is more basic, bare essentials,  and your code has more features.
Title: Re: Modbus on Raspberry Pi
Post by: avra on November 08, 2019, 11:05:45 am
I started with a simple test program but I am not sure what all the steps should be.
Do you really need console application? There are several GUI modbus demos in Examples directory. It would be much easier if you examine them and try to adapt them to your needs. You can even use some of the mentioned MODBUS slave simulators for a quick startup convenience. From your code and guessed expectations I think that one of the 2 mentioned libraries would be more appropriate.

Maybe we should integrate each others code for my suggested patch (there is a willingness to accept it for sysutils helpers from devel's)
Maybe we can work together and use some of your code for the helpers? My code is more basic, bare essentials, and your code has more features.
Feel free to use whatever you want from my code. If discussion is needed, then PM me or open a new thread. On the other hand I use almost every features from BitHelpers so if merge is not feature rich (especially custom format data printing) then I can simply continue using original BitHelpers. Not a problem, as long as there are no conflicts.

If you remember, we discussed adding BitHelpers to sysutils, and at first I was convinced that it was the way to go, but because this issue could not be fixed:
Code: Pascal  [Select][+][-]
  1. MyWord.Byte[1].Bit[7] := true; // %0000000100000010 MyWord equals 258 (Beware!!! This DOES NOT set a bit in MyWord !!!)
I felt that it did not belong there - having something that potentially could lead to bugs in user code. I know that documenting such behavior should be enough, but many people do not read every bit of docs and besides compiler lets them use it in such a way so they might expect different from what can be. I would satisfy even with a compiler warning or error in such case, but could not find a way to do it. That's why I wanted to simply donate BitHelpers unit to FPC (and documenting it including mentioned behavior), but I was late for 3.2 so I was initially hoping to do it for 3.4. Anyway, as already said if you come up with something else I am quite fine with that, too. Merge is fine, but leaving our code separate is also fine.
Title: Re: Modbus on Raspberry Pi
Post by: jdp on November 08, 2019, 11:58:06 am
Yes I need cli as the pi wont have a gui desktop. It runs the light Os without any gui stuff on it.
I am looking at the gui samples to try and figure out how this works but if sombody knows off hand then please help out a fellow developer lol.
Title: Re: Modbus on Raspberry Pi
Post by: MarkMLl on November 08, 2019, 12:08:48 pm
Yes I need cli as the pi wont have a gui desktop. It runs the light Os without any gui stuff on it.

Remember that you can always tunnel X11 programs over SSH, or install the non-lite variant of the OS and get a desktop using VNC.

MarkMLl
Title: Re: Modbus on Raspberry Pi
Post by: Thaddy on November 08, 2019, 12:12:30 pm
Code: Pascal  [Select][+][-]
  1. MyWord.Byte[1].Bit[7] := true; // %0000000100000010 MyWord equals 258 (Beware!!! This DOES NOT set a bit in MyWord !!!)
That has already been addressed in the patch(es), but the original request is somewhat obfuscated by unnecessary comments.
The real issue is that some ordinal formats are treated differently - and wrong! - by the compiler: it is a sign issue, e.g. 128 etc instead of -128. (actually that one works)
Fixing that without {$rangechecks off} takes quite some thought, unless the compiler behaves as it should. Luckily most cases do not pose a problem, but 2 cases do.
And I *must* do so, because otherwise it will break existing things. The actual code is straight forward and rather basic. The compiler behavior is not!
The current status is that all tests pass with range checks off (even the initial patch) but there happens to be a needless expansion in those two cases and only for Intel.
My walking bit demo is  the proof. It is exhaustive. The latest patch is because I was wrong footed. The first patch needs just an extra type cast (not a removal as was suggested)
Title: Re: Modbus on Raspberry Pi
Post by: jdp on November 08, 2019, 12:51:50 pm
Nope. I do not want to use any form of GUI. It adds a lot of overhead and I have other reasons. I need it to work on CLI. It works in Python with a couple of lines of code. Not sure why it is this difficult in Lazarus to do the same. I just want to read some registers using modbus. I am not a Lazarus guru that can build his own libs and downt have the time to do it also. I also asked Fabio if he can give me a sample ap. I hope he will as this should not be too complicated to do. I just don't know what to do as there is no documentation I can follow other than the GUI apps.
Title: Re: Modbus on Raspberry Pi
Post by: MarkMLl on November 08, 2019, 12:58:54 pm
That's fine. But you're putting yourself in a position where you're having to modify working code using a development tool with which you're not entirely familiar, and you're also asking everybody else to move away from a combination with which they're familiar.

You'd be in a stronger position if you first got the well-tested program working so that you know how things behave, and then investigated ripping out the GUI stuff etc. that you don't need.

Or at least that's the approach I've found most useful over the last 30 years or so.

MarkMLl
Title: Re: Modbus on Raspberry Pi
Post by: jdp on November 08, 2019, 02:01:12 pm
Mark I am not asking anybody to move away from anything. I am asking for help with a CLI app only. If there is no Modbus Lib for CLI only then there is a gap for one as a lot of IOT edge devices like the Pi will run headless in command line mode only. Modbus is a protocol that a lot of meters use and I see the need for such a lib in Lazarus. But again that is my opinion and need at this stage.

I guess I can build it all in C if I have to. The reason I don't use Python is the code is open and people can mess with it as the code is open for all to read.
Title: Re: Modbus on Raspberry Pi
Post by: avra on November 08, 2019, 02:36:30 pm
If there is no Modbus Lib for CLI only then there is a gap for one as a lot of IOT edge devices
Did you read my previous message at all about 2 other MODBUS libraries and one even comming with CLI demo?
https://forum.lazarus.freepascal.org/index.php/topic,47289.msg338661.html#msg338661
Title: Re: Modbus on Raspberry Pi
Post by: Thaddy on November 08, 2019, 04:47:59 pm
@Avra
Michael has accepted the patch, with a few tweaks, so trunk has basic bit manipulation for all integer types now... :D O:-)
If anyone wants more features, I will refer to your implementation.
And thx Bart for extensive testing!
- setbit()
- clearbit()
- togglebit()
- TestBit()
- ToBinString

All ranges supported up to Qword.
Title: Re: Modbus on Raspberry Pi
Post by: jdp on November 08, 2019, 05:24:34 pm
If there is no Modbus Lib for CLI only then there is a gap for one as a lot of IOT edge devices
Did you read my previous message at all about 2 other MODBUS libraries and one even comming with CLI demo?
https://forum.lazarus.freepascal.org/index.php/topic,47289.msg338661.html#msg338661

Hi yes I did. Thanks for pointing them out to me.

As there is no documentation I have no idea how they work to read a float from a register.
Title: Re: Modbus on Raspberry Pi
Post by: white_zombie on November 08, 2019, 09:43:52 pm
Then you will probably like BitHelpers from my signature  ;)

I already known your library, although I have not used it yet, mostly because over the years I had been writing my own routines for this, but your library is far more complete that what I have, it would be great to have in integrated in FPC.

What I known very well is your pasettimino library, it save me a lot of work in one of my projects, it was very helpful to have the communication with Siemens PLC done without any dependencies in external dlls. By the way, I am the guy who send you the patches for the Linux compatibility of the library.
Title: Re: Modbus on Raspberry Pi
Post by: avra on November 08, 2019, 11:43:19 pm
As there is no documentation I have no idea how they work to read a float from a register.
You should check with your hardware device manual, but floats are usually with single precision (32 bit) and stored in two registers next to each other. You find address of it in the documentation, and load starting register (16 bits) and following register (also 16 bits). Usually you use MODBUS function with parameters like first register address and number of registers to read. Then you read directly 32 bits from 2 registers and cast them to single float type. Beware that your device may have different endianess - if it does you have to adapt to that. That's all.

What I known very well is your pasettimino library, it save me a lot of work in one of my projects, it was very helpful to have the communication with Siemens PLC done without any dependencies in external dlls.
I am always glad to see pasettimino being used. It is based on Arduino lib so it is not thread safe yet. Hopefully I will catch time to change that.

By the way, I am the guy who send you the patches for the Linux compatibility of the library.
Nice to see you here too, Victor - and thank you once again for the patches.  :D
TinyPortal © 2005-2018