The following instructions are for both Modbus RTU (TModBusRTUDriver class) and Modbus TCP (TModBusTCPDriver class). To configure a protocol+tag connections you have to do:
- Insert a communication port appropriate for the chosen Modbus protocol:
- TTCP_UDPPort for Modbus TCP;
- TSerialPortDriver for Modbus RTU;
- Insert the chosen protocol component;
- Connect the protocol to the port, through the “CommunicationPort” property;
- Insert the tags manually or through the “Tag builder” tool
- If you insert the tags manually, set the properties as described below;
- Connect the tag to the protocol driver through the ProtocolDriver property present in each tag.
Both protocol classes support the following tag classes:
- TPLCTagNumber
- TPLCBlock
- TPLCStruct
- TPLCString
To configure a tag to use Modbus, you must configure the following tag properties:
- PLCStation: Modbus equipment address. For Modbus TCP, this property has its value set to 1, it usually depends on the Modbus Server implementation.
- 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.
- MemReadFuntion: Function that will be used to read the tag. See table below.
- MemWriteFuntion: Function that will be used to write tag values. See table below.
For the MemReadFunction and MemWriteFunction properties the following values are accepted according to the desired memory area:
DESIRED AREA | MemReadFunction | MemWriteFunction |
---|---|---|
Digital inputs | 2 | 0 |
Coils (digital outputs) | 1 |
5 (TPLCTagNumber) 15 (TPLCTagNumber TPLCBlock TPLCStruct TPLCString) |
Registers | 3 |
6 (TPLCTagNumber) 16 (TPLCTagNumber TPLCBlock TPLCStruct TPLCString) |
Analog registers (analog inputs) | 4 | 0 |
Device status | 7 | 0 |
You need to know the ModBus functions your device supports.
Hi,
I need to read digital inputs from an ICPDAS modbus module, M-7054, using standard 02 function “(0x02) Read discrete inputs”.
The string to send into module is “adr_byte 0x02 start_input (2bytes) count (2bytes) CRC (2bytes)”. The response will be according to the standard.
Please tell me how do I do this, using PascalScada Tags?
I’m using 0.7.3 version.
Hi!
Few steps:
1) Insert a TSerialPortDriver into your app and set up it with the same serial settings of your device and activate it.
2) Insert a TModbusRTUDriver and set CommunicationPort Property to point to Serial Port created on the previous step.
3) Insert a TPLCTagNumber and set:
3.1) MemAddress to point to your Digital Input (address starts from zero – 0)
3.2) MemReadFunction to 2 “(0x02) Read discrete inputs”
3.3) PLCStation to point to your Modbus slave address;
3.4) Set property ProtocolDriver to point to ModbusDriver created in step 2.
3.5) Assure that TagType is pttDefault or pttBit;
4) Put a THMILabel into your app/form and link it with the tag created at step 3.
5) If everything is set accordingly, you will see the label showing values 0 or 1, depending on the state of your digital input. The digital input can vary depending on your Modbus device.
Hi fabio
i have installed the software and done some basic works like configuring modbus device etc, after that i was trying to display the datas in the chart but i was unable to bind the tags to the chart. Could you pls instruct me how to do this and following features like alarming and reporting or pls provide me a deatiled documentation of those above mentioned .
Hi fabio,
i have installed pascal scada and done some stuff like creating tags and configured a modbus tcp device. when i try to get data of the device to be displayed in the charts provided in the package i was not able to bind the tags to chart. Could you pls tell me how to bind the tags and also an explanation about some features like alarms, reporting etc. Pls provide me a deatiled documentation .
Hi Mr. JAYAKRISHNAN!
There are missing features on PascalSCADA, due to I have tried to keep it working with Lazarus and Delphi:
** Alarm historic
** Historic
** Recipes
** User management stored in file/database;
** Tag chart connection.
Since I cutted off the Delphi support, some things have better progress, since I don’t need anymore to think multiple IDE support. I have two things started, but not finished:
** Lazarus TAChart series datasource linked with PLC Tags (started, near to be finished)
** Database abstraction (I’m researching the better way to achieve this)
So, for now, I’ll have to do your chartings using the components of TAChart with few lines of code, to add new values and delete old values.
Hi, Does PascalSCADA supports MODBUS ASCII protocol?
I see WEST ASCII there, but I think it is quite different from MODBUS ASCII.
Thanks
Konrad
Hi Konrad!
Modbus ASCII isn’t supported yet. At least, I don’t reserved time to do that and anybody else…
Also, you are the first that had requested this.
Hi Fabio,
I have a Project with 1xModBusRTU and 4xModBusTCP drivers (I want to read from 4 IP addresses).
The problems start when I want to close Lazarus and the Project is open in Lazarus – Lazarus locks my Windows10 with 100% CPU usage.
The compiled project does the same – 100% CPU usage.
OS: Windows 10 64bit, Lazarus versions tested 2.0.10 and 2.2.0RC1
I would send you my code if you want to take a look at it.
With just one ModBusRTU and one ModBusTCP drivers it works fine.
Can you test the same application on Windows 7 environment? I don’t have any Windows 10 environment configured.
Or if you have time and can share your environment with me, I can investigate using anydesk/teamviewer… If you agree, please send e-mail to fabio at pascalscada dot com
I apologize for late answer. I think I solved the problem.
I have 4x TTCP_UDPPort and if I set the events for all the error handling (OnCommErrorReading … OnCommPortOpenError) for every port – here is the problem with 100% CPU usage.
Here is my code for the events (all 4 ports are using the same procedures, no extra procedures for Port2-Port4):
procedure TfrmMain.TCPPort1CommPortClosed(Sender: TObject);
var
portName: String;
begin
portName := TTCP_UDPPort(Sender).Name;
mmLog.Lines.Add(portName + ‘ Port closed’);
end;
procedure TfrmMain.TCPPort1CommPortCloseError(Sender: TObject);
var
portName: String;
begin
portName := TTCP_UDPPort(Sender).Name;
mmLog.Lines.Add(portName + ‘ Port close error’);
end;
procedure TfrmMain.TCPPort1CommPortDisconnected(Sender: TObject);
var
portName: String;
begin
portName := TTCP_UDPPort(Sender).Name;
mmLog.Lines.Add(portName + ‘ Port disconnected’);
end;
procedure TfrmMain.TCPPort1CommPortOpened(Sender: TObject);
var
portName: String;
begin
portName := TTCP_UDPPort(Sender).Name;
mmLog.Lines.Add(portName + ‘ Port opened’);
end;
procedure TfrmMain.TCPPort1CommPortOpenError(Sender: TObject);
var
portName: String;
begin
portName := TTCP_UDPPort(Sender).Name;
if TTCP_UDPPort(Sender).LastOSErrorNumber 0 then
mmLog.Lines.Add(portName + ‘ Port open error: ‘ + IntToStr(TTCP_UDPPort(Sender).LastOSErrorNumber) +
‘: ‘ + TTCP_UDPPort(Sender).LastOSErrorMessage);
tbRun.Down := False;
isRunning := False;
tbRunClick(self);
end;
After removing these events, it looks it runs fine, although I didn’t do some extensive testing.
Hi Fabio,
Is it possible to implement Modbus TCP master / slave communication between two freepascal app using PascalSCADA?
Thanks!
Laurent
Hi Mr. Belanger
PascalSCADA has only master/client implementation of Modbus RTU/TCP protocol stack. PascalSCADA can’t communicate with other PascalSCADA implementation because it doesn’t have slave/server implementation of these protocols. I don’t have free time to do that, but it’s possible to do. I finished the move from SVN to Github. So, now is more easy receive these cool features
I am kind of new on Modbus. I have installed pascalscada on Lazarus. Now I would like to use it with Arduino. I need some sample code on pascalscada and Arduino. Where can I find some sample code for it?
Hi Mr. Simonsen!
Well, I’m not a arduino enthusiast, so I can’t help you on the arduino side. The unique thing that I know is that if arduino supports the standart modbus funcitons (0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x0f and 0x10) PascalSCADA will communicate with it. The unique thing that maybe causes some difficulties, is a setting to avoid pascalscada send packets when it’s in idle state that will make your arduino cpu usage high. But this settings is just a property that should be set to false.
I helped some people in the past, with the promise of when the prototype is done, they will send-me a full arduino example. For now, I received nothing.
Fabio,
I use Simply Modbus Master program that I was able to turn on some LEDs from Arduino. I am not sure how to do this from PascalScada. Here is what I have done so far on PascalScada. Add SerialPortDriver1 (setbaudrate as 9600 and ComPort as Com3). Then add ModbusRTUDriver1 (CommunicationPort as SerialPortDriver1). I am not sure which tag do we use to write code to Arduino. Here is the code which I need to send Arduino to turn on LEDs. To turn on first LEDs is 01 06 00 00 00 01 48 0A. To turn off the first LEDs is 01 06 00 00 00 00 89 CA. All I know is the first code for which slave and the sixth is turn off or on LEDs – 00 for off and 01 for on. For the Second LED to turn on is 01 10 00 00 00 02 04 00 01 00 00 A2 6F To turn off the second LED is 01 10 00 00 00 02 04 00 00 00 00 F3 AF.
I’m not sure how to do this. Do we use PLCTaqgNumber1?
Sorry for taking too much time to reply. I have problems with old email address. Today I updated the site to use the new one.
Put a TPLCTagNumber and set
MemAddress = 0
MemReadFunciton = 3 //maybe this is unnecessary.
MemWriteFunction = 6
PLCStation = 1
ProtocolDriver = ModbusRTUDriver1
TagType = pttDefault or pttWord (both unsigned 16 bit)
Then in your source do:
yourPLCTagNumber.Value := 1; //turn on
yourPLCTagNumber.Value := 0; //turn off
Then
Hi Fabio,
I could not find instruction how to send out this code from PascalScada. The code which I need to send out is 01 06 00 00 00 01 48 0A to turn on one LED. To turn off LED is 01 06 00 00 00 00 89 CA. For second LED to turn on is 01 10 00 00 00 02 04 00 00 00 00 A2 6F. Second LED to turn off is 01 10 00 00 00 02 04 00 00 00 00 F3 AF. I have more LED but I want to stat with this LED for now.
What I have on form
SerialPortDriver1
set BaudRate as br9600
ComPort as COM3
ModBusRTUDriver1
set CommunicationPort as SerialPortDriver1
I am not sure what is next or which Tags Should we use?
Hi Mr. Reed!
I replied you on a previous message. Again sorry by this mistake due my lack of attention on my e-mail address.
Hi Fabio, how to read 16bit Signed integer Modbus RTU/TCP ?
I was try all TagType but failed to read.
Sorry for taking too much time to reply. I have problems with old email address. Today I updated the site to use the new one.
Just change change yourTag.TagType to pttSmallInt (signed 16 bit integer)
Yes I can use it, but only until minus -500 to read.
Strange. Can you show the properties of your tag? Your variable has some kind of scale?
This from .lfm file :
object PLCTagNumber1: TPLCTagNumber
TagGUID = ‘{60AB3B0D-66D9-4E16-9542-7300FEA456BC}’
OnAsyncValueChange = PLCTagNumber1AsyncValueChange
PLCRack = 0
PLCSlot = 0
PLCStation = 1
MemFile_DB = 0
MemAddress = 1803
MemSubElement = 0
MemReadFunction = 3
MemWriteFunction = 0
ProtocolDriver = modbustcp
LongAddress = ”
TagType = pttSmallInt
EnableMaxValue = False
EnableMinValue = False
MaxValue = 1
Left = 440
Top = 256
end
Hi Fabio!
How can I change the tagtype programmatically?
Yes, you can . Just do
YourTag.tagType := pttDword; // if you want change it to dword data type
On your source code
Thanks!
I would like to save it to an ini file and reload it from there when the program starts. This way, you don’t need a new program for the different sensors. How can I do this?
You have to do this manually in your source code. I don’t have anything related to save/load tag parameters. You can also create tags at runtime
Hi Fabio,
How to get status Error when slave device off (this case in multidrop/multislave). Because Application stuck/error when one off device OFF.
Ola Fabio boa noite.
tem alguma dica de como utilizar o LogFile em um Memo.
O que queria era receber os bytes de (leitura) brutos em um memo para efetuar debugs de outros equipamentos, para saber o que está chegando igualmente o LogFile porem em um memo (somente o bytes recebidos).
Boa pergunta. Nao há como na implementacao atual. Nao com uma implementacao fácil. O maneira que existe é ficar recarregando o arquivo de tempo em tempo, ou adicionar algum tipo de watcher neste arquivo e recarregar quando o arquivo for atualizado.