Home > Back-end >  Delphi how to implement opc data real-time acquisition
Delphi how to implement opc data real-time acquisition

Time:09-19

Opc connection with PLC after I would like to receive real-time data change, I now use the callback OnDataChange, can monitor the change of the data, but I can't get a new variable with the item, how to do this.

CodePudding user response:

No one, and a great god gone

CodePudding user response:

You at the time of initialization OPC connection with PLC, not corresponding to initialize variables?

CodePudding user response:

The function TOPCDataCallback. OnDataChange (dwTransid: DWORD; HGroup: OPCHANDLE;
HrMasterquality: HResult; HrMastererror: HResult; DwCount: DWORD;
PhClientItems: POPCHANDLEARRAY; PvValues: POleVariantArray;
PwQualities: PWordArray; PftTimeStamps: PFileTimeArray;
PErrors: PResultList) : HResult; Stdcall;
Var
ClientItems: POPCHANDLEARRAY;
Values: POleVariantArray;
Qualities: PWORDARRAY;
I: Integer;
NewValue: array [0.. 1] of the string;
OutputValue: array [0.. 1] of the string;
The begin
Result:=S_OK;
ClientItems:=POPCHANDLEARRAY (phClientItems);
Values:=POleVariantArray (pvValues);
Qualities:=PWORDARRAY (pwQualities);
For I:=0 to do dwCount - 1
The begin
If Qualities [I]=OPC_QUALITY_GOOD then
The begin
NewValue: [I]=VarToStr (Values [I]);
OutputValue: [I]=format (' value: % d, % s', [ClientItems [I], NewValue [I]]).
//form1. Label1. Caption:=inttostr (ClientItems [0]).
//form1. Label2. Caption:=inttostr (ClientItems [1]).
End
The else
The begin
ShowMessage (' Callback received for the item, but quality not good ');
end;
end;
end;
This is a data change triggered the callback function, the inside of the dwCount got the data changes, the number of the item so ClientItems [I] I got and I is from the actual item

CodePudding user response:

refer to the second floor hongss response:
you at the time of initialization OPC connection with PLC, not corresponding to initialize variables?

There's a connection between this and I'll have the initialization
  • Related