title: reading from a serial port - Question marks appearing instead of values
body: <p>I'm currently converting an old vbs application to a c# application so I can provide more functionality.  The purpose of this application is to scan an identity card and take the id from it.  I can then use this to import the data into a door access system via a CSV file.</p>
  
  <p>Now here is my problem.  When I use the vb application to scan a card via the COM port it has a value of:</p>
  
  <p>3E8783D0</p>
  
  <p>I can see this works correctly.  However when I come to use my new program in c# and scan the barcode I get the following output:</p>
  
  <p>2??E878????</p>
  
  <p>So I can see that the card is scanning.  But part of the code is filled in with question marks.</p>
  
  <p>I have looked into altering the baud rate etc and this is the closest I can come to meaningful data.  The settings for the COM port are the same as the old VB program so I wouldn't have thought this shouldn't be a problem?</p>
  
  <p>The coding I have used is shown below.  Can someone help to explain why the question marks are appearing?  Have I missed something obvious?  The form I am using is laid out with a text button and a start / stop button to prepare the device for input from the proximity sensor.</p>
  
  <pre><code>    public Form1()
      {
          InitializeComponent();
      }
  
      private void buttonStart_Click(object sender, EventArgs e)
      {
          serialPort1.PortName = "COM1";
          serialPort1.BaudRate = 4800;
          serialPort1.Parity = System.IO.Ports.Parity.None;
          serialPort1.DtrEnable = true;
          serialPort1.RtsEnable = false;
          serialPort1.ReadTimeout = 500;
          serialPort1.WriteTimeout = 500;
          serialPort1.Open();
          if (serialPort1.IsOpen)
          {
              buttonStart.Enabled = false;
              buttonStop.Enabled = true;
              textBox1.ReadOnly = false;
          }
      }
  
      private void buttonStop_Click(object sender, EventArgs e)
      {
          if (serialPort1.IsOpen)
          {
              serialPort1.Close();
              buttonStart.Enabled = true;
              buttonStop.Enabled = false;
              textBox1.ReadOnly = true;
          }
      }
  
      private void Form1_FormClosing(object sender, FormClosingEventArgs e)
      {
          if (serialPort1.IsOpen) serialPort1.Close();
      }
  
      private void DisplayText(object sender, EventArgs e)
      {
          textBox1.AppendText("!");
          textBox1.AppendText(RxString);
      }
  
      private string ExtractPACID(string s)
      {
          return s.ToString() + "";
      }
  
      private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
      {
          RxString = serialPort1.ReadExisting();
          this.Invoke(new EventHandler(DisplayText));
      }
  </code></pre>