-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
45 lines (41 loc) · 1.03 KB
/
index.js
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
43
44
45
var pduConvert = require('sms-pdu-node');
var SerialPort = require("serialport").SerialPort;
module.exports = {
send: function(text, number, serialPortDev, options, cb) {
if (!cb) {
cb = options;
options = null;
}
if (!options) {
options = {
baudrate: 9600
};
}
var serialPort = new SerialPort(serialPortDev, options);
var pdu = pduConvert(text, number);
var logger = function(err, res) {
// console.error(err);
// console.log(res);
};
var commands = [
function(cb) {
serialPort.write(pdu.command + '\r', cb);
},
function(cb) {
serialPort.write(pdu.pdu + String.fromCharCode(26), cb); // ^Z
},
function(cb) {
serialPort.close();
}
];
//
serialPort.on("open", function () {
// console.log('serial opened');
serialPort.on('data', function(data) {
// console.log('data received: ' + data);
commands.shift()(logger);
});
commands.shift()(logger);
});
}
};