-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
28 lines (19 loc) · 795 Bytes
/
app.js
File metadata and controls
28 lines (19 loc) · 795 Bytes
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
/*
const {SerialPort} = require('serialport');
const {ReadlineParser} = require('@serialport/parser-readline');
const port = new SerialPort({ path: 'COM7', baudRate: 9600 })
const parser = port.pipe(new ReadlineParser({ delimiter: '\r\n' }));
parser.on('data', console.log);
*/
const { SerialPort } = require('serialport');
const { ReadlineParser } = require('@serialport/parser-readline');
const WebSocket = require('ws');
const port = new SerialPort({ path: 'COM7', baudRate: 9600 });
const parser = port.pipe(new ReadlineParser({ delimiter: '\r\n' }));
const wss = new WebSocket.Server({ port: 5000 });
wss.on('connection', function connection(ws) {
console.log('WebSocket connected and Server running on port 5000');
parser.on('data', (data) => {
ws.send(data);
});
});