title: Using read data from multiple serial ports within Main()
body: <p>I am quite new with C# programming and know very little about serial ports. I am following <a href="http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.datareceived.aspx" rel="nofollow">this method</a> provided by Microsoft to continuously read information entering multiple serial ports. Overall, my application is to bring data in from multiple COM ports and perform computational tasks on the resulting data.</p>
  
  <p>1) I want to use multiple serial ports. Unfortunately, I do not currently have enough USB-RS232 adapters to test multiple ports. I am not sure if creating a second DataReceivedHandler method is the correct way to do this. This is what I currently have:</p>
  
  <pre><code>// Receive data on COM Port A
  private static void DataReceivedHandlerA(object sender, SerialDataReceivedEventArgs e)
  {
      SerialPort sp = (SerialPort)sender;
      string inDataA = sp.ReadExisting();
  }
  
  // Receive data on COM Port B
  private static void DataReceivedHandlerB(object sender, SerialDataReceivedEventArgs e)
  {
      SerialPort spB = (SerialPort)sender;
      string inDataB = spB.ReadExisting();
  }
  </code></pre>
  
  <p>2) Using the received data from within the DataReceivedHandler method elsewhere in the Main() loop. Since the method is private, I am not able to use the inDataA within the Main() loop. Whenever I make this method public, it seems to fail. I want to be able to return the string inDataB. Is this possible, or is there another better way to do this.</p>