Windows上的PHP串行通信 [英] Serial comm with PHP on Windows

查看:102
本文介绍了Windows上的PHP串行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种与Windows上的RS232串行COM端口通信的方法.我在网上找到2个解决方案,一个并非完全免费(引入了故意的延迟)在功能上)和另一个在Windows上功能有限.后者只能写入Windows上的COM端口,而不能读取.

I am looking for a way to communicate with RS232 serial COM port on windows. I have found 2 solutions on the net, one which is not totally free (introduces deliberate delays on the function) and another with limited capability on Windows. The latter can only write to a COM port on Windows, not read.

我看不到第一个解决方案的代码,因为它已编译为.dll(这很有意义,否则人们可以编辑延迟而不购买它...),而第二个似乎只能使用使用fopen()打开端口,然后使用fwrite()对其进行写入,就像对流进行操作一样.但是显然,对其进行读取不会返回任何内容.

I can't look at the code of the first solution since it is compiled into a .dll (makes sense, otherwise people can just edit the delay and not purchase it...) and the second one seems only to use fopen() to open the port and later fwrite() to it for writing, just like one would do to a stream. But apparently freading it returns nothing.

我知道第一个解决方案是可行的,尽管它确实需要Apache使用php-cgi模块而不是php5module.

I know it's possible as the first solution did it, although it does require Apache to use php-cgi module instead of php5module.

有什么想法吗?

推荐答案

以上每种解决方案要么效率低下,要么工作量过多.

Every solution above is either inefficient or too much work.

您可以只使用 PHP-DIO库(dio_fcntl,dio_open, dio_read,dio_write,dio_seek等).它也在 DIO的PHP手册条目中:

You can just use the PHP-DIO library (dio_fcntl, dio_open, dio_read, dio_write, dio_seek, ...). It's also in the PHP manual's entry for DIO:

此PECL软件包默认情况下不可用.如果您的PHP 5.2.x大于5.2.6,则要在Windows上获取它,可以将其作为ZIP的一部分下载:

This PECL package isn't available by default. To get it for Windows if you have PHP 5.2.x greater than 5.2.6, you can download it as part of a ZIP:

非线程安全(适用于IIS)

这两个链接均在 http://中找到www.deveblog.com/index.php/download-pecl-extensions-for-windows/

这是Linux的构建版本,只需获取它并执行phpize/configure/make /make安装东西.

Here is the build from Linux, just get it and do the phpize/configure/make/make install thing.

我不知道是否应该在Apache会话中使用它,但是请继续使用它.

I don't know whether it should be used in an Apache session, but go for it.

这篇关于Windows上的PHP串行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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