Skip to content

Instantly share code, notes, and snippets.

@aeciolevy
Last active February 17, 2020 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aeciolevy/c7ace7ef7f2974e4aaa50981338317c4 to your computer and use it in GitHub Desktop.
Save aeciolevy/c7ace7ef7f2974e4aaa50981338317c4 to your computer and use it in GitHub Desktop.
const net = require('net');
let isConnected = false;
const delay = time => new Promise(resolve => setTimeout(resolve, time));
const client = net.createConnection({ host: '192.168.7.2', port: '9999' }, () => {
console.log('client connected to machine motion');
isConnected = true;
});
let count = 1;
client.on('data', (data) => {
console.log(`received ${count}:`,data.toString() + '\n')
count++;
});
client.on('error', () => console.log('error to connect to MM'));
(async function main() {
while (!isConnected) {
await delay(1000);
console.log('isConnected: ', isConnected);
}
client.write('io-expander/1/digital-input/0');
await delay(100);
client.write('io-expander/1/digital-input/1');
await delay(100);
client.write('io-expander/1/digital-input/2');
await delay(100);
client.write('io-expander/1/digital-input/3');
await delay(100);
client.write('io-expander/1/digital-input/0');
await delay(100);
client.write('io-expander/1/digital-input/1');
await delay(100);
client.write('io-expander/1/digital-input/2');
await delay(100);
client.write('io-expander/1/digital-input/3');
await delay(100);
client.write('io-expander/1/digital-input/0');
await delay(100);
client.write('io-expander/1/digital-input/1');
await delay(2000)
client.write('io-expander/1/digital-output/0 1');
await delay(1000);
client.write('io-expander/1/digital-output/1 1');
await delay(1000);
client.write('io-expander/1/digital-output/2 1');
await delay(1000);
client.write('io-expander/1/digital-output/3 1');
client.write('io-expander/1/digital-output/0 0');
await delay(1000);
client.write('io-expander/1/digital-output/1 0');
await delay(1000);
client.write('io-expander/1/digital-output/2 0');
await delay(1000);
client.write('io-expander/1/digital-output/3 0');
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment