PHP 以奇怪的波特率进行串口
我正在尝试使用 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能想研究一下 Linux 中的 setserial 命令 - 使用它,您可以分配串行端口以具有非标准速率。
方式运行setserial,您应该能够完成它(无论是在服务器初始化脚本中还是在您的PHP中......尽管不确定这是否是一个好主意):
如果您在连接初始化端口之前按如下 /bin/setserial /dev/ttyS1 spd_cust baud_base 115200 divisor 4
以下是命令中发生的情况:
115200 / 4 = 28800 ...您需要的速度:-)
在您的 PHP 代码中,您将在 38400 连接,这看起来很奇怪,但由于setserial,端口您指定将在 28800 运行
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.
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 divisor 4
Here's what's going on in the command:
115200 / 4 = 28800 ...the speed you need :-)
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
对于 Windows,请尝试
"mode " 。 $设备。 “波特=”。 $baud
对于 Linux,请尝试
"stty -F " 。 $设备。 ” “。 $baud
我认为这些是发送的正确命令
For windows try
"mode " . $device . " BAUD=" . $baud
For linux try
"stty -F " . $device . " " . $baud
I think these are the correct commands to send
查看这两个链接
Check out these two links