-
Notifications
You must be signed in to change notification settings - Fork 0
/
serial.js
54 lines (31 loc) · 809 Bytes
/
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
const {promisify} = require('util')
const SerialPort =require('serialport')
var com = new SerialPort('/dev/ttyUSB0', {
baudRate: 9600,
databits: 8,
parity: 'none'
,stopBits:1,
flowControl:false,
}, false);
const express=require('express');
const app=express();
let isOn=false;
let target=""
app.get('/a',(req,res)=>{target=req.query.target; res.end();})
app.listen(3000);
com.on('open',()=>{console.log('open');
setInterval(()=>{
for(var i=0;i<target.length;i++)
com.write(new Buffer(target[i],'ascii'),function(err, results) {
if(err!=null)
{
console.log('Error: ' + err);
}
else
console.log('Results ' + results);}
);
},1000)
})
com.on('data', function(data) {
console.log(data);
});