2021 기업연계프로젝트_컴퓨터소프트웨어공학 2조 팀 Sper
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
2.8 KiB

  1. const express = require('express');
  2. const app = express();
  3. const http = require('http');
  4. const Readline = require('@serialport/parser-readline')
  5. const server = http.createServer(app);
  6. const {Server} = require("socket.io");
  7. const io = new Server(server);
  8. // const bodyparser = require('body-parser')
  9. // const SerialPort = require('serialport')
  10. // const parsers = SerialPort.parsers;
  11. // const parser = new parsers.Readline({
  12. // delimiter: '\n'
  13. // });
  14. // const port = new SerialPort("COM6",{
  15. // io: io,
  16. // route: '/port/ttys002',
  17. // bitRate: 115200,
  18. // dataBits: 8,
  19. // buffersize:1,
  20. // parity: 'none',
  21. // flowControl: false,
  22. // dealay: 9600
  23. // });
  24. // const ByteLength = require('@serialport/parser-byte-length');
  25. // const { ifError } = require('assert');
  26. // const { parse } = require('path');
  27. // const parser = port.pipe(new ByteLength({length: 1 }))
  28. // //const parser = port.pipe(new parsers.Readline({delimiter:'\r\n'}))
  29. app.get('/', (req, res) => {
  30. res.sendFile(__dirname + '/index1.html');
  31. });
  32. //SerialPort
  33. // port.on("open", () => {
  34. // console.log("serialport Port open");
  35. // });
  36. // parser.on('data',function(data){
  37. // var Pressure = data[0];
  38. // if(Pressure <=100){
  39. // io.emit('Pre_War')
  40. // }
  41. // console.log(data);
  42. // io.emit('data',dat,dd[1]);
  43. // });
  44. var c='\0';
  45. var d='\0';
  46. var a=0;
  47. var z=[];
  48. var count=0;
  49. var f={};
  50. var i=0;
  51. f[0] = 35.1;
  52. f[1] = 36.1;
  53. f[2] = 'o';
  54. f[3] = 33.1;
  55. f[4] = 22.1;
  56. f[5]= 'x';
  57. // parser.on('data',function(data){
  58. // data=data.toString("ASCII");
  59. // c+=data;
  60. // console.log('c'+c);
  61. // if(data=='\n'){
  62. // var f= c;
  63. // c='\0';
  64. // if(f!='o'){
  65. // z[count] = parseFloat(f.substr(1));
  66. // console.log('z:'+(z[count]));
  67. // io.emit('data',z[count],count);
  68. // if(count==1){
  69. // io.emit('data1',z[count],count);
  70. // count=0;
  71. // }
  72. // else{
  73. // io.emit('data',z[count],count);
  74. // count++;
  75. // }
  76. // }
  77. // else if(f=='o'){
  78. // io.emit('Pressure',c);
  79. // }
  80. // else if(f=='x'){
  81. // io.emit('Pressure',c);
  82. // }
  83. // }
  84. // console.log('c:'+c);
  85. // console.log('data:'+data.toString("UTF-8"));
  86. // io.emit('data',data);
  87. // });
  88. // socket
  89. server.listen(3000, () => {
  90. console.log('listening on *:5000');
  91. for(i=0; i<3; i++){
  92. if(f[i]!='o'){
  93. z[count] = f[i];
  94. console.log('z:'+(z[count]));
  95. io.emit('data',z[count],count);
  96. if(count==1){
  97. io.emit('data1',z[count],count);
  98. count=0;
  99. }
  100. else{
  101. io.emit('data',z[count],count);
  102. count++;
  103. }
  104. }
  105. else if(f=='o'){
  106. io.emit('Pressure',c);
  107. }
  108. else if(f=='x'){
  109. io.emit('Pressure',c);
  110. }
  111. }
  112. });