main.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import {
  2. OPCUAServer,
  3. Variant,
  4. DataType,
  5. StatusCodes,
  6. standardUnits
  7. } from "node-opcua";
  8. import { nodesets, constructNodesetFilename } from "node-opcua-nodesets";
  9. import { generateAddressSpace } from "node-opcua-address-space/nodeJS.js";
  10. import { AddressSpace, RootFolder, UAAnalogItem, UAObject, UAObjectType } from "node-opcua-address-space";
  11. class Main {
  12. server: OPCUAServer;
  13. constructor() {
  14. this.init();
  15. this.start()
  16. }
  17. async init() {
  18. this.server = new OPCUAServer({
  19. port: 4334, // the port of the listening socket of the server
  20. resourcePath: "/UA/nfrontend", // this path will be added to the endpoint resource name
  21. buildInfo: {
  22. productName: "NFrontend",
  23. buildNumber: "1337",
  24. buildDate: new Date(2021, 3, 16)
  25. },
  26. nodeset_filename: [
  27. nodesets.standard,
  28. "nodeset/Opc.Ua.MachineTool.Nodeset2.xml",
  29. "nodeset/Opc.Ua.Machinery.NodeSet2.xml",
  30. "nodeset/Opc.Ua.Di.NodeSet2.xml",
  31. "nodeset/Opc.Ua.Ia.NodeSet2.xml",
  32. "nodeset/emco_umati.xml",
  33. ]
  34. });
  35. await this.server.initialize();
  36. }
  37. async start() {
  38. console.log("initialized");
  39. this.server.start(() => {
  40. console.log("Server is now listening ... ( press CTRL+C to s top)");
  41. console.log("port ", this.server.endpoints[0].port);
  42. const endpointUrl = this.server.endpoints[0].endpointDescriptions()[0].endpointUrl;
  43. console.log(" the primary server endpoint url is ", endpointUrl);
  44. });
  45. }
  46. }
  47. let main = new Main();