如何通过PHP读取RS232端口

如何通过PHP读取RS232端口,php,hardware-interface,Php,Hardware Interface,我正在尝试使用PHP套接字库建立连接,但没有其他方法,连接无法正常工作 <?php include "php_serial.class.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 f

我正在尝试使用PHP套接字库建立连接,但没有其他方法,连接无法正常工作

<?php
include "php_serial.class.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");

// Then we need to open it
$serial->deviceOpen();

// To write into
$serial->sendMessage("Hello !");

// Or to read from
$read = $serial->readPort();

// If you want to change the configuration, the device must be closed
$serial->deviceClose();

// We can change the baud rate
$serial->confBaudRate(2400);

// etc...
?>

如果您在Windows上运行此操作,因为您选择的“COM1”让我相信,那么当端口从不超时时,存在一个已知问题。我使用批处理文件启动我的php脚本,成功地解决了这个问题,但首先调用comconfig.exe来解决这个问题:

REM Fix bug with Windows serial port timeout not working
comconfig.exe COM1
php.exe myscript.php
当我的脚本开始使用以下行时,我也会运行MODE命令,但我不确定这是必需的(尽管是皮带和大括号!):

我在查找comconfig.exe程序时遇到了很多问题,因此我已上载了完整的程序,并为您提供了所需的vcredit.exe:


你说它不工作和工作不正常是什么意思?它部分有效还是完全无效?它会抛出错误吗?设备连接好了吗(你能看到吗?)我不认为有很多人会将php连接到rs232,但谁知道呢:)谢谢你的回复,我们在哪里可以执行这个脚本REM修复Windows串行端口超时不工作的错误comconfig.exe COM1 php.exe myscript.phpHi@KGolding,comconfig.exe不再可用,您能给我一些提示在哪里可以找到它吗?您好,这里是comconfig.exe和vcdist.exe的新链接
REM Fix bug with Windows serial port timeout not working
comconfig.exe COM1
php.exe myscript.php
exec('MODE COM1 to=on');