Thrown exceptions by calling Read method from OPC client

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
MrIS
Full Member
Full Member
Posts: 7
Joined: 19 Jul 2018, 10:30

Thrown exceptions by calling Read method from OPC client

Post by MrIS »

Hi there,

I have this code for reading value from the server.

Code: Select all

private void readDataType(NodeId node, out BuiltInType type)
        {
            type = BuiltInType.Null;
            List<ReadValueId> nodesToRead = new List<ReadValueId>();
            nodesToRead.Add(new ReadValueId()
            {
                NodeId = node,
                AttributeId = Attributes.DataType
            });
            List<DataValue> data = opcSession.Read(nodesToRead);
            type = TypeUtils.GetBuiltInType((NodeId)data[0].Value);
        }
Within run this code I have 2 troubles.
1. At the time of calling Read method, opcSession has sometimes state 'disconnected' and then it throws exception "The operation is not available because the session is in the 'Disconnected' state". I have tried to check if connection is alive, but it's not working always and it's ugly solution as well.

Code: Select all

if (opcSession.ConnectionStatus == ServerConnectionStatus.Disconnected)
{
       opcSession.Connect(PropEnpointUrl, SecuritySelection.BestAvailable);
}
2. In case of successfully server session connection the same part of code (Read method) throws exception with message '[BadOperationAbandoned]'. I have no idea may cause this exceptions :(

I will strongly appreciate any information or heplful tips. Thanks.

MrIS
Full Member
Full Member
Posts: 7
Joined: 19 Jul 2018, 10:30

Re: Thrown exceptions by calling Read method from OPC client

Post by MrIS »

Hello,

I changed arguments in Read method little bit and now it's working fine without exceptions.

Code: Select all

NodeId nodeId = new NodeId(myParam.PropVariableIdentifier, opcNameSpaceIndex);
List<ReadValueId> nodesToRead = new List<ReadValueId>();
nodesToRead.Add(new ReadValueId()
{
    NodeId = nodeId,
    AttributeId = Attributes.DataType
});
List<DataValue> data = opcSession.Read(nodesToRead);
Now, I have a problem to write a value to the server because it generates the exception The operation is not available because the session is in the 'Disconnected' state., of course connection is alive. Do you have any idea what could be wrong?

Code: Select all

List<StatusCode> results = null;
results = opcSession.Write(
    nodesToWrite,
    new RequestSettings { OperationTimeout = 10000 }
);
Content of the nodesToWrite variable is shown in the screenshot
Image

MrIS
Full Member
Full Member
Posts: 7
Joined: 19 Jul 2018, 10:30

Re: Thrown exceptions by calling Read method from OPC client

Post by MrIS »

Just for clarification, let me post an additional data which could be helpful in finding solution. When I run UA Sample Client Basic with default values and then if I click on the Write Synchronous button I get exception what you can see below.
Image

User avatar
Support Team
Hero Member
Hero Member
Posts: 3068
Joined: 18 Mar 2011, 15:09

Re: Thrown exceptions by calling Read method from OPC client

Post by Support Team »

Hello MrIS,

If you click on the Write Synchronous Button without typing a value in the Write Value fields, the client tries to call StringToNumber on an empty string, which causes your exception.

To find a solution why your write fails, you have to figure out why the client is in disconnected state. If you use a debugger and your client is on a breakpoint, it's possible that your session is timed out.

Could you please post your session settings?
Best regards
Unified Automation Support Team

Post Reply