PHP COM端口与DIO的连接 [英] PHP COM port connection with DIO

查看:462
本文介绍了PHP COM端口与DIO的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将加权机与PHP连接.

I am trying to connect weighting machine with PHP.

我已经用超级终端测试了它的正常工作.

I have tested with hyperterminal it is working fine.

但是当我将PHP代码与fopendio_open一起使用时,将执行该代码,但是当调用fgetsdio_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.

比较:

  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