title: C#, How can I read/write commands to a Linux SBC(BeagleBone) through a serial port in a certain order?
body: <p>I'm trying to write a command to a BeagleBone over serial port and then read that output but for some reasons it doesn't seem to work. Here is my code:</p>
  
  <pre><code>SerialPort port = new SerialPort("COM1", 115200, Parity.None, 8, StopBits.One);
  
              port.ReadTimeout = 500;
              port.WriteTimeout = 500;
  
  
              port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
  
              port.Open();
  
              port.WriteLine("debian\r\n"); //default login username
              port.WriteLine("temppwd\r\n");//default login password
  
  
              void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
              {
  
                      string message = port.ReadExisting();
                      System.Diagnostics.Debug.WriteLine(message);
  
  
              }
  </code></pre>
  
  <p>For example, <code>port.WriteLine("debian\r\n")</code> seems to correctly work but right after that <code>port.WriteLine("temppwd\r\n")</code> doesn't seem to work. I am expecting to see<code>debian@beaglebone:~$:</code> printed out in the debug console but after <code>port.WriteLine("debian\r\n")</code> all that is printed out is blank space. Is this because I need to wait for the first command to execute before the second? To my knowledge I thought the <code>SerialDataReceivedEventHandler</code> took care of that. Thanks, any help will be greatly appreciated.</p>
  
  <p><strong>EDIT</strong>: Just to clarify, I am able to establish a connection to the SBC because in the debug console the default text at login is printed out.</p>