|
|
const express = require('express');const app = express();const http = require('http');const Readline = require('@serialport/parser-readline')const server = http.createServer(app);const {Server} = require("socket.io");const io = new Server(server);// const bodyparser = require('body-parser')
// const SerialPort = require('serialport')
// const parsers = SerialPort.parsers;
// const parser = new parsers.Readline({
// delimiter: '\n'
// });
// const port = new SerialPort("COM6",{
// io: io,
// route: '/port/ttys002',
// bitRate: 115200,
// dataBits: 8,
// buffersize:1,
// parity: 'none',
// flowControl: false,
// dealay: 9600
// });
// const ByteLength = require('@serialport/parser-byte-length');
// const { ifError } = require('assert');
// const { parse } = require('path');
// const parser = port.pipe(new ByteLength({length: 1 }))
// //const parser = port.pipe(new parsers.Readline({delimiter:'\r\n'}))
app.get('/', (req, res) => { res.sendFile(__dirname + '/index1.html'); });//SerialPort
// port.on("open", () => {
// console.log("serialport Port open");
// });
// parser.on('data',function(data){
// var Pressure = data[0];
// if(Pressure <=100){
// io.emit('Pre_War')
// }
// console.log(data);
// io.emit('data',dat,dd[1]);
// });
var c='\0';var d='\0';var a=0;var z=[];var count=0;var f={};var i=0;f[0] = 35.1;f[1] = 36.1;f[2] = 'o';f[3] = 33.1;f[4] = 22.1;f[5]= 'x';
// parser.on('data',function(data){
// data=data.toString("ASCII");
// c+=data;
// console.log('c'+c);
// if(data=='\n'){
// var f= c;
// c='\0';
// if(f!='o'){
// z[count] = parseFloat(f.substr(1));
// console.log('z:'+(z[count]));
// io.emit('data',z[count],count);
// if(count==1){
// io.emit('data1',z[count],count);
// count=0;
// }
// else{
// io.emit('data',z[count],count);
// count++;
// }
// }
// else if(f=='o'){
// io.emit('Pressure',c);
// }
// else if(f=='x'){
// io.emit('Pressure',c);
// }
// }
// console.log('c:'+c);
// console.log('data:'+data.toString("UTF-8"));
// io.emit('data',data);
// });
// socket
server.listen(3000, () => { console.log('listening on *:5000'); for(i=0; i<3; i++){ if(f[i]!='o'){ z[count] = f[i]; console.log('z:'+(z[count])); io.emit('data',z[count],count); if(count==1){ io.emit('data1',z[count],count); count=0; } else{ io.emit('data',z[count],count); count++; } } else if(f=='o'){ io.emit('Pressure',c); } else if(f=='x'){ io.emit('Pressure',c); }} });
|