在 Windows 上使用 PHP 进行串行通信
我正在寻找一种与 Windows 上的 RS232 串行 COM 端口通信的方法.我在网上找到了 2 个解决方案, 一个 不是完全免费的(引入了故意延迟关于函数)和 another 在 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() 对其进行写入,就像对流所做的那样.但显然 freading 它什么也没有返回.
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,...).它也在 PHP 手册的 DIO 条目中:
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:
线程安全(适用于 Apache)
非线程安全(对于 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.
相关文章