From 4f4fbff5b323947b030930cbaf871fec31d17f55 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Fri, 30 Oct 2020 08:29:35 +0100 Subject: [PATCH] Add example script for initial connection; make it callable by "npm test" --- .gitignore | 1 + examples/example.js | 31 +++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 examples/example.js diff --git a/.gitignore b/.gitignore index e1a6cbf8..c94991a5 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,4 @@ typings/ # Visual Studio Code config folder .vscode +package-lock.json diff --git a/examples/example.js b/examples/example.js new file mode 100644 index 00000000..b1e1b40f --- /dev/null +++ b/examples/example.js @@ -0,0 +1,31 @@ +const { Session, Clsid, ComServer } = require('../dcom') + +const domain = 'WORKGROUP' +const username = 'myuser' +const password = 'mypassword' +const ipAddress = '1.2.3.4' +const timeout = 1000 +const classIdString = 'F8582CF2-88FB-11D0-B850-00C0F0104305' // Matrikon.OPC.Simulation + +const sessionSingleton = new Session() + +async function main () { + const comSession = sessionSingleton.createSession(domain, username, password) + comSession.setGlobalSocketTimeout(timeout) + const clsid = new Clsid(classIdString) + const comServer = new ComServer(clsid, ipAddress, comSession, { major: 5, minor: 7 }) + + try { + // start the COM Server + await comServer.init() + console.log(`Successfully connected to ${ipAddress}`) + + await comServer.closeStub() + } catch (err) { + console.trace(err) + } + + await comSession.destroySession(comSession) +} + +main() diff --git a/package.json b/package.json index a0a99c82..6a00fef4 100755 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Simple lib to support DCOM communication (Heavly based on J-Interop)", "main": "dcom/index.js", "scripts": { - "test": "none" + "test": "node examples/example.js" }, "repository": { "type": "git",