How to create a File object in OPC UA server in C#?

52 Views Asked by At

I'm trying to create a File object so that the client can send a file through the server, but when I try to write a local file to the object it returns a BadImplementation error.

Also, some attributes of the File object appear as invalid and take on the value BadAttributeIdInvalid and I don't know why.

I create a FileState node in the Files folder, as you can see below. And the node appears on the client side as expected. But it doesn't work as mentioned before.

folder = opcServer_.CreateFolderState(root, "Files", "Files", "String");

FileState file = new(folder)
{
    SymbolicName = "FileName",
    Description = "File object",
    ReferenceTypeId = ReferenceTypes.Organizes,
    TypeDefinitionId = ObjectTypeIds.FileType,
    NodeId = ObjectIds.FileDirectoryType_FileName_Placeholder,
    BrowseName = new QualifiedName("FileName", NamespaceIndex),
    DisplayName = "FileName",
    RolePermissions = new(),
    UserRolePermissions = new(),
};

folder.AddChild(file);
opcServer_.AddNode(folder);

Does anyone know what else I need to implement to make this object work as expected?

1

There are 1 best solutions below

2
ZbynekZ On

In OPC UA, file objects are created - if the server supports it (which is not always the case) - through the CreateFile method that you need to call. See https://reference.opcfoundation.org/v104/Core/docs/Part5/C.3.4 .