Created
October 17, 2013 18:50
-
-
Save thebadger412/7030193 to your computer and use it in GitHub Desktop.
This file contains 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
var SerialPort = require('serialport').SerialPort; | |
var modbus = require('../lib'); | |
var serialPort = new SerialPort('COM8', { | |
baudRate: 9600 | |
}); | |
serialPort.write = function(data) | |
{ | |
console.log('TX:', data); | |
SerialPort.prototype.write.call(this, data); | |
}; | |
serialPort.on('data', function(data) | |
{ | |
console.log('RX:', data); | |
//THIS DOES EXECUTE THOUGH..they both talk fine then so the code seems fine just the once open never happens.. | |
master.readCoils(0, 8, | |
{ | |
unit: 245, | |
interval: 1000, | |
onComplete: function(err, res) | |
{ | |
if (err) | |
{ | |
console.error(err.message); | |
} | |
else | |
{ | |
console.log(res.toString()); | |
} | |
} | |
}); | |
}); | |
var master = modbus.createMaster | |
({ | |
transport: | |
{ | |
type: 'rtu', // ip, ascii or rtu | |
eofTimeout: 50, | |
connection: { | |
type: 'serial', // tcp, udp or serial | |
serialPort: serialPort | |
} | |
} | |
}); | |
master.once('open', function() | |
{ | |
//IT NEVER GETS TO HERE SO NOTHING HAPPENS | |
console.log("opened master"); | |
master.readCoils(0, 8, | |
{ | |
unit: 245, | |
interval: 1000, | |
onComplete: function(err, res) | |
{ | |
if (err) | |
{ | |
console.error(err.message); | |
} | |
else | |
{ | |
console.log(res.toString()); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment