2

I am using lazarus and the nodave component, and I want to read the status of a digital input e.g. I45.6 I am connecting via ethernet and as far as I can tell I have a connection the CPU is in slot 3 and the comms card is slot 5.

To do this I am trying to use the GetBit function.

begin
IF
  nodave1.GetBit(45,6)
then
  showmessage('got it')
else
  showmessage('not got it')
end;

but no matter what I do I can't get a response. I'm not sure if it is the component properties or something else.

here is the full code, the component is set up Area=daveinputs and protocol = protoISOTCP

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Spin,
  StdCtrls, NoDaveComponent;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    NoDave1: TNoDave;
    SpinEdit1: TSpinEdit;
    SpinEdit2: TSpinEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure NoDave1Connect(Sender: TObject);
    procedure NoDave1Disconnect(Sender: TObject);
    procedure NoDave1Read(Sender: TObject);
    procedure SpinEdit1Change(Sender: TObject);
    procedure SpinEdit2Change(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
  nodave1.CPURack:=spinedit1.Value;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  nodave1.Active:=true;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  nodave1.Disconnect;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
if
nodave1.GetBit(46,5,nil,0,0)
then
showmessage('got it')
else
showmessage('dont got it')
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
  nodave1.IPAddress:=edit1.text;
end;

procedure TForm1.NoDave1Connect(Sender: TObject);
begin
form1.Caption:='connected'

end;

procedure TForm1.NoDave1Disconnect(Sender: TObject);
begin
  form1.caption:='disconnected';
end;

procedure TForm1.NoDave1Read(Sender: TObject);
begin

end;

procedure TForm1.SpinEdit2Change(Sender: TObject);
begin
  nodave1.CPUSlot:=spinedit2.Value;
end;

end.

1 Answers1

0

It's been 8 years since I have touched libNoDave in C and Delphi, but my guess is that you are interpreting slot numbers for CPU and ethernet card wrong. I have looked at my 20+ PLCs libnodave connection parameters and they all have CPU in slot 0 and ethernet card in slots 2, 3 or 5. That is a big difference compared to your settings. Do you count power supply to occupy 2 slots? You shouldn't. There is a TNoDave Test Utility in \DelphiComponent\Demo\Lazarus directory that you can compile. Run that executable to first establish a successful connection to your PLC and get some good live readings. Reading bits is not implemented in that utility, but you can read the whole byte from I45. Once you have established a connection, copying connection parameters from this utility to your code and reading bits with it should be trivial.

avra
  • 3,690
  • 19
  • 19