0
votes

I'm messing around with the OPC Foundations .NET library looking at building an OPC Client. The Client is communicating with a Kepware OPC Server (KEPServerExV5). The tags that my OPC Client is reading use the in built Modbus TCP/IP driver that is part of the OPC Server. The problem I'm having is that I'm not able to do a cache read of any of the OPC tags on the OPC Server, every tag value the OPC Client requests results in the OPC Server performing a device read. I need to do a cache read because in this instance I need to quickly read the data rather than wait until the most recent data is retrieved.

My current understanding is that the MaxAge property is what is used to determine if a device read or a cache read should be performed based on how stale the data in the cache is. Below is the code I'm currently using to perform a cache read.

Server = new Server(new Factory(), new URL("MyOpcServerConnectionString"));

Server.Connect();

var readValue = new Item[1];

readValue[0] = new Item
{
    ItemName = "Channel1.Device1.Tag1",
    // set max age high so the OPC servers always reads from the cache not the device
    MaxAge = int.MaxValue,
    // we specify that the max age property is in effect
    MaxAgeSpecified = true
};

ItemValueResult[] result = null;

result = Server.Read(readValue);

With the above code the Server.Read() method causes the OPC Server to perform a device read even though I have set the MaxAge property to roughly 60 years such that it should never read from anything if there is a cached value. I don't see why it does this. Using a subscription approach to reading also results in the same problem, the MaxAge property still gets ignored.

So my question really boils down to: what am I missing with regards to forcing a cache read?

Edit:

Well I found a way to do a cache read though it is not exactly what I wanted. If I create a subscription and perform a device read then any subsequent reads done before device read timestamp + MaxAge property will be cache reads. This does mean that for my purposes everything has to be done in terms of subscriptions. Ideally I wanted to be able to perform once off reads that would access the cache instead of setting up a number of subscriptions which I then have to manage or explicitly destroy.

If someone comes across a way to do a device read outside of the subscription method I'd love to hear it. But for now I think what I've found will have to suffice in terms of my understanding of how the cache reads work. I'm going to leave the question unanswered as it is because I'm not convinced what I want to do cannot be done using the OPC Foundation .Net library.

1

1 Answers

1
votes

You should use Server from OpcCom.Da20, there is a method called

ReadValues(Item[] items, ItemValueResult[] results, bool cache)