c# Serialport problem: data are send in "clumps"
<p>I am trying to remote control a lego mindstorms NXT robot using a bluetooth serial connection. The program connects without any problem but when i send single commands they do not appear before several other commands has been send. Then they all appear at once on the nxt. </p>

<p>I have tried everything (i can think of or google has told me to) but i cannot seam to get the buffer to flush after a command is send. </p>

<p>Anyone having a idea about what i can do?
Here is my code</p>

<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;

namespace NXTBtRemote
 {
  public class BTHandler
  {
    SerialPort comm;
    private string comPort;
    public BTHandler()
    {
        comm = new SerialPort(); 
    }

    public Boolean Connect(string _comPort)
    {
        this.comPort = _comPort;
        comm.PortName = comPort;
        comm.Open();

        if (comm.IsOpen) return true;
        else return false; 
    }

    public void sendCommand(Command command)
    {
        string msg = command.cmdType + "#" + command.arguments;
        if (!comm.IsOpen) comm.Open();
        comm.WriteLine(msg);
        comm.DiscardOutBuffer();
    }
}
}
</code></pre>

<p>Hope somone can help. Thanks in advance
kind regards - kenneth</p>
