Hello friends,
i have a code to read values from a serial port:
private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
if (Startint == true)
{
string DataIn = serialPort1.ReadExisting();
if (DataIn.Contains("Copyright"))
{
Console.Write(DataIn);
}
}
}
the string received from the port definitely contains the substring "Copyright" but for some reason the Linq contains is not working.
any ideas?
thank you.
Rijwan AnsariPosted Mar 16, 2022, 3:26 PM
Muhammad Imran AnsariPosted Mar 16, 2022, 2:26 PM
This is typical behavior for a serial port. They are very slow in nature. When the DataReceived event fires, you'd typically only get one or two characters.
Serial port required lots of time to receive additional characters or complete string.
You'll need some way to know that you've received the full response. Most typically serial devices will terminate the string with a special character, often a line-feed. Try the following code: