最近一直在跟其他学院的同学在弄串口通信这一块,因为这不是我擅长的,所以花费了很多时间,在这中间我用过mscomm这个控件,但是它似乎不稳定,好像win10的系统对这个控件不兼容,所以我只能另找方法,一个偶然的机会让我在一个外国网站上面找到了方法,特地跟你们分享一下。
在这之前你需要先下载一个名为php.serial.class.php文件,在https://www.phpclasses.org/package/3679-PHP-Communicate-with-a-serial-port.html里面下载。然后使用如下:
<?php
include 'PhpSerial.php';
// Let's start the class
$serial = new PhpSerial;
// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1, etc)
$serial->deviceSet("COM1");
// We can change the baud rate, parity, length, stop bits, flow control
$serial->confBaudRate(2400);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
// Then we need to open it
$serial->deviceOpen();
// T

本文介绍了在PHP中进行串口通信的解决方法,由于MSComm控件在Win10系统的兼容性问题,作者转向使用php.serial.class.php类库来实现。通过在https://www.phpclasses.org/package/3679-PHP-Communicate-with-a-serial-port.html下载所需文件,即可开始使用。

920

被折叠的 条评论
为什么被折叠?



