php-general Digest 26 Dec 2012 11:41:46 -0000 Issue 8076
Topics (messages 319948 through 319953):
Re: Serial Comm problem
319948 by: Ken Arck
319953 by: Matijn Woudt
Nested loopa
319949 by: Ken Arck
319950 by: Simon J Welsh
319951 by: Jim Giner
319952 by: Jim Lucas
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
At 11:36 AM 12/25/2012, you wrote:
The ^ is sent by the remove device with \r\n so I assumed telling
fgets to look for one character should be enough but apparently it isn't.
<---Sorry but the above is wrong.
The ^ is sent by the remove device WITHOUT \r\n
Ken
--- End Message ---
--- Begin Message ---
On Tue, Dec 25, 2012 at 8:36 PM, Ken Arck <ah...@ah6le.net> wrote:
> I'm pretty much a php newbie but have been programming for years in other
> languages
>
> Anyway...
>
> Using /dev/ttyS0. I need to set the serial port to 9600, send one command
> to an embedded processor board, then change the baud rate to 57600 and wait
> for a response. My code is working up to (and including) sending the
> command (and is being received correctly and acted on by the other device)
> but hangs up while waiting for the device to ACK back.
> ------------------------------**------------------------------**
> ---------------------
> //set ttyS0 speed to 9600 to send command
> exec('stty -F /dev/ttyS0 9600');
>
> // first open comport if it exists
> $fp = fopen ("/dev/ttyS0", "w+");
> if (!$fp) {
> die( "Uh-oh. Port not opened.");
> } else {
> }
>
> //send command
> $fw = fwrite($fp, "1*219999\r\n");
>
>
> //set ttyS0 speed to 57600 to for bootloader
> exec('stty -F /dev/ttyS0 57600');
>
> // wait for bootloader to send "^" (does not send CR or LF)
>
> echo "Waiting for Bootloader Active Character.....\n" ;
>
>
> // ********************************Were good to
> here***********************************
>
>
> Do {
> $InData = fgets($fp,1);
> }
> While ($InData != "^") ;
> ------------------------------**------------------------------**-
>
> I have also tried both While ($InData !=="^") ; and While ($InData <>
> "^") ; for the last line but it always hangs in this loop and times out
> after 30 seconds
>
> The ^ is sent by the remove device with \r\n so I assumed telling fgets to
> look for one character should be enough but apparently it isn't.
>
> Any help would be greatly appreciated
>
> Ken
>
You should probably use fgetc if you only need one character.
You could also try $InData = exec('head -c 1 /dev/ttyS0');
- Matijn
--- End Message ---
--- Begin Message ---
So I cannot do nested do loops in php?
<?php
$a = 0 ;
$b = 0 ;
do {
echo "$a\n" ;
do {
echo "$b\n" ;
$b++
}while($b <=10) ;
$a++;
}while($a <= 20) ;
?>
--- End Message ---
--- Begin Message ---
On 26/12/2012, at 1:21 PM, Ken Arck <ah...@ah6le.net> wrote:
> So I cannot do nested do loops in php?
>
> <?php
> $a = 0 ;
> $b = 0 ;
> do {
> echo "$a\n" ;
> do {
> echo "$b\n" ;
> $b++
> }while($b <=10) ;
> $a++;
> }while($a <= 20) ;
> ?>
You can, though you're never resetting the value of $b in the outer loop, so
the inner loop will only run once each time after the first run of the outer.
---
Simon Welsh
Admin of http://simon.geek.nz/
--- End Message ---
--- Begin Message ---
On 12/25/2012 7:21 PM, Ken Arck wrote:
So I cannot do nested do loops in php?
<?php
$a = 0 ;
$b = 0 ;
do {
echo "$a\n" ;
do {
echo "$b\n" ;
$b++
}while($b <=10) ;
$a++;
}while($a <= 20) ;
?>
Why do you say that?
--- End Message ---
--- Begin Message ---
On 12/25/2012 4:21 PM, Ken Arck wrote:
So I cannot do nested do loops in php?
<?php
$a = 0 ;
$b = 0 ;
do {
echo "$a\n" ;
do {
echo "$b\n" ;
$b++
}while($b <=10) ;
$a++;
}while($a <= 20) ;
?>
You have a typo. Line 8
What are you expecting as output?
--
Jim Lucas
--- End Message ---