read FROM com1

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


Im having trouble reading from COM1, writing works like a charm but Id
like to be able to read the output from a switch or a router in order to
determine that the command was succesful and the configuration actually
went fine :-)


$fp = fopen("COM1", "rwb");
fwrite($fp, $username . "\r\n");
if($response == 'password')

works, using hyperterminal shows that Im logged in and i can actually
config the device as I want, but if I try to do something like :

$fp = fopen("COM1", "rwb");
fwrite($fp, $username . "\r\n");
$response = fread($fp, 4096);
if($response == 'password')
   fwrite($fp, $password . "\r\n");
else {
   print "no response?";

this is where it ends. Anyone got an idea?

Kim Madsen

Re: read FROM com1

Kim Madsen - ComX wrote:
Quoted text here. Click to load it

The example from the manual on fgetc works when used as a wrapper:

$handle = fopen("COM1", "r");
while (!feof($handle)) {
    $buffer = fgets($handle, 4096);
    // do the stuff You wanna do
    echo $buffer;

When starting this script nothing happend, so I figured that the switch
might be locked somehow and I turned it off and on again, then all start
up info FROM the switch was shown on my screen...

Kim Madsen
Systemdeveloper / ComX -

Site Timeline