Created
October 17, 2013 17:02
-
-
Save thebadger412/7028519 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
'use strict'; | |
// Verbose example of reading `8` discrete inputs starting from address `0x0000` | |
// from a MODBUS TCP/IP slave. | |
var net = require('net'); | |
var SerialConnection = require('../lib/connections/SerialConnection'); | |
var RtuTransport = require('../lib/transports/RtuTransport'); | |
var functions = require('../lib/functions'); | |
var Transaction = require('../lib/Transaction'); | |
var Master = require('../lib/Master'); | |
var socket = new net.Socket(); | |
//Opening serialport | |
var SerialPort = require("serialport").SerialPort | |
var samsPort = new SerialPort("COM8", { | |
baudrate: 9600 | |
}, false); // this is the openImmediately flag [default is true] | |
var connection = new SerialConnection(samsPort); | |
samsPort.open(function () { | |
console.log('open'); | |
samsPort.write("ls\n", function(err, results) { | |
console.log('err ' + err); | |
console.log('results ' + results); | |
}); | |
}); | |
connection.on('open', function() | |
{ | |
console.log('[connection#open]'); | |
}); | |
connection.on('close', function() | |
{ | |
console.log('[connection#close]'); | |
}); | |
connection.on('error', function(err) | |
{ | |
console.log('[connection#error] %s', err.message); | |
}); | |
connection.on('data', function(data) | |
{ | |
console.log('[connection#data]', data); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment