How we know with SerialPort class in c# when we receive all the data from the device connected on the serial port ?
There is my code. How i know i received all the data from the device ?
private void button1_Click(object sender, RoutedEventArgs e)
{
p = new SerialPort("COM5");
if (!p.IsOpen)
{
try
{
p.Open();
p.DataReceived += new SerialDataReceivedEventHandler(p_DataReceived);
p.PinChanged += new SerialPinChangedEventHandler(p_PinChanged);
Data = "Port ouvert";
}
catch (Exception ex)
{
Data = string.Format("Erreur ouverture du port : {0}", ex.Message);
}
}}
void p_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
var serial = (SerialPort)sender;
string line = serial.ReadExisting();
string data = string.Format("Donné recu : {0}",line);
Data = data;
strb.Append(line);
}