Professional OPC
Development Tools

logos

Getting OPC property values in Delphi

More
06 Sep 2017 14:35 #5494 by support
The example comes with the product and is in the documentation. See the DocExamples sample project for Delphi, and in it, the _easyDAClient.GetMultiplePropertyValues.Main.inc file:
// This example shows how to get value of multiple OPC properties.
//
// Note that some properties may not have a useful value initially (e.g. until the item is activated in a group), which also the
// case with Timestamp property as implemented by the demo server. This behavior is server-dependent, and normal. You can run
// IEasyDAClient.ReadMultipleItemValues.Main.vbs shortly before this example, in order to obtain better property values. Your
// code may also subscribe to the items in order to assure that they remain active.
 
class procedure GetMultiplePropertyValues.Main;
var
  Arguments: OleVariant;
  Client: TEasyDAClient;
  I: Cardinal;
  PropertyArguments1: _DAPropertyArguments;
  PropertyArguments2: _DAPropertyArguments;
  PropertyArguments3: _DAPropertyArguments;
  PropertyArguments4: _DAPropertyArguments;
  Result: _ValueResult;
  Results: OleVariant;
begin
  PropertyArguments1 := CoDAPropertyArguments.Create;
  PropertyArguments1.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
  PropertyArguments1.NodeDescriptor.ItemID := 'Simulation.Random';
  PropertyArguments1.PropertyDescriptor.PropertyId.NumericalValue := DAPropertyIds_Timestamp;
 
  PropertyArguments2 := CoDAPropertyArguments.Create;
  PropertyArguments2.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
  PropertyArguments2.NodeDescriptor.ItemID := 'Simulation.Random';
  PropertyArguments2.PropertyDescriptor.PropertyId.NumericalValue := DAPropertyIds_AccessRights;
 
  PropertyArguments3 := CoDAPropertyArguments.Create;
  PropertyArguments3.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
  PropertyArguments3.NodeDescriptor.ItemID := 'Trends.Ramp (1 min)';
  PropertyArguments3.PropertyDescriptor.PropertyId.NumericalValue := DAPropertyIds_Timestamp;
 
  PropertyArguments4 := CoDAPropertyArguments.Create;
  PropertyArguments4.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2';
  PropertyArguments4.NodeDescriptor.ItemID := 'Trends.Ramp (1 min)';
  PropertyArguments4.PropertyDescriptor.PropertyId.NumericalValue := DAPropertyIds_AccessRights;
 
  Arguments := VarArrayCreate([0, 3], varVariant);
  Arguments[0] := PropertyArguments1;
  Arguments[1] := PropertyArguments2;
  Arguments[2] := PropertyArguments3;
  Arguments[3] := PropertyArguments4;
 
  // Instantiate the client object
  Client := TEasyDAClient.Create(nil);
 
  TVarData(Results).VType := varArray or varVariant;
  TVarData(Results).VArray := PVarArray(
    Client.GetMultiplePropertyValues(PSafeArray(TVarData(Arguments).VArray)));
 
  // Display results
  for I := VarArrayLowBound(Results, 1) to VarArrayHighBound(Results, 1) do
  begin
      Result := IInterface(Results[I]) as _ValueResult;
      WriteLn('results(', i, ').Value: ', Result.Value);
  end;
end;

Regards

Please Log in or Create an account to join the conversation.

More
06 Sep 2017 13:56 #5493 by alr1976
Hi!

It possible to have a Delphi demo to read properties in opc da?
I have read Vb example but it use old opc library and now I have ServerDescription and node scriptor.

Br,Alessandro

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.208 seconds

      

 Recommend this on Google