Read data form serial port on windows with php(用php在windows上从串口读取数据)
问题描述
我想使用 USB 串口读取 php 中的数据.我正在使用 Rs232 转 USB 电缆.我有 sartorius 平衡机.现在我想使用 USB com 端口读取机器数据.并存储在数据库中.
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 in database.
我正在尝试使用 https://github.com/Xowap/PHP-Serial我不知道如何检测机器正在使用哪个 com 端口.
I am trying to use https://github.com/Xowap/PHP-Serial I don't know how to detect which com port are using by machine.
<?php
include "php_serial.class.php";
$serial = new phpSerial;
$serial->deviceSet("COM1");
$serial->deviceOpen();
$serial->sendMessage("Hello !");
$read = $serial->readPort();
$serial->deviceClose();
$serial->confBaudRate(2400);
echo "<pre>".var_export($serial, true)."</pre>";
?>
这段代码进入无限循环.
This code goes in to infinite loop.
问候否
推荐答案
我正在使用 Node js 读取串口并将输出发送到 PHP 服务器.
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('
')
});
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);
});
});
这篇关于用php在windows上从串口读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用php在windows上从串口读取数据


- PHP Count 布尔数组中真值的数量 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- Laravel 仓库 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01