Modbus Components

Hi All,

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,

  1. Control the Ethernet TCP connection
  2. Read Modbus data from the PLC
  3. 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

Thanks in advance
Grant
Roslyn, NSW

I haven’t used any of these, but have you looked 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

I think Half Duplex is as simple as

FConnection:=TIdTCPClient.Create()
FConnection.Connect(const AHost: string; const APort: TIdPort);
FConnection.IoHandlerWriteDirect(const ABuffer: TIdBytes; const ALength: Integer = -1;
const AOffset: Integer = 0))
FConnection.Socket.ReadBytes(var VBuffer: TIdBytes; AByteCount: Integer; AAppend: Boolean)

Indy offers functions to get from IDBytes to strings or ansistrings

Also works in Lazarus

I am ready to help and will look for my original play apps tomorrow or example in Delphi.
Cheers Roger

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:

  1. Connect to Server ( Connect; )
  2. Read welcome message from theserver.
  3. For each line the user entered in the TMemo:
  4. Send request to server (WriteLn('ZipCode ’ + memoInput.Lines[i]):wink:
  5. Read response from server (s := ReadLn;)
  6. Send Quit command ( WriteLn(‘Quit’); )
  7. Disconnect (Disconnect;)