Last active
February 17, 2020 23:22
-
-
Save aeciolevy/c7ace7ef7f2974e4aaa50981338317c4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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