Reputation: 448
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.
Upvotes: 4
Views: 8398
Reputation: 16867
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
Upvotes: 2
Reputation: 226
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:
Upvotes: 8
Reputation: 2139
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...)
Upvotes: 3