-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
untracked files on napi-rewrite: ab44857 On napi-rewrite: save
- Loading branch information
1 parent
e492c3b
commit 2727834
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const snap7 = require('../'); | ||
const s7client = new snap7.S7Client(); | ||
|
||
(async () => { | ||
try { | ||
await s7client.ConnectTo('127.0.0.1', 0, 1); | ||
console.log('Connected') | ||
var DB1 = await s7client.DBRead(1, 0, 8); | ||
console.log(DB1); | ||
} catch (error) { | ||
console.log(` >> Error Code #${error} - ${s7client.ErrorText(error)}`) | ||
} | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const snap7 = require('../'); | ||
const s7server = new snap7.S7Server(); | ||
const s7client = new snap7.S7Client(); | ||
|
||
|
||
// Set up event listener | ||
s7server.on("event", (event) => { | ||
console.log(s7server.EventText(event)); | ||
}); | ||
|
||
// Create a new Buffer and register it to the server as DB1 | ||
var db1 = Buffer.alloc(100, 'ÿ'); | ||
s7server.RegisterArea(s7server.srvAreaDB, 1, db1); | ||
console.log('RegisterArea'); | ||
|
||
// Start the server | ||
(async () => { | ||
try { | ||
await s7server.StartTo('127.0.0.1'); | ||
console.log('Server started'); | ||
|
||
// Close the server after 20s in this example | ||
setTimeout(async function() { | ||
await s7server.Stop(); | ||
console.log('Server stopped') | ||
s7server.UnregisterArea(s7server.srvAreaDB, 1); | ||
console.log('UnregisterArea') | ||
s7server.removeAllListeners("event"); | ||
}, 10000); | ||
} catch (error) { | ||
console.log(` >> Error Code #${error} - ${s7server.ErrorText(error)}`) | ||
} | ||
|
||
try { | ||
await s7client.ConnectTo('127.0.0.1', 0, 1); | ||
console.log('Connected') | ||
console.log(await s7client.DBRead(1, 0, 8)); | ||
console.log(await s7client.ListBlocksOfType(s7client.Block_DB)); | ||
console.log(await s7client.GetAgBlockInfo(s7client.Block_DB, 1)); | ||
} catch (error) { | ||
console.log(` >> Error Code #${error} - ${s7client.ErrorText(error)}`) | ||
} | ||
})(); |