Может кто-нибудь сказать мне, почему код ниже будет отсутствовать или отбрасывать данные. Я гуглил всю ночь, но не могу найти никаких указателей. последовательный порт использует следующие настройки; 38400, n, 8,1 xon / xoff flow control. ReceivedBytesThreshold = 1.
isReceiving и stockReceived оба являются членами формы
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
string dataReceived = serialPort1.ReadExisting();
bytecount += dataReceived.Length;
processSerialData(dataReceived);
}
private void processSerialData(string dataReceived)
{
if (isReceiving == false)
{
int stxpos = dataReceived.IndexOf('\x02');
if (stxpos != -1)
{
dataReceived = dataReceived.Replace("\x02", "");
labelcaption = "Receiving... ";
this.Invoke(new EventHandler(SetLabel));
isReceiving = true;
}
}
int etxpos = dataReceived.IndexOf('\x03');
if (etxpos != -1)
{
dataReceived = dataReceived.Replace("\x03", "");
//tmpFile.Write(dataReceived);
writeToFile(dataReceived);
tmpFile.Close();
isReceiving = false;
stockReceived = true;
}
// Now we need to write the data to file
if (isReceiving == true)
{
if ((bytecount / recordSize) % 100 == 0)
{
labelcaption = "Receiving... " + (bytecount / recordSize);
this.Invoke(new EventHandler(SetLabel));
}
//tmpFile.Write(dataReceived);
writeToFile(dataReceived);
}
}