dogulas - 19 hours ago

Ok, I have a simple test environment. From C#, using OPC UA, I can read DINTs, write DINTs, read Structs, but when I try to write a struct I get BadNotWritable.

I am using Communication Manager, OPC UA Server, and IEC Symbol Publishing. I have a struct defined with one single DINT in it. The instance of the struct is in GVL. The struct is marked read/write in IEC Symbol Publishing.

Any ideas? Pointers are welcome.

    public static async Task WriteStructA(byte[] structAData)
    {
        if (_session == null)
            throw new Exception("session is null");

        // create a RequestHeader
        RequestHeader requestHeader = new RequestHeader
        {
            Timestamp = DateTime.UtcNow,
            TimeoutHint = 30000 // timeout in milliseconds
        };

        // create an ExtensionObject to wrap the value to be written
        ExtensionObject extensionObject = new ExtensionObject(
            new ExpandedNodeId("GVL_StructA", 5),
            structAData
            );

        // create a WriteValue object to hold the value to be written
        WriteValue writeValue = new WriteValue
        {
            NodeId = _structANodeId,
            AttributeId = Attributes.Value,
            Value = new DataValue(extensionObject)
        };

        // put the WriteValue object into a WriteValueCollection object
        WriteValueCollection writeValueCollection = new WriteValueCollection() { writeValue };

        // perform the write operation asynchronously
        WriteResponse writeResponse = await _session.WriteAsync(
            requestHeader,
            writeValueCollection,
            CancellationToken.None
            );

        // check the result of the write operation
        if (writeResponse.Results[0] != StatusCodes.Good)
            throw new Exception("Write failed: " + writeResponse.Results[0]);
    }