From 7b387d6e702c30cc26ec6e554b4df521717665a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20K=C3=BCsel?= Date: Sun, 10 Mar 2024 17:25:18 +0100 Subject: [PATCH] untracked files on napi-rewrite: 008b1f5 save --- test/client.js | 13 +++++++++++++ test/server.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 test/client.js create mode 100644 test/server.js diff --git a/test/client.js b/test/client.js new file mode 100644 index 0000000..8d799dc --- /dev/null +++ b/test/client.js @@ -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)}`) + } +})() diff --git a/test/server.js b/test/server.js new file mode 100644 index 0000000..032f981 --- /dev/null +++ b/test/server.js @@ -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)}`) + } +})();