Read data form serial port on windows with php

后端 未结 3 1371
轻奢々
轻奢々 2021-01-07 02:55

I want to read data in php using USB serial. I am Using Rs232 to USB cable. I have sartorius balance machine. now i want to read machine data using USB com port. and store

3条回答
  •  失恋的感觉
    2021-01-07 03:28

    I am using Node js To read serial port and send output to PHP server.

    var fs = require('fs')
    , http = require('http')
    , socketio = require('socket.io')
    , com = require("serialport");
    
    var WebSocketServer = require('websocket').server;
    
    // create the server
    var wsServer = new WebSocketServer({
    httpServer: http.createServer().listen(1337)
    });
    
    var serialPort = new com.SerialPort("COM4", {
    baudrate: 1200,
    dataBits: 7,
    parity: 'none',
    stopBits: 1,
    parser: com.parsers.readline('\r\n')
    });
    
    wsServer.on('request', function(request) {
    
    var connection = request.accept(null, request.origin);
    serialPort.on('data', function(data) {
            //console.log('Received Message: ' + data);
            fs.writeFile("data.txt", data, function(err) {
                if(err) {
                    return console.log(err);
                }
            });
            connection.sendUTF(data);
    });
    });
    

提交回复
热议问题