3

I am developing a OPC UA Client Application which reads a file stored on a OPC UA Server. For testing Purpose i need a OPC UA Server simulator where i can add nodes of FileType and configure those nodes.

Currently i am using Prosys OPC UA Server Simulator where i can add a node of variable type but not of file type.

enter image description here

Harshith R
  • 418
  • 1
  • 11
  • 31

3 Answers3

8

Just to be sure when it comes to a node that has a "HasTypeDefinition" reference to "FileType", it is an "Object" node (Object of type FileType) and not a "Variable" node.

I have seen reusable items in node-opcua stack and UA-.NETStandard stack to achieve what you are trying to do. If you can spend about a day with UA-.NETStandard stack, you might be able to accomplish what you are trying to do. ReferenceServer application in the UA-.NETStandard stack can be a good starting point.

You will have to instantiate an "Object" node of type "FileType" in the ReferenceNodeManager.cs file inside CreateAddressSpace() function definition. In a similar usecase, I have successfully instantiated an "Object" node under the Objects Folder with "HasTypeDefinition" reference to "FileType" and have used the same for File Transfer operations.

Hope this answers your question. Thank you.

If you are looking for any other hands-on information, you can check out these resources:

Asish Ganesh
  • 216
  • 1
  • 9
  • thanks a lot for the information! It really helped me :-) I also found a demo server from Unified automation which has features i am looking for. http://documentation.unified-automation.com/uasdkdotnet/2.5.5/html/L2ServerTutDemoServer.html – Harshith R Aug 11 '20 at 12:45
3

You should try with the new version 5 of Prosys OPC UA Simulation Server. It enables you to add objects of any type - although it doesn't let you configure any files behind the FileType.

For that, you could just try the Prosys OPC UA SDK for Java. The free evaluation version comes with a sample server that can serve files as well. (And yes, I work for Prosys OPC...)

Jouni Aro
  • 2,099
  • 14
  • 30
  • Thanks for the information! I am particularly looking for a .NET OPC UA SDK, so that i can modify the sample server code any way i want to fit my requirements. Can i find something like that with Prosys? – Harshith R Aug 11 '20 at 12:56
  • 1
    We don't provide our own SDK for .NET, but use the Unified Automation SDK, which you seem to have found already. – Jouni Aro Aug 12 '20 at 13:07
2

If you need a fully functional OPCUA server that exposes a File Node from which you can actually read and write, you can achieve this easily using node-opcua and the following script:

import {
    OPCUAServer,
    UAFileType,
    StatusCodes,
    Variant,
    CallMethodResultOptions,
    SessionContext,
} from "node-opcua";
import { installFileType, getFileData } from "node-opcua-file-transfer";
import { callbackify } from "util";
import * as fs from "fs";

const my_data_filename = "/tmp/someFile.txt";
fs.writeFileSync(my_data_filename, "some content", "utf8");

(async () => {
    try {
        const server = new OPCUAServer({
            port: 26540,
        });

        await server.initialize();

        // now add a file object in the address Space
        const addressSpace = server.engine.addressSpace;
        const namespace = addressSpace.getOwnNamespace();

        // retrieve the FileType UAObjectType
        const fileType = addressSpace.findObjectType("FileType")!;

        // create a instance of FileType
        const opcuaFile = fileType.instantiate({
            nodeId: "s=MyFile",
            browseName: "MyFile",
            organizedBy: addressSpace.rootFolder.objects,
        }) as UAFileType;

        // now bind the opcuaFile object with our file
        installFileType(opcuaFile, {
            filename: my_data_filename,
        });

        await server.start();
        console.log("Server is now listening on port 26540.. ( press CTRL+C to stop)");
       
    } catch (err) {
        console.log("err", err);
    }
})();

More examples can be found in https://leanpub.com/node-opcuabyexample

Etienne
  • 16,249
  • 3
  • 26
  • 31
  • I have just started checking out Etienne's [`node-opcua`](https://github.com/node-opcua/node-opcua), and it is excellent. If you're not familiar with Node.js / comfortable setting it up, someone from the community (maybe me :D) might help you set up a Dockerfile or something to play it with more easily. – jacobq Apr 07 '23 at 19:56