PHP Classes

phpSerial not "capturing" the serial modem

Recommend this page to a friend!

      PHP Serial  >  All threads  >  phpSerial not "capturing" the serial...  >  (Un) Subscribe thread alerts  
Subject:phpSerial not "capturing" the serial...
Summary:Terminal program needed to enable serial coms with phpSerial
Author:James Valentine
Date:2009-06-04 14:51:49
Update:2014-05-18 06:26:07

  1. phpSerial not "capturing" the serial...   Reply   Report abuse  
Picture of James Valentine James Valentine - 2009-06-04 14:51:49
Firstly, many thanks to the creator for implementing serial comms with a class in PHP. The concept suits my project very well.

I have a problem to which I'm sure there's a simple solution. Despite sending the same AT commands that my terminal program (minicom) does when it connects to the modem, phpSerial cannot talk to the modem unless the terminal program connects first.

I did not notice this initially, because I was monitoring the data exchange with minicom during the testing phase. When I stopped using minicom, my program stopped working, too.

I would be grateful of any advice. How can I get phpSerial to "capture" the port in the way that minicom does?

Many thanks,

  2. SOLVED Re: phpSerial not "capturing"...   Reply   Report abuse  
Picture of James Valentine James Valentine - 2009-06-04 16:17:41 - In reply to message 1 from James Valentine

Using stty -F to inspect the device (a GSM modem) with and without minicom running, it became clear that the configuration used is quite different.

Make sure to try/use a baud rate of 115200

Try adding the following to the class.

around line 381, in the flow control section, add the indicated line:


$linuxModes = array(
---this one---> "custom" => "ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke raw",
"none" => "clocal -crtscts -ixon -ixoff raw",
"rts/cts" => "-clocal crtscts -ixon -ixoff",
"xon/xoff" => "-clocal -crtscts ixon ixoff"


You might need to try different "custom" values from mine. As I said, take a look at the output of stty -F /dev/yourdevice and try to match it.

Then mend the error check/validation around line 392 to accommodate your changes, like this:

if ($mode !== "none" and $mode !== "rts/cts" and $mode !== "xon/xoff" and $mode !== 'custom') {

Try your script again: it should be configured like your working terminal program.

I hope this helps someone new to serial port control of a (GSM) modem

  3. Re: phpSerial not "capturing" the serial...   Reply   Report abuse  
Picture of Dave Coles-Dobay Dave Coles-Dobay - 2011-02-17 09:45:47 - In reply to message 2 from James Valentine
Many hours to find this fix but adding the post moserial stty -F .dev/ttyS0 arguments in a custom flow control mode did the trick.

For Noobs like me having problems with using this script after reboot...
1. Install and open Moserial it allows multibyte words instead of simple one character at a time on no flow control devices.
2. Use Moserial to get the serial port and the device attached talking.
3 while the device is still connected to Moserial open a shell and type stty -F /dev/ttyS0 or what ever serial port you are using.
4. Follow the instruction for adding a custom mode line to the script ignore any unconf bits but put in all the stuff preceded by the - sign.

Also for the hardware benders
Solder a diode cathode and a 2.2Kohm resistor to pin 2 on a DB9 connect pin 5 to the signal ground of the serial device you are scanning. Connect the diode anode and the other side of the resistor to the two serial pins to scan.
Try the settings in moserial until you can read the output.
Watch the two devices communicate back and forth until you can see the pattern of the communications.
Then you can easily write a script that tries a series of codes on a serial port and output the results to a text file.
This will allow you to find all sorts of undocumented features and capabilities of common products.
I now have a php driven robotic arm fully functional without documentation.

Again KUDOS and many thanks James

  4. Re: phpSerial not "capturing" the serial...   Reply   Report abuse  
Picture of Philipp Philipp - 2014-05-18 06:26:07 - In reply to message 3 from Dave Coles-Dobay
Thanks for your inspiration, James!

In my case, trying to talk to a telephone modem, "-clocal" (used in the php-serial library) seems to be the evil one. Because, the modem obviously keeps DCD=false as long as there is no connection (carrier on the line) yet.
So, using "clocal" (without the minus) solves that problem by ignoring the missing DCD signal.

I also saw people using the stty parameter "raw" which feels somehow appropriate to me, avoiding going into detail with lots of exotic settings, but I have not tested everything yet...