title: How to detect if thermal printer has been disconnected from com port?
body: <p>I'm trying to print with a thermal printer which uses a com port. And I would like to detect whether the printer is connected or not.  </p>
  
  <p>I was assuming that if I try to run the codes which tries to print without connecting the printer, I would get some kind of error. So I used try-catch block. The following is what I have tried so far. </p>
  
  <pre><code>using System.IO.Ports;
  
  private readonly SerialPort _printer = new SerialPort(Port, BaudRate, Parity, DataBits, Stopbits);
  
  private void Print(string text)
          {            
              try
              {
                  if (!_printer.IsOpen)
                      _printer.Open();               
  
                  _printer.WriteLine(text);
  
                  _printer.Close();
              }
              catch (Exception ex)
              {
                  Logging.Log("PRINT ERROR: " + ex.Message);
              }            
          }
  </code></pre>
  
  <p>In most cases, if you try to print programmatically with the printer being disconnected, the code block which tries to print will throw error. </p>
  
  <p>But in this case, the codes were executed as if the printer was connected and no errors were thrown.</p>
  
  <p>I have also tried <code>SerialPort.ErrorReceived</code> event but it didn't work either.</p>
  
  <p>So, I was wondering if there's a way to detect the status of the printer (whether it was connected or disconnected). Thanks for the help.</p>