-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathardpi-serial_3.js
More file actions
42 lines (30 loc) · 798 Bytes
/
Copy pathardpi-serial_3.js
File metadata and controls
42 lines (30 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var prompt = require('prompt');
var SerialPort = require("serialport");
var port = new SerialPort("/dev/ttyUSB0", {
baudRate: 9600,
parser: SerialPort.parsers.readline("\n")
});
prompt.start();
port.on('open', function() {
port.on('data', function(data) {
//console.log((data));
var res = data.split(",");
console.log(res[0]);
});
getinput();
});
function getinput(){
prompt.get(['enterCommand'], function (err, result) {
port.write(result.enterCommand, function(err) {
if (err) {
return console.log('Error on write: ', err.message);
}
console.log("Command Entered = "+result.enterCommand);
getinput();
});
});
}
// open errors will be emitted as an error event
port.on('error', function(err) {
console.log('Error: ', err.message);
})