Go Down

Topic: php Serial Class (Read 13234 times) previous topic - next topic


Hey all,
I've been trying my hardest to get the php_serial.class to work with my arduino by opening a serial port to send some data. I've run into a problem though, and I have no idea what to do. Seems that every time it calls the fopen() function the program just freezes. No output/ errors/ etc... just frozen. I've been running the script via OS X terminal and its connected to a Diecimila board. I've also tried doing the same task in Python, which works flawlessly...
This is driving me nuts.. Any ideas on why the fopen() call is freezing???


i've not worked yet with php_serial, but maybe it's just a user rights issue? how do you run your PHP in the terminal? you could also check the console for error messages.

best, kuk


Apr 17, 2008, 09:27 pm Last Edit: Apr 17, 2008, 09:35 pm by leKuk Reason: 1
oooooh look what i've found in php_serial.class.php:
Code: [Select]

function phpSerial ()
           setlocale(LC_ALL, "en_US");

           $sysname = php_uname();

           if (substr($sysname, 0, 5) === "Linux")
                 $this->_os = "linux";

                 if($this->_exec("stty --version") === 0)
                       register_shutdown_function(array($this, "deviceClose"));
                       trigger_error("No stty availible, unable to run.", E_USER_ERROR);
           elseif(substr($sysname, 0, 7) === "Windows")
                 $this->_os = "windows";
                 register_shutdown_function(array($this, "deviceClose"));
                 trigger_error("Host OS is neither linux nor windows, unable tu run.", E_USER_ERROR);

still doesn't explain why you get no error on OS X but, if we're talking about the same php class...

PS: i'm not very sure what these lines do except that they quit the script on an operating system which is not linux or windows... maybe just take out the ifs and try the linux code on OS X ... but that's just a shot in the dark, and you might be better off finding someone who documented doing this on a mac.


Apr 17, 2008, 10:45 pm Last Edit: Apr 17, 2008, 10:46 pm by John_Ryan Reason: 1
Here - I've included the mac version as well :)


OSX is "DARWIN" btw


Hey, sorry for not specifying, but the OSX compatible version of the class is the one I've been trying to work with, so I don't think that's the problem.
Like I said, I've tried calling the same fopen() function that the serial class calls in its deviceOpen() routine and that definitely seems to be where the program is failing....  just can't figure out why.

The help is appreciated though!
Thanks again.


There's a mistake in the 'php_serial.class.php' file above - on line 111, it says:
Code: [Select]
if ($this->_exec("stty -f " . $device) === 0)
you need to change the '===' so it is:
Code: [Select]
if ($this->_exec("stty -f " . $device) !== 0)
Hope that helps any of you!


Ditch PHP and use Perl  ;D

Code: [Select]


use Device::SerialPort;

my $port = Device::SerialPort->new("/dev/ttyUSB0");

my $var="testing...";

my $return=$port->write("$var");


isn't perl considered self-obfuscating?  ;D


lol  ;D

Seriously though Perl would be a good choice :)


After checking that I run the upgraded version I am unable to read/write to rs232 port with php_serial. Is there something to do before running? with stty I can read rs232 parameters or change thems, all seems correct but no change if I try to modify thems with the soft!
Happy new year to all the menbers.


Are you using the mac version (posted above)? I assume you're suing a PC (RS232 port), so you don't need to, and that may be why it's not working. Just use the php_serial class on phpclasses - http://www.phpclasses.org/browse/package/3679.html



the code was correct

Code: [Select]

if ($this->_exec("stty -F " . $device) === 0)


I spent a long time trying to make my Arduino to work on Windows with PHP !
The PHP serial class worked fine on my WDTV (yep I connected my Arduino to it!) which is running in linux. But The same code did nothing on Windows.
The way phpserial class is setting the "mode.com" command is a mess and doesn't configure the com port correctly at the end.
The bay way to configure the com port is to use :
Code: [Select]
MODE COM3:9600,N,8,1,P


Actually...PHP is much better, From my experience...


Hi all don't know if this is any good to you but i have had the same problem tho found a solution using other software that will save to and send a text file automatically then edit in PHP seams to work tho not as direct as i would like.


hope this helps  :)

Go Up