PHP to serial with weird baud rates

点点圈 提交于 2020-01-02 05:41:12

问题


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.


回答1:


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:

  • The spd_cust option tells the OS to set the speed to a custom divisor when the application requests 38400.
  • /dev/ttyS1 is the serial port. You'll change this to whatever.
  • The baud_base is the number to be used by the divisor 4

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




回答2:


For windows try

"mode " . $device . " BAUD=" . $baud

For linux try

"stty -F " . $device . " " . $baud

I think these are the correct commands to send




回答3:


Check out these two links

  • http://www.communitymx.com/content/article.cfm?cid=8658A
  • http://www.phpclasses.org/package/3679-PHP-Communicate-with-a-serial-port.html (Can send data to the "COM1" for windows and so on.)


来源:https://stackoverflow.com/questions/2997642/php-to-serial-with-weird-baud-rates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!