PHP to serial with weird baud rates

强颜欢笑 提交于 2019-12-05 16:05:19

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

For windows try

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

For linux try

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

I think these are the correct commands to send

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