Sonnich Jensen
2016-01-08 15:59:13 UTC
Hi all
I have a small problem - I have a thread, which will scan comports for a specific item (by starting by the most obvious). My problem is that I rely on an answer from the device I am looking for.
However, I open a port, send a "ping", wait for "pong". But while my thread is in Thread.Sleep I dont get the receive event from the port, and thereby not any "pong" before I have been through all ports.
In Delphi I would have made an empty thread-class, which would synchronize to the search thread.
How do I make this work in C#?
foreach(port...)
{
open port
if in use then continue;
send ping
wait for pong (w/timeout)
if pong then break
}
In case you ask, I have a USB-COM adapater which will get any port name - so I go by the highest port, as it is most probably there. Replugged and I cannot be sure where it is.
I have a small problem - I have a thread, which will scan comports for a specific item (by starting by the most obvious). My problem is that I rely on an answer from the device I am looking for.
However, I open a port, send a "ping", wait for "pong". But while my thread is in Thread.Sleep I dont get the receive event from the port, and thereby not any "pong" before I have been through all ports.
In Delphi I would have made an empty thread-class, which would synchronize to the search thread.
How do I make this work in C#?
foreach(port...)
{
open port
if in use then continue;
send ping
wait for pong (w/timeout)
if pong then break
}
In case you ask, I have a USB-COM adapater which will get any port name - so I go by the highest port, as it is most probably there. Replugged and I cannot be sure where it is.