SV: Read From COM1 port

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Richard Lynch [mailto:ceo@xxxxxxxxx] 
Sent: 3. march 2005 20:56

>> $fp = fopen("COM1", "rwb");
> You might try this:
> $input = fopen("COM1", "rb");
> $output = fopen("COM1", "wb");
> Use $output to write, and $input to read.

On a windows one would have to close the connection every time then since that OS only allow _one_ connection to the serial ports.

> Another possibility would be to check the manual...

I´ve been it around, as I wrote in the first mail, but something must have been misspelled by me, cause I took the example from fgetc:

$fp = fopen("COM1", "w+b");
while (false !== ($char = fgetc($fp))) {
  echo ".$char";
}

And nothing happened, so I figured that the switch might me locked somehow, I turned it off and on again and suddenly all the start up info from the switch was shown on my screen. I now use the example as a wrapper:

// open connection
$fp = fopen("COM1", "w+b");

// listen for output from $fp
while (false !== ($char = fgetc($fp))) {
  // save chars in buffer, if NOT returns or newlines
  if($char != "\r" && $char != "\n") {
    $buffer .= $char;

  // We need to know if things went wrong
  if(trim($buffer) == "Error")
    $response[] = "Error";

  // execute commands
  if(trim($buffer) == "SecOff >") {
    $command = "$Sec[$SecOff]\r\n";
    fwrite($fp, $command);
    print "writing: $command\n";
    $SecOff++;
    $buffer = "";
  }		
}

I´m working on it as we speak, this is just a part of the script. It´s so nice to have a break through finally :-)

> I don't thing 'rwb' is the correct way to fopen for read/write access.

> 'wb+' would be a better answer, I think.

I know, that´s how I´ve done it. During try&fail tests I´ve tried like everything. My mistake to not check the code properly before mailing it here...

Have a nice weekend out there :o)

-- 
Sincerly
Kim Madsen
Systemdeveloper / ComX - http://www.comx.dk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux