diff --git a/.gitignore b/.gitignore index e1a6cbf..c94991a 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 0000000..b1e1b40 --- /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 a0a99c8..6a00fef 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",