I’m looking to read/write data to/from a Allen Bradley Micro850 PLC via Ethernet TCP
The PC end will act as a Modbus Server and the PLC a Modbus Client
Can anyone please suggest some components that can,
Control the Ethernet TCP connection
Read Modbus data from the PLC
Send Modbus data to the PLC
In the first instance I will create a visual Delphi application to make it easier to fault find etc but at some stage I need the above to be working as a background service.
Can any one suggest some components to do the above Modbus stuff
Does anyone have any example code that I can look at
Hi Grant
I am not familiar with Mobus but it seems to support TCP/IP
I use Indy extensively to interact with TCP ports. I do not use their visual components because as you flagged I want my stuff to run in the background on any thread so I use the TIdTCPClient directly.
I assume your application is “Half Duplex” That is you send some data and the Mobus returns an answer.
My implementation Builds on Indy Objects and I do not have a simple code examples but looking at what I use
Are yes the problem with Indy is getting the documentation
But thanks to ADUG I and others have copies
Indy 10 comes with Delphi
A Client sample App from that documentation
Introduction to Indy
unit ClientMain;
interface
uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls,
IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient;
type
TformMain = class(TForm)
Client: TIdTCPClient;
IdAntiFreeze1: TIdAntiFreeze;
Panel1: TPanel;
Panel2: TPanel;
memoInput: TMemo;
lboxResults: TListBox;
Panel3: TPanel;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
public
end;
var
formMain: TformMain;
implementation
{ R *.DFM }
procedure TformMain.Button2Click(Sender: TObject);
begin
memoInput.Clear;
lboxResults.Clear;
end;
procedure TformMain.Button1Click(Sender: TObject);
var
i: integer;
s: string;
begin
butnLookup.Enabled := true;
try
lboxResults.Clear;
with Client do
begin
Connect;
try
lboxResults.Items.Add(ReadLn);
for i := 0 to memoInput.Lines.Count - 1 do
begin
WriteLn('ZipCode ' + memoInput.Lines[i]);
lboxResults.Items.Add(memoInput.Lines[i]);
s := ReadLn;
if s = '' then
begin
s := '-- No entry found for this zip code.';
end;
lboxResults.Items.Add(s);
lboxResults.Items.Add('');
end;
WriteLn('Quit');
finally
Disconnect;
end;
end;
finally
butnLookup.Enabled := true;
end;
end;
end.
The only parts that are Indy specific are the Client component and the Button1Click method.
Client is a TIdTCPClient and is a component on the form. The following properties were altered from the default:
• Host = 127.0.0.1 - Host was set to contact a server on the same machine as the client.
• Port = 6000 - An arbitrary number for this demo. This is the port that the client will contact the server with.
Button1Click is a method that is hooked to the OnClick event of Button1. When the button is clicked it executes this method.
The Indy portion of this method can be reduced to the following:
Connect to Server ( Connect; )
Read welcome message from theserver.
For each line the user entered in the TMemo:
Send request to server (WriteLn('ZipCode ’ + memoInput.Lines[i])