Professional OPC
Development Tools


Need to force Sycrounous device read and writes to device, using Powerbulder

10 Dec 2019 15:54 #8080 by spaxman
Yes I was getting data from cache and not from the device. Thank you for your quick and thorough answer.

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

10 Dec 2019 09:07 - 10 Dec 2019 09:08 #8079 by support
regarding the sync read: I think you are doing it right; but you are not doing the right thing.

Let me explain:
Asynchronous operations in OPC are used to allow the caller perform other operations while the OPC server works on the call. They only affect the communication between the OPC client and OPC server. Unless there is a bug somewhere, the data (value/timestamp/quality) you get through sync read vs. async read is obtained by the OPC server in the same way, at the same time, and you get the same data.

What you are probably looking for is to force the server to actually do a read from the device, and not send you any cached data. Here is an example of how that can be done in VBScript; I think that translating to PowerBuilder will not be a problem.

Rem This example shows how to read 4 items from the device, and display their values, timestamps and qualities.
Option Explicit
' Selects the data source for OPC reads (from device, from OPC cache, or dynamically determined).
' The data source (memory, OPC cache or OPC device) selection will be based on the desired value age and current status of 
' data received from the server.
Const DADataSource_ByValueAge = 0
' OPC reads will be fulfilled from the cache in the OPC server.
Const DADataSource_Cache = 1
' OPC reads will be fulfilled from the device by the OPC server.
Const DADataSource_Device = 2
Dim ReadItemArguments1: Set ReadItemArguments1 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
ReadItemArguments1.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ReadItemArguments1.ItemDescriptor.ItemID = "Simulation.Random"
ReadItemArguments1.ReadParameters.DataSource = DADataSource_Device  ' read will be from device
Dim ReadItemArguments2: Set ReadItemArguments2 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
ReadItemArguments2.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ReadItemArguments2.ItemDescriptor.ItemID = "Trends.Ramp (1 min)"
ReadItemArguments2.ReadParameters.DataSource = DADataSource_Device  ' read will be from device
Dim ReadItemArguments3: Set ReadItemArguments3 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
ReadItemArguments3.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ReadItemArguments3.ItemDescriptor.ItemID = "Trends.Sine (1 min)"
ReadItemArguments3.ReadParameters.DataSource = DADataSource_Device  ' read will be from device
Dim ReadItemArguments4: Set ReadItemArguments4 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAReadItemArguments")
ReadItemArguments4.ServerDescriptor.ServerClass = "OPCLabs.KitServer.2"
ReadItemArguments4.ItemDescriptor.ItemID = "Simulation.Register_I4"
ReadItemArguments4.ReadParameters.DataSource = DADataSource_Device  ' read will be from device
Dim arguments(3)
Set arguments(0) = ReadItemArguments1
Set arguments(1) = ReadItemArguments2
Set arguments(2) = ReadItemArguments3
Set arguments(3) = ReadItemArguments4
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
Dim results: results = Client.ReadMultipleItems(arguments)
Dim i: For i = LBound(results) To UBound(results)
    Dim VtqResult: Set VtqResult = results(i)
    If VtqResult.Succeeded Then
        WScript.Echo "results(" & i & ").Vtq.ToString(): " & VtqResult.Vtq.ToString()
        WScript.Echo "results(" & i & ") *** Failure: " & VtqResult.ErrorMessageBrief
    End If
Best regards
Last edit: 10 Dec 2019 09:08 by support.
The following user(s) said Thank You: spaxman

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

09 Dec 2019 20:19 #8078 by spaxman
I have created a client using PowerBuilder and can read and write tags.

The way my client works is as follows.
1. read one tag and this tags tells the client what type of message the device is sending. Bascially tells me which tags I now need to get data from.
2. We then read the needed tags we want from the device. We must do this synchronously, to the device to get the list of accurate tags that are populated from the device.

I set up my client using

g_opclabs.InstanceParameters.Mode.AllowAsynchronousMethod = false // only do sync reds
g_opclabs.InstanceParameters.Mode.AllowSynchronousMethod= true
g_opclabs.InstanceParameters.Mode.DesiredMethod = 0

But it seems not to be reading all the tags from the device(plc). I am getting some data from the previous message which means it sending data back from the server and not going to the device to get the latest data from the tags.

How can I force syncronous reads and writes to the device(plc)?

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

Moderators: support
Time to create page: 0.186 seconds


 Recommend this on Google