-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_serial.js
71 lines (65 loc) · 1.03 KB
/
test_serial.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var SerialPort = require("serialport");
var num = 0;
// this is the openImmediately flag [default is true]
var my_uart = new SerialPort
(
"/dev/ttyS0",
{
baudRate: 256000
},
false
);
function build_tx_string( num )
{
return 'P' +num +'\0';
}
var num = 0;
my_uart.on
(
"open",
function()
{
console.log("Port is open!");
//Periodically send the current server time to the client in string form
setInterval
(
function()
{
console.log("Sending str: ", build_tx_string(num) );
my_uart.write
(
build_tx_string(num),
function(err, res)
{
if (err)
{
console.log("err ", err);
}
else
{
if (res)
{
console.log("results ", results);
}
else
{
console.log("write success!");
}
}
}
);
num++;
},
//Send every * [ms]
500
);
}
);
my_uart.on
(
'data',
function(data)
{
console.log('data received: ' + data);
}
);