Closed rmnbs closed 1 year ago
Ok, so I found out why it didn't work. So i'm letting this here for people with the same problem,
do not do
[BinaryEncodingId("ns=4;s=<StructuredDataType>:Status__DefaultBinary")]
do
[BinaryEncodingId("nsu=urn:BeckhoffAutomation:Ua:PLC1;s=<StructuredDataType>:Status__DefaultBinary")]
Thank you for your error solving.
Just one question, why did you put "nsu=urn:BeckhoffAutomation:Ua:PLC1" in the NodeId?
Is it because you defined the namespace this way?
encoder.PushNamespace("urn:BeckhoffAutomation:Ua:PLC1");
//...
decoder.PushNamespace("urn:BeckhoffAutomation:Ua:PLC1");
So I ask myself... if one uses this in the Encode (and similar in Decode):
encoder.PushNamespace("my:namespace");
then it should be (?): nsu=my:namespace
Is this OK or are there some rules to follow when defining namespaces? Maybe the PLC vendor has some other rules? (in this case, how did you found that full namespace of your structure?)
Thank you very much
I can try to answer this question but do not give my words too much credit, i'm fairly new to opcUA and still discovering its particularities.
So,
the only way I was able to make it work with Beckhoff's own opc UA server and my associated Twincat Project was to put nsu=urn:BeckhoffAutomation:Ua:PLC1
in the
[BinaryEncodingId]
declaration
and
use
encoder.PushNamespace("urn:BeckhoffAutomation:Ua:PLC1");
//...
decoder.PushNamespace("urn:BeckhoffAutomation:Ua:PLC1");
in the Encode/Decode
I guess if your BinaryEncodingIds are in "my:namespace" then that's what you should use in your code because when I explore the server BeckhoffAutomation:Ua:PLC1 is "where" this data is declared.
I am afraid this may be dependent of your opc ua server provider, for example last time I checked B&R's opc ua server did not support custom structure types.
I also found this repo https://github.com/RoddenLab/HMI-Demo in the list of project dependent of opc-ua-client. you'll find a duplicate of this issue in his.
I originally used the OPC ua browser VS extension provided by the creator of this library. With it you can auto generate MonitoringItem and DataTypes by dragging them from the browser to the code file.
the generated code for my DataType was
[DataTypeId("ns=4;s=<StructuredDataType>:Status")]
[BinaryEncodingId("ns=4;s=<StructuredDataType>:Status__DefaultBinary")]
public class Status : Structure
{
// Properties Omitted for brevity
public override void Encode(IEncoder encoder)
{
base.Encode(encoder);
encoder.PushNamespace("urn:BeckhoffAutomation:Ua:PLC1");
encoder.PopNamespace();
}
public override void Decode(IDecoder decoder)
{
base.Decode(decoder);
decoder.PushNamespace("urn:BeckhoffAutomation:Ua:PLC1");
decoder.PopNamespace();
}
}
which is incorrect in my case (It may be a Beckhoff quirk).
Once changed to :
[DataTypeId("ns=4;s=<StructuredDataType>:Status")]
[BinaryEncodingId("nsu=urn:BeckhoffAutomation:Ua:PLC1;s=<StructuredDataType>:Status__DefaultBinary")]
public class Status : Structure
{
// Properties Omitted for brevity
public override void Encode(IEncoder encoder)
{
base.Encode(encoder);
encoder.PushNamespace("urn:BeckhoffAutomation:Ua:PLC1");
encoder.PopNamespace();
}
public override void Decode(IDecoder decoder)
{
base.Decode(decoder);
decoder.PushNamespace("urn:BeckhoffAutomation:Ua:PLC1");
decoder.PopNamespace();
}
}
Then once completed with the Structure's members and filled out Decode/Encode I can read/write my data.
Thank you very much for your explanation. It helps me a lot.
Hi,
I'm trying to create an MVVM application for a beckhoff automation project.
I'm trying to read my Status structure.
I am unable read my struct with the MonitoredItem / Structure pattern.
To find out why I created a small Terminal app trying to read just that structure.
What I get is that
BodyType
is of type ByteString. for GetValueOrDefault to function properly I would need an Encodable.I don't understand why i'm reading the data as a ByteString. For context I have tried multiple ways to configure the structure. directly on the structure itself
or on the variable
without success. I feel like it's a configuration issue somewhere on the client or server but I can't find it. If you have any idea about what is it I am doing wrong I'll gladly accept it. Thanks.