read FROM com1

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kim Madsen - ComX

    #1

    read FROM com1

    Hi

    I´m having trouble reading from COM1, writing works like a charm but I´d
    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 :-)

    doin´:

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

    works, using hyperterminal shows that I´m 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?";
    exit;
    }

    this is where it ends. Anyone got an idea?

    Sincerly
    Kim Madsen
  • Kim Madsen - ComX

    #2
    Re: read FROM com1

    Kim Madsen - ComX wrote:[color=blue]
    > Hi
    >
    > I´m having trouble reading from COM1, writing works like a charm but I´d
    > 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 :-)[/color]

    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;
    }
    fclose($handle) ;

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

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

    Comment

    Working...