Hi,
I am in desparate need here. I need a timer method that will sit globally at form level and hold everything (except one com) to look for replys from a device. I have tried to use a Windows form timer (with out much success) and Thread.Sleep() but this has caused the grief I am in now where the device is replying but the timers I am using appear to either miss the reply's or they donot get back in time. I am suspecting it is the Timer that is missing events. But I'm not really sure. Is there a quick timer method that I can use for to the serial port replies and then process the data quickly!
Glenn

1 answers
Try using the <a target="_new" href="http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx">System.Timers.Timer</a> instead.
answered 2 years ago by:
17279
Hi Vulpes,
I have in the Form Load:
CallLoadDefaults();
BOX_Port_timerTimer = new System.Timers.Timer(500); //create a timer with a 1/2 second time
// Hook up the Elapsed event for the timer.
BOX_Port_timerTimer.Elapsed += new ElapsedEventHandler(OnBOX_PortElapsed);
// Set the Interval to 1/2 second (500 milliseconds).
BOX_Port_timerTimer.Interval = 500;
Also I have the events handler:
private static void OnBOX_PortElapsed(object source, ElapsedEventArgs e)
{
//Form1.ActiveForm
}
my intention which has failed at the moment is to use this timer once the serial port is open to catch everything that is sent back
so I'm guessing.....
if(MyComPort.IsOpen())
{
//stuff
}
at the moment using Windows Stop Whatch (Timers) I have
if (!(myComPort.IsOpen))
{
tmrBoxError.Enabled = true;
myComPort.Open();
btnOpen.Text = "C&lose";
btnClose.Enabled = false;
rtbOutgoing.Focus();
tmrPollForRecievedData.Enabled = true;
tmrTF930.Enabled = true;
Write_Out_Data();
myComPort.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
Check_Instruments();
rbProgramBoardYes.Visible = true;
rbProgramNo.Visible = true;
Thread.Sleep(100);
tmrErrorCheck.Enabled = true;
..................................
tmrErrorCheck amongst other things:
foreach (string Reply in Contents.Split(new char[] { '\r','\n' }))
{
CompareToValue = Convert.ToString(Reply.CompareTo(">E"));
if (CompareToValue == "0")
Error = true;
label13.Text = label13.Text + ".";
}
Reply is the return string from a piece of equipment.
This timer does not work, but I think You can get my intention from it.
Sorry Glenn
answered 2 years ago by:
329
This post was imported from csharpfriends, if you have a similiar question please ask it again.
All previous members have been migrated, hope you enjoy the new platform!