I have a device in which if I send a properly formatted string; I get a string back. I would like to use this returned string in a WPF ListView control but I'm having trouble infinitely querying the device on the other end of the serial port. I would like to refresh the data every 3 or so seconds.
Here is the application logic:
public static void queryDevice()
{
SerialPort _serialPort = new SerialPort("COM3", 115200, Parity.None, 8, StopBits.One);
_serialPort.Handshake = Handshake.None;
ObservableCollection<string> store= new ObservableCollection<string> { " ", " ", " " };
string[] query = new string[3] { "t02", "t03", "t04" };
while (true)
{
for (int i = 0; i < 3; i++)
{
string add = SerialCom.returnData(query[i], _serialPort);//returns data depending on which query was sent
if (store[i] != add)
{
store.Add(add);
}
}
Thread.wait(300);
}
}
I'm trying to find the best way to thread this code as putting this code in the UI thread locks the UI thread up. I am planning to use the ObservableCollection as the datasource for the ListView on that note.
Thanks!