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.
A:
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.)
powtac
2010-06-08 13:28:53
I know about the serial class, but it won't let you use 28800 as the baud rate.
aloishis89
2010-06-08 13:32:15
+1
A:
For windows try
"mode " . $device . " BAUD=" . $baud
For linux try
"stty -F " . $device . " " . $baud
I think these are the correct commands to send
RobertPitt
2010-06-08 13:31:12
The PHP serial class is based on stty. The problem is that it throws an error when you try to specify a baud rate that isn't one of the standard speeds (2400, 4800, 9600, 14400, 19200, etc)
aloishis89
2010-06-08 13:37:10
Have you tried to modify the stty program to accept your baudrates, Take a look here, http://mhonarc.axis.se/dev-etrax/msg06754.html
RobertPitt
2010-06-08 13:44:13
aloishis89
2010-06-08 14:13:48
+1
A:
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
Mark B.
2010-06-08 20:37:17