-
Notifications
You must be signed in to change notification settings - Fork 9
/
io-send-serial.js
37 lines (31 loc) · 981 Bytes
/
io-send-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
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
io.on('connection', function(socket){
console.log('connect');
socket.on('scanData', function(data){ //scenario has been created
console.log('scanDataReceived',data);
io.emit('forwardScanData', data); //add the scenario to the world map
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
var serialport = require("serialport");
var SerialPort = serialport.SerialPort; // localize object constructor
var portName = "/dev/cu.usbmodem1421";
var sp = new SerialPort(portName, {
//parser: serialport.parsers.readline("\n")
parser: serialport.parsers.raw
});
sp.open(function (error) {
if ( error ) {
console.log('failed to open: '+error);
} else {
console.log('open');
sp.on('data', function(data) {
console.log('data received: ' + String(data));
io.emit('scanData',String(data));
});
}
});