mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
* upgrade to non deprecated buffer methods * Don't lint on node 4 as it's now broken I really wish packages would keep things working on LTS platforms.
36 lines
824 B
JavaScript
36 lines
824 B
JavaScript
'use strict';
|
|
|
|
const Buffer = require('safe-buffer').Buffer;
|
|
const SerialPort = require('../../');
|
|
const port = process.env.TEST_PORT;
|
|
|
|
if (!port) {
|
|
console.error('Please pass TEST_PORT environment variable');
|
|
process.exit(1);
|
|
}
|
|
|
|
// var Binding = require('../../lib/bindings/mock');
|
|
// Binding.createPort(port);
|
|
// SerialPort.Binding = Binding;
|
|
// debugger;
|
|
|
|
const writeData = Buffer.alloc(50000, 1);
|
|
|
|
const serialPort = new SerialPort(port, {
|
|
// baudRate: 115200
|
|
});
|
|
|
|
serialPort.once('data', () => {
|
|
console.log('writing', writeData.length, 'bytes of data');
|
|
serialPort.write(writeData);
|
|
});
|
|
|
|
let recieved = 0;
|
|
serialPort.on('data', (data) => {
|
|
recieved += data.length;
|
|
if (recieved >= writeData.length) {
|
|
serialPort.close(() => {
|
|
console.log('finished reading', recieved, 'bytes');
|
|
});
|
|
}
|
|
});
|