-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
74 lines (55 loc) · 1.45 KB
/
app.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
72
73
74
var express = require('express');
var app = express();
var httpServer = require('http').createServer(app);
var io = require('socket.io')(httpServer);
const SerialPort = require('serialport');
const Readline = require('@serialport/parser-readline');
const port = new SerialPort('COM3', {
baudRate: 19200
});
const parser = port.pipe(new Readline({ delimiter: '\r\n' }));
parser.on('data', function(data){
switch (data) {
case 'A':
// io.emit('start');
console.log("A");
break;
case 'B':
// io.emit('stop');
console.log("B");
break;
case 'TESTE':
console.log("TESTE");
break;
default:
break;
}
});
io.on('connection', function(tecla) {
tecla.on('text',function(text){
io.emit('text',text);
});
tecla.on('start',function(){
io.emit('start');
});
tecla.on('stop',function(){
io.emit('stop');
});
tecla.on('mais',function(){
console.log("mais");
io.emit('mais');
});
tecla.on('menos',function(){
console.log("menos");
io.emit('menos');
});
});
app.use(express.static(__dirname + '/node_modules'));
app.use("/javas", express.static('./javas/'));
app.get('/', function(req, res,next) {
res.sendFile(__dirname + '/index.html');
});
app.get('/tele', function(req, res,next) {
res.sendFile(__dirname + '/tele.html');
});
httpServer.listen(8000,'192.168.20.103');