Recent

Author Topic: Lazarus IDE-Modbus Communication (Energy Analyzer, PascalSCADA)  (Read 7329 times)

sentago

  • New Member
  • *
  • Posts: 11
Lazarus IDE-Modbus Communication (Energy Analyzer, PascalSCADA)
« on: December 06, 2021, 11:54:05 am »
Hello to everyone.

I am new to Lazarus IDE. I have an energy analyzer. I want to receive hourly energy information from this analyzer. I did all the steps correctly by referencing a video I found on the internet. Even though I am connected to the analyzer, the Label always shows 0. What is the reason of this? Could it be due to the version of the Lazarus IDE?

Reference video: https://youtu.be/KWEKXz_ge1k

tr_escape

  • Sr. Member
  • ****
  • Posts: 410
  • sector name toys | respect to spectre
    • Github:
Re: Lazarus IDE-Modbus Communication (Energy Analyzer, PascalSCADA)
« Reply #1 on: December 06, 2021, 12:25:00 pm »
Which analyzer you have it? As mentioned MPR63 or another?

Maybe you have to read diffrent address of the modbus rtu slave.

So as I remember pascalscada has got a log system maybe you should look into it for diagnostic of your system.



sentago

  • New Member
  • *
  • Posts: 11
Re: Lazarus IDE-Modbus Communication (Energy Analyzer, PascalSCADA)
« Reply #2 on: December 06, 2021, 12:34:03 pm »
Here is the analyzer I used and its manual;

https://www.entes.com.tr/mpr-47s-0-5/

I specified the register addresses correctly

af0815

  • Hero Member
  • *****
  • Posts: 838
Re: Lazarus IDE-Modbus Communication (Energy Analyzer, PascalSCADA)
« Reply #3 on: December 06, 2021, 01:29:37 pm »
Have you applied the correct MemReadFunction normal 3 for a read on Modbus and the correct MemAdress according the Register-specs of the device.

The Video was dealing with a serial device, but you use tcp/ip. If the settings are not ok, you get nothing = 0.0.

--- edit: Install the RTTI components, put 3 TIPropertygrid on your form an connect on to the tcp_UDP_port, one to the proctocol and one to the Tag.
If you start, you can see the information like in the Objectinspector and look from the tcp_port upgoing if the any errormessage.

The Port must be Active and you should see TXBytes and RXBytes raising.
On the protocoldriver you see normal the AvgTagUpadateTime as a value not Zero
In the PLCTag, Comm* should be ok and the Last*Sync should ne ioOk

« Last Edit: December 06, 2021, 01:39:07 pm by af0815 »
regards
Andreas

sentago

  • New Member
  • *
  • Posts: 11
Re: Lazarus IDE-Modbus Communication (Energy Analyzer, PascalSCADA)
« Reply #4 on: December 06, 2021, 01:49:22 pm »
Hi af0815,

First of all, thank you for your answer.

I tried the process in the picture with TCP on PC. I just wanted to show you as an example. I performed all the operations related to the energy analyzer with the serial device (TSerialPortDriver). I followed the steps in the video exactly. MemAdress and MemRead Function values are also correct.

avra

  • Hero Member
  • *****
  • Posts: 2291
    • Additional info
Re: Lazarus IDE-Modbus Communication (Energy Analyzer, PascalSCADA)
« Reply #5 on: December 06, 2021, 02:06:23 pm »
Even though I am connected to the analyzer, the Label always shows 0. What is the reason of this? Could it be due to the version of the Lazarus IDE?
How do you know that you are really connected to the analyzer? Having physical connection isn't enough. You need to check connection with some external application. Manufacturer offer software "Log Reader Program", but when you know relevent MODBUS registers and comm parameters - there are others like https://www.modbustools.com, https://www.modbusdriver.com/modpoll.html and https://bitbucket.org/heXor/openmodbustool/src/master/ (test server). First step would be to test connection from your pc using some MODBUS client application, and see if you get expected data from the device using some already working app. Then second step would be to test connection from your app to some MODBUS server application that would simulate your device MODBUS registers and where you can monitor if data you are sending with your Lazarus application is showing in the relevant registers on MODBUSserver. Even more advanced usage would be to use Wireshark for spying MODBUS messages, but that is not really needed. You can even skip PascalSCADA and directly use simple MODBUS lib as https://sourceforge.net/projects/mbutils/files/, https://github.com/coassoftwaresystems/delphi-modbus or already mentioned openmodbustool.

Manufacturer seams to have different MODBUS register tables for older and newer firmware. Are you using the correct one?

You might also face register naming confusion (start with 0 or 1, 30001 or 0000...), if you do not know enough about MODBUS it self:
https://support.industry.siemens.com/tf/ww/en/posts/modbus-registers-address-confusion/223613/
https://electronics.stackexchange.com/questions/505189/modbus-register-address-vs-register-number-absolute-address-vs-offset

You should follow this tutorial (TSerialPortDriver is not for TCP - if you have Ethernet option installed on your device):
https://www.pascalscada.com/modbus-rtu-and-tcp/
« Last Edit: December 06, 2021, 02:09:50 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

sentago

  • New Member
  • *
  • Posts: 11
