mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-28 11:57:30 +00:00
good to roll
This commit is contained in:
parent
77e38c7898
commit
a0018bb814
3 changed files with 28 additions and 16 deletions
|
|
@ -1,11 +1,11 @@
|
|||
"use strict";
|
||||
/*global process require exports console */
|
||||
|
||||
var sys = require('sys'),
|
||||
Buffer = require('buffer').Buffer,
|
||||
events = require('events'),
|
||||
fs = require('fs'),
|
||||
serialport_native = require('./serialport_native');
|
||||
var sys = require('sys');
|
||||
var Buffer = require('buffer').Buffer;
|
||||
var events = require('events');
|
||||
var fs = require('fs');
|
||||
var serialport_native = require('./serialport_native');
|
||||
|
||||
|
||||
var BAUDRATES = [115200, 57600, 38400, 19200, 9600, 4800, 2400, 1800, 120,, 600, 300, 200, 150, 134, 110, 75, 50];
|
||||
|
|
@ -37,7 +37,7 @@ function SerialPort(path) {
|
|||
this.parity = arguments[4];
|
||||
}
|
||||
|
||||
this.fd = serialport_native.open(path, baudrate, databits, stopbits, parity);
|
||||
this.fd = serialport_native.open(path, this.baudrate, this.databits, this.stopbits, this.parity);
|
||||
this.active = true;
|
||||
|
||||
this.readWatcher = new process.IOWatcher();
|
||||
|
|
@ -55,7 +55,7 @@ function SerialPort(path) {
|
|||
|
||||
// readWatcher gets a callback when pcap has data to read. multiple packets may be readable.
|
||||
this.readWatcher.callback = function pcap_read_callback() {
|
||||
var packets_read = binding.dispatch(me.buf, packet_ready);
|
||||
var packets_read = binding.dispatch(me.buf, data_ready);
|
||||
if (packets_read < 1) {
|
||||
// TODO - figure out what is causing this, and if it is bad.
|
||||
me.empty_reads += 1;
|
||||
|
|
@ -79,8 +79,11 @@ SerialPort.prototype.close = function () {
|
|||
};
|
||||
|
||||
|
||||
SerialPort.prototype.write = function (buffer) {
|
||||
fs.write(this.fd);
|
||||
SerialPort.prototype.write = function (buffer, cb) {
|
||||
if (cb)
|
||||
fs.write(this.fd, buffer, cb);
|
||||
else
|
||||
fs.write(this.fd, buffer);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
14
test.js
14
test.js
|
|
@ -1,9 +1,9 @@
|
|||
var SerialPort = require("./serialport").SerialPort;
|
||||
var sys = require("sys");
|
||||
var fs = require("fs");
|
||||
|
||||
var SerialPort = require("./serialport_native").SerialPort;
|
||||
|
||||
|
||||
var fd = SerialPort.open("./sampleport");
|
||||
fs.close(fd);
|
||||
|
||||
var serial_port = new SerialPort("./sampleport");
|
||||
serial_port.write("test");
|
||||
serial_port.on("data", function () {
|
||||
sys.puts("here");
|
||||
})
|
||||
// serial_port.close();
|
||||
|
|
|
|||
9
test_native.js
Normal file
9
test_native.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
var sys = require("sys");
|
||||
var fs = require("fs");
|
||||
|
||||
var SerialPort = require("./serialport_native");
|
||||
|
||||
|
||||
var fd = SerialPort.open("./sampleport");
|
||||
fs.close(fd);
|
||||
|
||||
Loading…
Add table
Reference in a new issue