Go Down

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

effinrobots

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???
Thanks

kuuk

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

kuuk

#2
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"));
                 }
                 else
                 {
                       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"));
           }
           else
           {
                 trigger_error("Host OS is neither linux nor windows, unable tu run.", E_USER_ERROR);
                 exit();
           }
     }


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.

John_Ryan

#3
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 :)

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1185507207/51#51

OSX is "DARWIN" btw

effinrobots

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.

macmaniac

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!

gnu_linux

Ditch PHP and use Perl  ;D

Code: [Select]

#!/usr/bin/perl

use Device::SerialPort;

my $port = Device::SerialPort->new("/dev/ttyUSB0");
$port->databits(8);
$port->baudrate(9600);
$port->parity("none");
$port->stopbits(1);

my $var="testing...";

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

dcb

isn't perl considered self-obfuscating?  ;D


gnu_linux

lol  ;D

Seriously though Perl would be a good choice :)

Larzac

Hello,
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.

macmaniac

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

adalgisio

macmaniac

the code was correct

Code: [Select]

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

alx5962

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

ReCreate

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

ace5342

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.

http://realterm.sourceforge.net/

hope this helps  :)


Go Up