title: C# SerialPort DSR/DTR and CTS/RTS handshaking
body: <p>I am trying to communicate with a device using C#/.NET's <code>SerialPort</code> class.</p>
  
  <p>The documentation for interacting with the device is described here.</p>
  
  <hr>
  
  <p><img src="https://i.stack.imgur.com/3n0rZ.jpg" alt="RS232 documentation"></p>
  
  <hr>
  
  <p>I am using a NULL modem cable with the TX/RX and all the handshake pins swapped (verified).</p>
  
  <p>I would expect the following C# code to work, but I am not getting any response back (low to high) from the camera I am trying to interact with. I am sure the problem is with the code though. This camera works with other "PCs". Why would I never get <code>DsrHolding</code> (null modem cable, so DTR high from camera) to become true within my code?</p>
  
  <pre><code>static void Main(string[] args)
  {
      var serialPort = new SerialPort("COM5");
  
      // start the DSR/DTR handshake
      // we are using a null modem cable, so DTR/DSR is switched
      serialPort.DtrEnable = true;
      while (!serialPort.DsrHolding)
      {
          // probally should timeout instead of infinite wait
          Thread.Sleep(10);
          Console.WriteLine("Waiting for the DTR line to go high.");
      }
  
  
      // start the RTS/CTS handshake
      // we are using a null modem cable, so RTS/CTS is switched
      serialPort.RtsEnable = true;
      while (!serialPort.CtsHolding)
      {
          // probally should timeout instead of infinite wait
          Thread.Sleep(10);
          Console.WriteLine("Waiting for the RTS line to go high.");
      }
  
      // read/write
      //serialPort.Write("Some command");
      //var response = serialPort.ReadChar();
      //while (response != stopBit)
      //    response = serialPort.ReadChar();
  
      // close the connection because we have written/read our data
  
      // start the DSR/DTR handshake
      // we are using a null modem cable, so DTR/DSR is switched
      serialPort.DtrEnable = false;
      while (serialPort.DsrHolding)
      {
          // probally should timeout instead of infinite wait
          Thread.Sleep(10);
          Console.WriteLine("Waiting for the DTR line to go low.");
      }
  
  
      // start the RTS/CTS handshake
      // we are using a null modem cable, so RTS/CTS is switched
      serialPort.RtsEnable = false;
      while (serialPort.CtsHolding)
      {
          // probally should timeout instead of infinite wait
          Thread.Sleep(10);
          Console.WriteLine("Waiting for the RTS line to go low.");
      }
  }
  </code></pre>