Node-OPCUA 项目教程

Node-OPCUA 项目教程

node-opcuaUnlocking the Full Potential of OPC UA with Typescript and NodeJS - http://node-opcua.github.io/项目地址:https://gitcode.com/gh_mirrors/no/node-opcua

1. 项目的目录结构及介绍

Node-OPCUA 项目的目录结构如下:

node-opcua/
├── code_gen/
├── docker/
├── documentation/
├── modeling/
├── packages/
├── packages_extra/
├── packets/
├── test/
├── .codeclimate.yml
├── .eslintignore
├── .eslintrc.js
├── .gitattributes
├── .gitignore
├── .gitlab-ci.yml
├── .ignore
├── .jshintrc
├── .mocharc.js
├── .mocharc.yml
├── .npmignore
├── .nycrc.yaml
├── LICENSE
├── README.md
├── updateReleaseNotes.js
├── webpack.config.js
├── webpack.dll.config.js
└── yuidoc.json

目录介绍

  • code_gen/: 代码生成相关文件。
  • docker/: Docker 容器相关文件。
  • documentation/: 项目文档。
  • modeling/: 模型相关文件。
  • packages/: 核心包文件。
  • packages_extra/: 额外包文件。
  • packets/: 数据包相关文件。
  • test/: 测试文件。
  • .codeclimate.yml: CodeClimate 配置文件。
  • .eslintignore: ESLint 忽略文件。
  • .eslintrc.js: ESLint 配置文件。
  • .gitattributes: Git 属性配置文件。
  • .gitignore: Git 忽略文件。
  • .gitlab-ci.yml: GitLab CI 配置文件。
  • .ignore: 忽略文件。
  • .jshintrc: JSHint 配置文件。
  • .mocharc.js: Mocha 配置文件。
  • .mocharc.yml: Mocha 配置文件。
  • .npmignore: NPM 忽略文件。
  • .nycrc.yaml: NYC 配置文件。
  • LICENSE: 项目许可证。
  • README.md: 项目说明文档。
  • updateReleaseNotes.js: 更新发布说明脚本。
  • webpack.config.js: Webpack 配置文件。
  • webpack.dll.config.js: Webpack DLL 配置文件。
  • yuidoc.json: YUIDoc 配置文件。

2. 项目的启动文件介绍

Node-OPCUA 项目的启动文件通常位于 packages/node-opcua-samples/bin/ 目录下。以下是一个示例启动文件 simple_server.js 的介绍:

const { OPCUAServer } = require("node-opcua");

async function main() {
    const server = new OPCUAServer({
        port: 4840, // 默认端口
        resourcePath: "/UA/MyLittleServer",
        buildInfo: {
            productName: "MySampleServer",
            buildNumber: "1",
            buildDate: new Date(2024, 1, 1)
        }
    });

    await server.initialize();
    await server.start();

    console.log("Server is now listening ... ( press CTRL+C to stop)");
    console.log("port ", server.endpoints[0].port);
    console.log("endpointUrl", server.endpoints[0].endpointDescriptions()[0].endpointUrl);

    process.once("SIGINT", async () => {
        await server.shutdown();
        console.log("Server has been shut down");
        process.exit(0);
    });
}

main();

启动文件介绍

  • OPCUAServer: 创建一个 OPC UA 服务器实例。
  • server.initialize(): 初始化服务器。
  • server.start(): 启动服务器。
  • process.once("SIGINT", ...): 捕获 CTRL+C 信号,优雅地关闭服务器。

3. 项目的配置文件介绍

Node-OPCUA 项目的配置文件主要包括以下几个:

webpack.config.js

Webpack 配置文件,用于打包项目。

const path = require("path");

module.exports = {
    entry: "./src/index.js",
    output: {
        filename: "bundle.js",
        path: path.resolve(__

node-opcuaUnlocking the Full Potential of OPC UA with Typescript and NodeJS - http://node-opcua.github.io/项目地址:https://gitcode.com/gh_mirrors/no/node-opcua

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

戚逸玫Silas

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值