mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-25 18:37:19 +00:00
preliminary unix support for break
This commit is contained in:
parent
6e18a39df7
commit
52abeb002f
5 changed files with 51 additions and 2 deletions
39
examples/break.js
Normal file
39
examples/break.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
////////////////////////////////////////////////////////
|
||||
// Use the cool library //
|
||||
// git://github.com/voodootikigod/node-serialport.git //
|
||||
// to reset an arduino . //
|
||||
////////////////////////////////////////////////////////
|
||||
var com = require("serialport");
|
||||
|
||||
var serialPort = new com.SerialPort("/dev/tty.usbserial-A700eTSd", {
|
||||
baudrate: 115200,
|
||||
parser: com.parsers.readline('\r\n')
|
||||
}, false);
|
||||
|
||||
serialPort.on('open',function() {
|
||||
console.log('Port open');
|
||||
});
|
||||
|
||||
serialPort.on('data', function(data) {
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
function asserting() {
|
||||
console.log('asserting');
|
||||
serialPort.set({brk:true}, function(err, something) {
|
||||
console.log('asserted');
|
||||
setTimeout(clear, 5000);
|
||||
});
|
||||
}
|
||||
|
||||
function clear() {
|
||||
console.log('clearing');
|
||||
serialPort.set({br:false}, function(err, something) {
|
||||
console.log('clear');
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
function done() {
|
||||
console.log("done breaking");
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ function SerialPortFactory() {
|
|||
var STOPBITS = [1, 1.5, 2];
|
||||
var PARITY = ['none', 'even', 'mark', 'odd', 'space'];
|
||||
var FLOWCONTROLS = ['XON', 'XOFF', 'XANY', 'RTSCTS'];
|
||||
var SETS = ['rts', 'cts', 'dtr', 'dts'];
|
||||
var SETS = ['rts', 'cts', 'dtr', 'dts', 'brk'];
|
||||
|
||||
|
||||
// Stuff from ReadStream, refactored for our usage:
|
||||
|
|
@ -64,6 +64,7 @@ function SerialPortFactory() {
|
|||
cts: false,
|
||||
dtr: false,
|
||||
dts: false,
|
||||
brk: false,
|
||||
databits: 8,
|
||||
stopbits: 1,
|
||||
buffersize: 256,
|
||||
|
|
@ -593,6 +594,7 @@ function SerialPortFactory() {
|
|||
options = (typeof option !== 'function') && options || {};
|
||||
|
||||
// flush defaults, then update with provided details
|
||||
options.brk = options.brk || options.brk || _options.brk;
|
||||
options.rts = options.rts || options.rts || _options.rts;
|
||||
options.cts = options.cts || options.cts || _options.cts;
|
||||
options.dtr = options.dtr || options.dtr || _options.dtr;
|
||||
|
|
|
|||
|
|
@ -481,6 +481,7 @@ NAN_METHOD(Set) {
|
|||
memset(baton, 0, sizeof(SetBaton));
|
||||
baton->fd = fd;
|
||||
baton->callback = new NanCallback(callback);
|
||||
baton->brk = options->Get(NanNew<v8::String>("brk"))->ToBoolean()->BooleanValue();
|
||||
baton->rts = options->Get(NanNew<v8::String>("rts"))->ToBoolean()->BooleanValue();
|
||||
baton->cts = options->Get(NanNew<v8::String>("cts"))->ToBoolean()->BooleanValue();
|
||||
baton->dtr = options->Get(NanNew<v8::String>("dtr"))->ToBoolean()->BooleanValue();
|
||||
|
|
|
|||
|
|
@ -178,6 +178,7 @@ public:
|
|||
bool cts;
|
||||
bool dtr;
|
||||
bool dsr;
|
||||
bool brk;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -722,8 +722,14 @@ void EIO_Set(uv_work_t* req) {
|
|||
bits |= TIOCM_DSR;
|
||||
}
|
||||
|
||||
data->result = ioctl( data->fd, TIOCMSET, &bits );
|
||||
//todo check these returns
|
||||
if (data->brk) {
|
||||
ioctl(data->fd, TIOCSBRK, NULL);
|
||||
}else{
|
||||
ioctl(data->fd, TIOCCBRK, NULL);
|
||||
}
|
||||
|
||||
data->result = ioctl(data->fd, TIOCMSET, &bits );
|
||||
}
|
||||
|
||||
void EIO_Drain(uv_work_t* req) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue