Help with serial com

Using /dev/ttyS0. I need to set the serial port to 9600, send one command, 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.

[php]//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 = fgetc($fp);
// echo $InData ;
}
While ($InData != “^”) ;
[/php]

We need to wait for the remote device to send a carrot, which it does without a CR or LF. What is happening is my Do loop just hangs. What am I doing wrong?

Sponsor our Newsletter | Privacy Policy | Terms of Service