Skip to content

Commit

Permalink
Add example script for initial connection; make it callable by "npm t…
Browse files Browse the repository at this point in the history
…est"
  • Loading branch information
Christian Stimming committed Nov 27, 2020
1 parent aa077d0 commit 4f4fbff
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ typings/

# Visual Studio Code config folder
.vscode
package-lock.json
31 changes: 31 additions & 0 deletions examples/example.js
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4f4fbff

Please sign in to comment.