-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserial.js
More file actions
28 lines (24 loc) · 691 Bytes
/
serial.js
File metadata and controls
28 lines (24 loc) · 691 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
var serial = require('serialport'),
alphabet = 'HOLA',
alphabetArray = alphabet.split('');
var port = new serial('/dev/cu.usbmodem1421', {
baudRate: 250000
});
port.on('open', function() {
sendChars = setInterval(function(){
if (!alphabetArray.length) {
clearInterval(sendChars);
}
port.write(alphabetArray[0], function(err) {
if (err) {
return console.log('Error on write: ', err.message);
}
console.log(alphabetArray[0]);
alphabetArray.shift();
});
}, 2000)
});
port.on('error', function(err) {
console.log('Error: ', err.message);
})
console.log('ended');