Re: Lazarus IDE-Modbus Communication (Energy Analyzer, PascalSCADA)
« Reply #6 on: December 06, 2021, 02:44:36 pm »
Even though I am connected to the analyzer, the Label always shows 0. What is the reason of this? Could it be due to the version of the Lazarus IDE?
How do you know that you are really connected to the analyzer? Having physical connection isn't enough. You need to check connection with some external application. Manufacturer offer software "Log Reader Program", but when you know relevent MODBUS registers and comm parameters - there are others like https://www.modbustools.com, https://www.modbusdriver.com/modpoll.html and https://bitbucket.org/heXor/openmodbustool/src/master/ (test server). First step would be to test connection from your pc using some MODBUS client application, and see if you get expected data from the device using some already working app. Then second step would be to test connection from your app to some MODBUS server application that would simulate your device MODBUS registers and where you can monitor if data you are sending with your Lazarus application is showing in the relevant registers on MODBUSserver. Even more advanced usage would be to use Wireshark for spying MODBUS messages, but that is not really needed. You can even skip PascalSCADA and directly use simple MODBUS lib as https://sourceforge.net/projects/mbutils/files/, https://github.com/coassoftwaresystems/delphi-modbus or already mentioned openmodbustool.

Manufacturer seams to have different MODBUS register tables for older and newer firmware. Are you using the correct one?

You might also face register naming confusion (start with 0 or 1, 30001 or 0000...), if you do not know enough about MODBUS it self:
https://support.industry.siemens.com/tf/ww/en/posts/modbus-registers-address-confusion/223613/
https://electronics.stackexchange.com/questions/505189/modbus-register-address-vs-register-number-absolute-address-vs-offset

You should follow this tutorial (TSerialPortDriver is not for TCP - if you have Ethernet option installed on your device):
https://www.pascalscada.com/modbus-rtu-and-tcp/

Hi avra,

Thank you for your answer.

I'll look into these and test again. I will post the results right here. The analyzer also has an ethernet port. I will test with TCP/IP as well.

sentago

  • New Member
  • *
  • Posts: 11
Re: Lazarus IDE-Modbus Communication (Energy Analyzer, PascalSCADA)
« Reply #7 on: December 07, 2021, 07:57:31 am »
Hello again everyone

Yesterday I tried the Lazarus IDE with TCP/IP. I took a video about it and uploaded it. Where am I doing wrong?

https://youtu.be/FRWKIlOxYgM


DonAlfredo

  • Hero Member
  • *****
  • Posts: 1530
Re: Lazarus IDE-Modbus Communication (Energy Analyzer, PascalSCADA)
« Reply #8 on: December 07, 2021, 08:11:04 am »
I would advice you to set:
PLCStation := 1;
MemAddress := 400001;

sentago

  • New Member
  • *
  • Posts: 11
Re: Lazarus IDE-Modbus Communication (Energy Analyzer, PascalSCADA)
« Reply #9 on: December 07, 2021, 08:30:14 am »
I would advice you to set:
PLCStation := 1;
MemAddress := 400001;

This time, the values sent and received on the simulation also change, but the label part still shows the value 0 in the Lazarum Form window.  :(

af0815

  • Hero Member
  • *****
  • Posts: 838
Re: Lazarus IDE-Modbus Communication (Energy Analyzer, PascalSCADA)
« Reply #10 on: December 07, 2021, 08:39:21 am »
MemAddress := 400001;

Not supported by pascalscada - see https://www.pascalscada.com/modbus-rtu-and-tcp/
Quote
MemAddress: Address of the input/output/register that you want to read/write. The addresses start from zero, always. Do not use the address notation 1xxxxx, 2xxxxx, 3xxxxx, 4xxxxx, as it is not supported.
And remember, adresses always start from 0 ! in PascalScada.

@sentago: have you used the RTTI to look if the basics are working ?
« Last Edit: December 07, 2021, 08:41:41 am by af0815 »
regards
Andreas


sentago

  • New Member
  • *
  • Posts: 11
Re: Lazarus IDE-Modbus Communication (Energy Analyzer, PascalSCADA)
« Reply #12 on: December 07, 2021, 09:16:29 am »
MemAddress := 400001;

Not supported by pascalscada - see https://www.pascalscada.com/modbus-rtu-and-tcp/
Quote
MemAddress: Address of the input/output/register that you want to read/write. The addresses start from zero, always. Do not use the address notation 1xxxxx, 2xxxxx, 3xxxxx, 4xxxxx, as it is not supported.
And remember, adresses always start from 0 ! in PascalScada.

@sentago: have you used the RTTI to look if the basics are working ?

It finally worked but the weird thing is that when I add RTTI components on the Form it works. If there are no RTTI components, label 0 appears.  :o


sentago

  • New Member
  • *
  • Posts: 11
Re: Lazarus IDE-Modbus Communication (Energy Analyzer, PascalSCADA)
« Reply #13 on: December 07, 2021, 12:48:38 pm »
Hey @af0815

TCP works in simulation, but when I connect to the analyzer, DeviceGatewayFailedRespond error appears in LastASyncReadStatus  :'(

af0815

  • Hero Member
  • *****
  • Posts: 838
Re: Lazarus IDE-Modbus Communication (Energy Analyzer, PascalSCADA)
« Reply #14 on: December 07, 2021, 01:10:34 pm »
Have you the reading working without pascal ?
If yes, you can only use wireshark to inspect the working way and the not working way.

When the simulation is ok, there must be a basic communication problem.
regards
Andreas

 

TinyPortal © 2005-2018