本文整理匯總了TypeScript中node-opcua.OPCUAServer.start方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript OPCUAServer.start方法的具體用法?TypeScript OPCUAServer.start怎麽用?TypeScript OPCUAServer.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類node-opcua.OPCUAServer
的用法示例。
在下文中一共展示了OPCUAServer.start方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: main
async function main() {
try {
const server = new OPCUAServer({
nodeset_filename: [
nodesets.standard_nodeset_file
]
});
await server.initialize();
// post-initialize
const addressSpace = server.engine.addressSpace!;
const object = installObjectWithMethod(addressSpace);
console.log("object = ", object.toString());
await callMethodFromServer(addressSpace, object.nodeId);
await server.start();
console.log(" Server started ", server.endpoints[0].endpointDescriptions()[0].endpointUrl);
} catch (err) {
console.log(" Error: ", err.message);
console.log(err.stack);
}
}
示例2: before
before(done => {
port += 1;
const options = { port };
server = new OPCUAServer(options);
server.on("post_initialize", () => {
const addressSpace = server.engine.addressSpace!;
const group = addressSpace.getOwnNamespace().addObject({
browseName: "Group",
organizedBy: addressSpace.rootFolder.objects
});
for (let i = 0; i < 27; i++) {
addressSpace.getOwnNamespace().addObject({
browseName: "Object" + i,
organizedBy: group
});
}
groupNodeId = group.nodeId;
});
server.start((err?: Error) => {
if (err) {
return done(err);
}
endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl;
if (err) {
return done(err);
}
done();
});
});
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:33,代碼來源:test_e2e_#519_Nodecrawler_is_not_browsing_some_nodes.ts
示例3: startServer
// openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout example.pem \
// -outform der -out example.der -subj "/CN=example.com" -days 3650
async function startServer(): Promise<OPCUAServer> {
server = new OPCUAServer({
maxAllowedSessionNumber: 10,
nodeset_filename: empty_nodeset_filename,
port,
});
await server.start();
endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl!;
return server;
}
示例4: main
async function main() {
const server = new OPCUAServer(server_options);
server.on("post_initialize", () => {
/* empty */
});
console.log(chalk.yellow(" server PID :"), process.pid);
console.log(chalk.yellow(" silent :"), argv.silent);
await server.start();
const endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl!;
console.log(chalk.yellow(" server on port :"), chalk.cyan(server.endpoints[0].port.toString()));
console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
if (argv.silent) {
console.log("silent");
console.log = (...args: [any?, ... any[]]) => {
/* silent */
};
}
server.on("create_session", (session: ServerSession) => {
console.log(" SESSION CREATED");
console.log(chalk.cyan(" client application URI: "), session.clientDescription!.applicationUri);
console.log(chalk.cyan(" client product URI: "), session.clientDescription!.productUri);
console.log(chalk.cyan(" client application name: "), session.clientDescription!.applicationName.toString());
console.log(chalk.cyan(" client application type: "), session.clientDescription!.applicationType.toString());
console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
console.log(chalk.cyan(" session timeout: "), session.sessionTimeout);
console.log(chalk.cyan(" session id: "), session.nodeId);
});
server.on("session_closed", (session: ServerSession, reason: string) => {
console.log(" SESSION CLOSED :", reason);
console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
});
process.on("SIGINT", async () => {
// only work on linux apparently
console.error(chalk.red.bold(" Received server interruption from user "));
console.error(chalk.red.bold(" shutting down ..."));
await server.shutdown(1000);
console.error(chalk.red.bold(" shot down ..."));
process.exit(1);
});
}
示例5: main
async function main() {
const server = new OPCUAServer(server_options);
console.log(chalk.yellow(" server PID :"), process.pid);
server.on("post_initialize", () => {
const addressSpace = server.engine.addressSpace!;
// to do: expose new nodeid here
const ns = addressSpace.getNamespaceIndex("http://yourorganisation.org/my_data_type/");
const myStructureType = addressSpace.findVariableType("MyStructureType", ns);
if (!myStructureType) {
console.log(" ns = ", ns, "cannot find MyStructureDataType ");
return;
}
const namespace = addressSpace.getOwnNamespace();
const someObject = namespace.addObject({
browseName: "SomeObject",
organizedBy: addressSpace.rootFolder.objects
});
myStructureType.instantiate({
browseName: "MyVar",
componentOf: someObject
});
});
try {
await server.start();
} catch (err) {
console.log(" Server failed to start ... exiting");
process.exit(-3);
}
const endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl!;
console.log(chalk.yellow(" server on port :"), chalk.cyan(server.endpoints[0].port.toString()));
console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
process.on("SIGINT", async () => {
// only work on linux apparently
await server.shutdown(1000);
console.log(chalk.red.bold(" shutting down completed "));
process.exit(-1);
});
}
示例6: main
async function main() {
const tmpFolder = path.join(__dirname, "../certificates/myApp");
const applicationGroup = new CertificateManager({
location: tmpFolder
});
await applicationGroup.initialize();
const server = new OPCUAServer(server_options);
console.log(" Configuration rootdir = ", server.serverCertificateManager.rootDir);
console.log(chalk.yellow(" server PID :"), process.pid);
server.on("post_initialize", () => {
const addressSpace = server.engine.addressSpace!;
// to do: expose new nodeid here
const ns = addressSpace.getNamespaceIndex("http://yourorganisation.org/my_data_type/");
installPushCertificateManagement(addressSpace, {
applicationGroup: server.serverCertificateManager,
userTokenGroup: server.userCertificateManager
});
console.log("Certificate rejected folder ", server.serverCertificateManager.rejectedFolder);
});
try {
await server.start();
} catch (err) {
console.log(" Server failed to start ... exiting");
process.exit(-3);
}
const endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl!;
console.log(chalk.yellow(" server on port :"), chalk.cyan(server.endpoints[0].port.toString()));
console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
process.on("SIGINT", async () => {
// only work on linux apparently
await server.shutdown(1000);
console.log(chalk.red.bold(" shutting down completed "));
process.exit(-1);
});
}
示例7: startMultiHeadServer
async function startMultiHeadServer() {
const server_options: OPCUAServerOptions = {
isAuditing: false,
nodeset_filename: [
nodesets.standard
],
serverInfo: {
applicationName: { text: "Mini NodeOPCUA Server", locale: "en" },
applicationUri: makeApplicationUrn("%FQDN%", "MiniNodeOPCUA-Server"),
productUri: "Mini NodeOPCUA-Server"
},
// default endpoint
allowAnonymous: false,
alternateHostname: ["MyHostname1"],
port: port1,
securityModes: [MessageSecurityMode.None],
securityPolicies: [SecurityPolicy.None],
// alternate endpoint
alternateEndpoints: [
{
allowAnonymous: false,
alternateHostname: ["1.2.3.4"],
port: port2,
securityModes: [MessageSecurityMode.SignAndEncrypt],
securityPolicies: [SecurityPolicy.Basic256Sha256]
}
]
};
server = new OPCUAServer(server_options);
server.on("post_initialize", () => {/**/
});
console.log(chalk.yellow(" server PID :"), process.pid);
try {
await server.start();
} catch (err) {
console.log(" Server failed to start ... exiting => err:", err.message);
return;
}
}
示例8: startServer
async function startServer() {
const server_options: OPCUAServerOptions = {
port: port1,
nodeset_filename: [
nodesets.standard
],
serverInfo: {
applicationUri: makeApplicationUrn("%FQDN%", "MiniNodeOPCUA-Server"),
productUri: "Mini NodeOPCUA-Server",
applicationName: { text: "Mini NodeOPCUA Server", locale: "en" }
},
alternateHostname: ["MyHostname1", "MyHostname2"],
isAuditing: false
};
server = new OPCUAServer(server_options);
server.on("post_initialize", () => {/**/
});
console.log(chalk.yellow(" server PID :"), process.pid);
try {
await server.start();
} catch (err) {
console.log(" Server failed to start ... exiting => err:", err.message);
return;
}
for (const endpoint of server.endpoints) {
const endpointUrl = endpoint.endpointDescriptions()[0].endpointUrl!;
console.log(chalk.yellow(" server on port1 :"), endpoint.port.toString());
console.log(chalk.yellow(" endpointUrl1 :"), chalk.cyan(endpointUrl));
}
}
示例9: main
async function main() {
process.title = "Node OPCUA Server on port : " + server_options.port;
const server = new OPCUAServer(server_options);
server.on("post_initialize", () => {/**/
});
console.log(chalk.yellow(" server PID :"), process.pid);
try {
await server.start();
} catch (err) {
console.log(" Server failed to start ... exiting");
process.exit(-3);
}
const endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl!;
console.log(chalk.yellow(" server on port :"), server.endpoints[0].port.toString());
console.log(chalk.yellow(" endpointUrl :"), chalk.cyan(endpointUrl));
console.log(chalk.yellow("\n server now waiting for connections. CTRL+C to stop"));
server.on("create_session", (session: ServerSession) => {
console.log(" SESSION CREATED");
console.log(chalk.cyan(" client application URI: "), session.clientDescription!.applicationUri);
console.log(chalk.cyan(" client product URI: "), session.clientDescription!.productUri);
console.log(chalk.cyan(" client application name: "), session.clientDescription!.applicationName.toString());
console.log(chalk.cyan(" client application type: "), session.clientDescription!.applicationType.toString());
console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
console.log(chalk.cyan(" session timeout: "), session.sessionTimeout);
console.log(chalk.cyan(" session id: "), session.nodeId);
});
server.on("session_closed", (session: ServerSession, reason: string) => {
console.log(" SESSION CLOSED :", reason);
console.log(chalk.cyan(" session name: "), session.sessionName ? session.sessionName.toString() : "<null>");
});
}
示例10: main
async function main() {
try {
const server = new OPCUAServer({
registerServerMethod: RegisterServerMethod.LDS
});
await server.initialize();
server.on("request", (request: Request) => {
console.log(request.constructor.name, request.requestHeader.requestHandle);
// you can either check the instance of the request object directl
if (request instanceof BrowseRequest) {
console.log("BrowseRequest.requestedMaxReferencesPerNode=", request.requestedMaxReferencesPerNode);
} else if (request instanceof ActivateSessionRequest) {
console.log(request.toString());
}
// ... or check its schema name
switch (request.schema.name) {
case "BrowseRequest":
{
const browseRequest = request as BrowseRequest;
} break;
// etc...
}
});
server.on("response", (response: Response) => {
// you can either check the instance of the request object directl
if (response instanceof BrowseResponse) {
console.log("BrowseResponse.results.length =", response.results ? response.results.length : 0);
}
switch (response.schema.name) {
case "BrowseResponse": {
const browseRequest = response as BrowseResponse;
console.log("BrowseResponse.results.length =", browseRequest.results ? browseRequest.results.length : 0);
} break;
// etc...
}
});
// post-initialize
const addressSpace = server.engine.addressSpace!;
addressSpace.installAlarmsAndConditionsService();
const namespace = addressSpace.getOwnNamespace();
const myEventType = namespace.addEventType({
browseName: "MyEventType",
subtypeOf: "TransitionEventType"
});
const HVACModuleType = namespace.addObjectType({
browseName: "HVACModuleType"
});
namespace.addAnalogDataItem({
modellingRule: "Mandatory",
componentOf: HVACModuleType,
browseName: "TargetTemperature",
minimumSamplingInterval: 0, // could be event Based
dataType: "Double",
instrumentRange: { low: -70, high: 120 },
engineeringUnitsRange: { low: -100, high: 200 }
});
namespace.addObject({
browseName: "Test",
eventNotifier: 0,
organizedBy: addressSpace.rootFolder.objects
});
const boiler1 = makeBoiler(addressSpace, {
browseName: "Boiler1",
organizedBy: addressSpace.rootFolder.objects
});
await server.start();
console.log(" Server started ", server.endpoints[0].endpointDescriptions()[0].endpointUrl);
} catch (err) {
console.log("Error : ", err.message);
console.log(err.stack);
}
}