1

我正在使用http://www.activeexperts.com/serial-port-component/ API 与 PHP 中的 RS-232 设备进行通信。

它的 WriteByte() 函数工作正常,但 ReadByte() 不显示 NULL (0x00) 十六进制值。例如-> WriteByte(0);

输出什么都不是(甚至不是字符)

请帮我弄清楚为什么它不显示 NULL 值。

<?php
  $objComport = new COM("AxSerial.ComPort");

  // Good practise: Clear
  $objComport->Clear();

  $objComport->LogFile = "C:\AxSerial.ComPort.log";
  // Windows default: 'C:\Windows\Temp\AxSerial.ComPort.log'

  //Form submitted
  if (isset($_POST["btnSendCommand"]))
  {  
    $objComport->Device = $_POST['cbDevice'];
    $objComport->Baudrate = $_POST['cbBaudrate'];

    $objComport->Open();

    if ($objComport->LastError == 0)
    {

      // Set all Read functions (e.g. ReadString) to timeout after a specified number of millisconds
      $objComport->ComTimeout = 2000;  // Timeout after 1000msecs 

      $objComport->WriteBytes($_POST['txtCommand']);

      $str = ""; 

      Do
      {
          $str = $objComport->ReadByte();    // < THIS FUNCTION NOT DISPLAYING NULL VALUE
            echo $str.'<br>';
        if ($objComport->LastError == 0)
          $strResponse = $strResponse .$str;
      }
      While ($str != "");    

    }    


    $strResult = $objComport->LastError . ': ' . $objComport->GetErrorDescription($objComport->LastError);

    $objComport->Close();
  }

?>

这是 HTML 表格:

<form action="index.php" method="post">
        <h2>Component:</h2>
        <h3>Module: [<?php echo $objComport->Module; ?>]; Build: [<?php echo $objComport->Build; ?>]</h3>

        <!-- Command -->
        <label for="command">Command:</label>
        <p>
          <input type="text" id="command" name="txtCommand" value="ATI0" />
        </p>

        <!-- Com port -->
        <label for="Device">Device:</label>
        <p>
          <select id="Device" name="cbDevice">
            <option value="COM1">Com1</option>
            <option value="COM2">Com2</option>
            <option value="COM3">Com3</option>
            <option value="COM4">Com4</option>
            <option value="COM5">Com5</option>
            <option value="COM6">Com6</option>
            <option value="COM7">Com7</option>
            <option value="COM8">Com8</option>
            <option value="COM11" selected="selected">Com11</option>                                                                                                                                                                                                                                                                                                                                                                                                                                
          </select>
        </p>

        <!-- Baudrate -->
        <label for="baudrate">Baudrate:</label>
        <p>
          <select id="baudrate" name="cbBaudrate">
            <option value="0">Default</option>
            <option value="110">110</option>
            <option value="300">300</option>
            <option value="600">600</option>

            <option value="1200">1200</option>
            <option value="2400">2400</option>
            <option value="4800">4800</option>
            <option value="9600" selected="selected">9600</option>

            <option value="14400">14400</option>
            <option value="19200">19200</option>
            <option value="38400">38400</option>
            <option value="57600">57600</option>

            <option value="64000">64000</option>
            <option value="115200">115200</option>
            <option value="128000">128000</option>
            <option value="256000">256000</option>                                                    
          </select>
        </p>

        <!-- Empty row -->
        <div class="clearRow"></div>

        <!-- List Messages button -->
        <div class="clearLabel"></div>
        <p>
          <input type="submit" name="btnSendCommand" value="Submit Command" />
        </p>  

        <!-- Result -->
        <label for="Result" class="Bold">Result:</label>
        <p>
          <input type="text" id="Result" name="txtResult" class="FullWidth Bold" value="<?php echo $strResult; ?>" />
        </p>

        <!-- Response -->
        <label for="Response">Response:</label>
        <p>
          <textarea id="Response" name="txtResponse" style="height:100px; overflow:auto;" class="FullWidth" ><?php echo $strResponse; ?></textarea>
        </p>
      </form>
4

0 回答 0