0

I have a serial console session and I need to answer specific questions from the device. If I enter the command "setup" the device will start a setup wizard, which will ask me some questions. I want to automate this setup as much as possible to autofill the values/answers to the regarding questions.

These questions are regarding to the operating system version always a bit different - also the order of the questions. A regex may help here.

What is the best way to send datas to the serial connected device and read the output of it? I have tried to solve this with the following script, but it is under a Windows webserver not able to read the console log:

    <!DOCTYPE html>
    <html>
        <header>
            <meta charset="utf8">
        </header>
    <body>
    <?php

    //-- settings --//

    //brainboxes serial ports
    //on 'nix start with cu.usbserial-
    //on windows starts with com : must be lower case in windows and end with a colon
    $portName = 'COM35';
    $baudRate = 9600;
    $bits = 8;
    $spotBit = 1;

    ?>
    Serial Port Test<br>
    ================<br>
    <br>
    <?php


    function echoFlush($string)
    {
        echo $string . "\n";
        flush();
        ob_flush();
    }

    if(!extension_loaded('dio'))
    {
        echoFlush( "PHP Direct IO does not appear to be installed for more info see: http://www.php.net/manual/en/book.dio.php" );
        exit;
    }

    try 
    {
        //the serial port resource
        $bbSerialPort;

        echoFlush(  "Connecting to serial port: {$portName}<br><br>" );

        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') 
        { 
            $bbSerialPort = dio_open('\\\\.\COM35', O_RDWR);
            //we're on windows configure com port from command line
            exec("mode {$portName} baud={$baudRate} data={$bits} stop={$spotBit} parity=n xon=on");
        } 
        else //'nix
        {
            $bbSerialPort = dio_open('\\\\.\COM35', O_RDWR | O_NOCTTY | O_NONBLOCK );
            dio_fcntl($bbSerialPort, F_SETFL, O_SYNC);
            //we're on 'nix configure com from php direct io function
            dio_tcsetattr($bbSerialPort, array(
                'baud' => $baudRate,
                'bits' => $bits,
                'stop'  => $spotBit,
                'parity' => 0
            ));
        }

        if(!$bbSerialPort)
        {
            echoFlush( "Could not open Serial port {$portName}<br><br>");
            exit;
        }

        // send data

        $dataToSend = "version\n";
        echoFlush( "Writing to serial port data: \"{$dataToSend}\"<br>" );
        if($bytesSent = dio_write($bbSerialPort, $dataToSend )) {
            echoFlush( "Sent: {$bytesSent} bytes<br><br>" );

            echoFlush(  "Closing Port" );

            dio_close($bbSerialPort);
        }
    }
    ?>
    </body>
    </html>

I hope somebody can help me.

NOTE: The device is a NetApp FAS-Head.

checker284
  • 1,286
  • 3
  • 14
  • 29

1 Answers1

0

Do you have documentation for the device? You should check to see what settings it requires. You need to verify that you have the correct values for: port name, baud rate, parity bit, data bits, and stop bit when you open instantiate the object and that the handshake, newLine, RtsEnable, DtrEnable and Encoding properties are are set correctly before you can communicate. Many of these arguments and properties have default values which work most of the time but your device may require settings the are different from the defaults. In particular, the Handshake property must be set to the right value or you will not be able to communicate. If your device uses hardware handshake you will have a number of items to verify before it will work.

skinnedknuckles
  • 371
  • 3
  • 12
  • Data Ontap uses FreeBSD. The default settings of Putty are the correct ones for communicating with the device. – checker284 Sep 14 '14 at 12:57