title: Can't send via serial communication, but can receive
body: <p>The situation is I have a Honeywell N5683 barcode scanner and I am unable to send it commands in any serial communication program outside of the Honeywell EZConfig Scanning software. </p>
  
  <p>Please note the scanner has many different configuration settings it can accept. See here: <a href="https://www.honeywellaidc.com/CatalogDocuments/N56XX-UG%20Rev%20C.pdf" rel="nofollow noreferrer">https://www.honeywellaidc.com/CatalogDocuments/N56XX-UG%20Rev%20C.pdf</a></p>
  
  <p>The goal of this program is to send a software trigger instead of having to manually press the scan button. The program I have written so far is able to receive the data when the physical button is pressed, but is unable to currently send data via the <code>SerialPort</code> class in .NET. Please see code below:</p>
  
  <pre><code>public partial class Form1 : Form
  {
      private SerialPort serialPort1 = new SerialPort("COM3", 115200, Parity.None, 8, StopBits.One);
  
      public Form1()
      {
          InitializeComponent();
          serialPort1.DataReceived += new SerialDataReceivedEventHandler(scannerDataReceivedHandler);
      }
  
      private void Form1_Load(object sender, EventArgs e)
      {
          // COM Settings
          serialPort1.RtsEnable = true;
          serialPort1.DtrEnable = false;
  
          if (serialPort1.IsOpen)
              serialPort1.Close();
          serialPort1.Open();
      }
  
      private void scannerDataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
      {
          Console.WriteLine("Scan Successful");
          SerialPort sp = (SerialPort)sender;
          Thread.Sleep(50);
          int bytes = sp.BytesToRead;
          byte[] buffer = new byte[bytes];
          sp.Read(buffer, 0, bytes);
          string bufferOutput;
          bufferOutput = ByteArrayToHexString(buffer);
  
          Console.WriteLine(bufferOutput);
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          // on
          //this is the string I send with the Honeywell Program = "PAPTPR";
  
          string toSend = "50 41 50 54 50 52";
  
          try
          {
              byte[] data = HexStringToByteArray(toSend);
  
              if (!serialPort1.IsOpen)
              {
                  serialPort1.Open();
              }
  
              serialPort1.Write(data, 0, data.Length);
          }
          catch (System.IO.IOException)
          {
          }
      }
  
      // UTILITY
      private byte[] HexStringToByteArray(string s)
      {
          s = s.Replace(" ", "");
          byte[] buffer = new byte[s.Length / 2];
          for (int i = 0; i &lt; s.Length; i += 2)
              buffer[i / 2] = (byte)Convert.ToByte(s.Substring(i, 2), 16);
          return buffer;
      }
  
      private string ByteArrayToHexString(byte[] data)
      {
          StringBuilder sb = new StringBuilder(data.Length * 3);
          foreach (byte b in data)
              sb.Append(Convert.ToString(b, 16).PadLeft(2, '0').PadRight(3, ' '));
          return sb.ToString().ToUpper();
      }
  }
  </code></pre>
  
  <p>Here is a screenshot of a successful command sent to the Honeywell N5683 in the Honeywell EZConfig application: 
  <img src="https://i.stack.imgur.com/6ngkC.png" alt="enter image description here"></p>