PHP以奇怪的波特率串行 [英] PHP to serial with weird baud rates
问题描述
我正在尝试使用 PHP 向 LED 标牌发送文本,以便我可以向其发送支持票号.标志本身就是一件作品;它来自 eBay,制作精良,几乎没有任何文档.摆弄了一段时间后,我能够弄清楚它期望将东西发送给它的方式并且波特率为 28800.我已经知道如何使用 PHP 与这样的东西进行通信,但我不知道知道如何将波特率更改为非标准的东西.我尝试了其他波特率,但无法使其正常工作.
I am trying to use PHP to send text to an LED sign so I can send support ticket numbers to it. The sign itself is a piece of work; it came from eBay and is poorly made with almost no documentation. After fiddling with it for a while, I was able to figure out the way it expected stuff to be sent to it and that the baud rate is 28800. I already know how to communicate with stuff like this using PHP, but I don't know how to change the baud rate to something nonstandard. I've tried other baud rates, and haven't been able to get it to work.
推荐答案
您可能想查看 Linux 中的 setserial 命令 - 使用它,您可以分配串行端口以具有非标准速率.
You might want to look into the setserial command in Linux - with it, you can assign a serial port to have a non-standard rate.
如果您在连接初始化端口之前按如下方式运行 setserial,您应该能够将其关闭(在服务器初始化脚本中或在您的 PHP 中...虽然不确定这是否是一个好主意):
You should be able to pull it off if you run setserial as follows before connecting to initialize the port (either in the server init scripts or in your PHP...though not sure if that'd be a good idea):
/bin/setserial/dev/ttyS1 spd_cust baud_base 115200 除数 4
这是命令中发生的事情:
Here's what's going on in the command:
- spd_cust 选项告诉操作系统在应用程序请求 38400 时将速度设置为自定义除数.
- /dev/ttyS1 是串口.您可以将其更改为任何内容.
- baud_base 是除数 4 使用的数字
115200/4 = 28800 ...你需要的速度:-)
115200 / 4 = 28800 ...the speed you need :-)
在你的 PHP 代码中,你将在 38400 连接,这看起来很奇怪,但由于 setserial,你指定的端口将在 28800 运行
In your PHP code, you'll connect at 38400, which seems strange, but because of setserial, the port you specify will be running at 28800
这篇关于PHP以奇怪的波特率串行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!