Skip to content

Commit

Permalink
untracked files on napi-rewrite: 008b1f5 save
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiask88 committed Mar 10, 2024
0 parents commit 7b387d6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/client.js
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)}`)
}
})()
43 changes: 43 additions & 0 deletions test/server.js
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)}`)
}
})();

0 comments on commit 7b387d6

Please sign in to comment.