@autocodingsystems/x20-device
v1.0.4
Published
A framework for creating a generic device that the ACS X20 driver can talk to.
Downloads
9
Readme
x20 Emulation
Installation
npm install --save @autocodingsystems/x20-emulation
Quickstart
A fully featured x20 device implementation.
const server = require('net').createServer()
const device = require('@autocodingsystems/x20-device')(server)
device.on('connection', (connectiontodriver) => {
connectiontodriver.on('error', (err) => { console.log('ERROR: ', err) })
connectiontodriver.on('close', (had_error) => { console.log('CLOSED with error', had_error) });
});
device.on('connectionstatusmode', (connectionstatusmode) => { console.log('Connection Status Mode', connectionstatusmode) })
device.on('outputchanged', (data) => { console.log('Output changed', data.outputid, data.state) })
device.on('counterreset', (data) => { console.log('Counter reset', data) })
server.listen(12000)
Sending data back to the driver
const server = require('net').createServer()
const device = require('@autocodingsystems/x20-device')(server)
device.on('connection', (connectiontodriver) => {
connectiontodriver.on('error', (err) => { console.log('ERROR: ', err) })
connectiontodriver.on('close', (had_error) => { console.log('CLOSED with error', had_error) });
});
server.listen(12000)
device.inputs[0].setAutoCount(true)
let flipflop = true
setInterval(() => { device.inputs[0].setState(flipflop = !flipflop) }, 1000)
setTimeout(() => { device.errors.push('Custom error'); device.setDirty() }, 60000)
setTimeout(() => { device.errors.pop(); device.setDirty() }, 90000)