Skip to content

Commit 4f4fbff

Browse files
author
Christian Stimming
committed
Add example script for initial connection; make it callable by "npm test"
1 parent aa077d0 commit 4f4fbff

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ typings/
5959

6060
# Visual Studio Code config folder
6161
.vscode
62+
package-lock.json

examples/example.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const { Session, Clsid, ComServer } = require('../dcom')
2+
3+
const domain = 'WORKGROUP'
4+
const username = 'myuser'
5+
const password = 'mypassword'
6+
const ipAddress = '1.2.3.4'
7+
const timeout = 1000
8+
const classIdString = 'F8582CF2-88FB-11D0-B850-00C0F0104305' // Matrikon.OPC.Simulation
9+
10+
const sessionSingleton = new Session()
11+
12+
async function main () {
13+
const comSession = sessionSingleton.createSession(domain, username, password)
14+
comSession.setGlobalSocketTimeout(timeout)
15+
const clsid = new Clsid(classIdString)
16+
const comServer = new ComServer(clsid, ipAddress, comSession, { major: 5, minor: 7 })
17+
18+
try {
19+
// start the COM Server
20+
await comServer.init()
21+
console.log(`Successfully connected to ${ipAddress}`)
22+
23+
await comServer.closeStub()
24+
} catch (err) {
25+
console.trace(err)
26+
}
27+
28+
await comSession.destroySession(comSession)
29+
}
30+
31+
main()

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Simple lib to support DCOM communication (Heavly based on J-Interop)",
55
"main": "dcom/index.js",
66
"scripts": {
7-
"test": "none"
7+
"test": "node examples/example.js"
88
},
99
"repository": {
1010
"type": "git",

0 commit comments

Comments
 (0)