PHP COM端口与DIO的连接 [英] PHP COM port connection with DIO
问题描述
我正在尝试将加权机与PHP连接.
I am trying to connect weighting machine with PHP.
我已经用超级终端测试了它的正常工作.
I have tested with hyperterminal it is working fine.
但是当我将PHP代码与fopen
或dio_open
一起使用时,将执行该代码,但是当调用fgets
或dio_read
时,它将挂起并且不显示任何内容.
But when I use PHP code with fopen
or dio_open
it is executed but when fgets
or dio_read
is called, it hangs and does not display anything.
exec('mode com2: BAUD=2400 PARITY=N data=8 stop=1 xon=on');
$fp = fopen("COM2:", "r");
if (!$fp) {
echo "Uh-oh. Port not opened.";
} else {
echo fgets($fp);
fclose($fp);
}
DIO示例
exec('mode COM2: baud=2400 data=8 stop=1 parity=n xon=off to=on');
$fd = dio_open('COM2:', O_RDONLY | O_NONBLOCK, 0644);
echo dio_read($fd, 256);
我无法通过两种方式来收集任何有用的输出.
I'm unable with my tries of both ways to gather any useful output.
我需要inpout32.dll
文件进行连接吗?
Do I require inpout32.dll
file to connect?
php_iol.dll
的作用是什么,我也需要此文件?
And what is role of php_iol.dll
, this file I also required?
推荐答案
PHP无法在Windows下从串行端口读取.在Linux系统上不是这种情况,在Linux系统上,使用常见的PHP文件系统功能从COM端口读取数据没有问题.
PHP can not read from serial ports under Windows. This is not the case on a Linux system, on which there is no problem to reading from COM ports with the common PHP filesystem functions.
对于 DIO扩展,这些文件系统功能也是首选的方法:
Those filesystem functions are also the preferred ways to do in regard of the DIO extension:
使用DIO功能应 仅在需要直接控制设备时才考虑使用. 在所有其他情况下,标准文件系统功能为 绰绰有余.
The use of the DIO functions should be considered only when direct control of a device is needed. In all other cases, the standard filesystem functions are more than adequate.
当您将DIO示例报告为无效"时,您需要跟踪错误.参见:
As you report your DIO example as "non-working", you need to keep track of errors. See:
接下来,您需要首先找到一个有效的POSIX示例,因为DIO不是超级终端,而是POSIX样式.
Next to that you need to find a working POSIX example first, as DIO is not hyperterminal but POSIX style.
或者存在一些通过网络代理COM端口的软件(例如GPL版本的 serproxy ) .这可能会解决您与操作系统的集成问题,但是我很确定您不走运.
Alternatively some software exists to proxy a COM port through network (for example GPL'ed serproxy). This might solve you integration problem with your operating system, however I'm pretty sure you're out of luck.
比较:
- 如何像这样的QBasic程序在PHP中读取RS232串行端口(2010年7月)
- 使用PHP读取COM(串行调制解调器)(2011年6月)
- 授予PHP访问COM端口的权限(2012年2月)-仅写
- How to Read RS232 Serial Port in PHP like this QBasic Program (Jul 2010)
- Reading COM (Serial Modem) in PHP (Jun 2011)
- Giving PHP permission to access COM port (Feb 2012) - writing only
这篇关于PHP COM端口与DIO的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!