Dear All,
Data comes to my serial port every 6 seconds.
My application is capturing the data @ 1 data/6 seconds initially, properly and converting it into graphs.
But as the time proceeds the capture rate becomes @ 2 data/12 seconds and again after some time @3 data/18 seconds.
At the end of 10 hours its around @ 50-60 data/6 minutes ... and keeps increasing.

MY QUESTION IS : WHY DOES THE TIME INTERVAL KEEPS ON INCREASING AND WHAT CAN BE DONE TO KEEP TIME INTERVAL AT 6 SECONDS?

Please note that no data is lost even though the application comes to a stand-still for 6 minutes.
I have searched various forums for many days without any success.
I am attaching the code and properties settings.


private void Import_Data_Button_Click(object sender, EventArgs e)
{

if (LiveMenu.Checked)
{
LiveMenu.Checked = false;
Live = false;
SPTimer.Enabled = false;

try
{
if (SP.IsOpen) { SP.Close(); }
}
catch { }
}
else
{
{
LiveMenu.Checked = true;
Live = true;
SPTimer.Enabled = true;

try
{
if (!SP.IsOpen) { SP.Open(); }
}
catch { }
DrawGraphs();
}

}


private void SP_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
try
{
Serial_Data += SP.ReadLine();
}
catch { }
}

private void SPTimer_Tick(object sender, EventArgs e)
{
SPTimer.Enabled = false;
if (lblLive.Visible == false) { lblLive.Visible = true; }
else { lblLive.Visible = false; }

if (Serial_Data.Contains("\r"))
{
WriteToDatabase(Serial_Data);
Serial_Data = "";
}

SPTimer.Enabled = true;
}

Any suggestions will be of great help to me.

Thanks!!!
Rupali

Recommended Answers

All 3 Replies

Have you verified that the SPTimer_Tick is firing at a constant rate? Have you checked if there is something in Serial_Data each time it fires but that there is no '\r' character in it?

This might also be the problem (from the documentation):
The DataReceived event is not guaranteed to be raised for every byte received. Use the BytesToRead property to determine how much data is left to be read in the buffer.

Serial port properties attached

dear all,
data comes to my serial port every 6 seconds.
My application is capturing the data @ 1 data/6 seconds initially, properly and converting it into graphs.
But as the time proceeds the capture rate becomes @ 2 data/12 seconds and again after some time @3 data/18 seconds.
At the end of 10 hours its around @ 50-60 data/6 minutes ... And keeps increasing.

My question is : Why does the time interval keeps on increasing and what can be done to keep time interval at 6 seconds?

Please note that no data is lost even though the application comes to a stand-still for 6 minutes.
I have searched various forums for many days without any success.
I am attaching the code and properties settings.


Private void import_data_button_click(object sender, eventargs e)
{

if (livemenu.checked)
{
livemenu.checked = false;
live = false;
sptimer.enabled = false;

try
{
if (sp.isopen) { sp.close(); }
}
catch { }
}
else
{
{
livemenu.checked = true;
live = true;
sptimer.enabled = true;

try
{
if (!sp.isopen) { sp.open(); }
}
catch { }
drawgraphs();
}

}


private void sp_datareceived(object sender, system.io.ports.serialdatareceivedeventargs e)
{
try
{
serial_data += sp.readline();
}
catch { }
}

private void sptimer_tick(object sender, eventargs e)
{
sptimer.enabled = false;
if (lbllive.visible == false) { lbllive.visible = true; }
else { lbllive.visible = false; }

if (serial_data.contains("\r"))
{
writetodatabase(serial_data);
serial_data = "";
}

sptimer.enabled = true;
}

any suggestions will be of great help to me.

Thanks!!!
Rupali

Thanks for your reply!

The data comes properly when viewed on hyper terminal i.e. @1 data/6 seconds, continously. Also all the data contains "\r", as the data is never lost and only the time interval of importing into app and drawing graphs keeps increases.

I have also attached a snapshot of properties please view.

Also "Drawgraph" doesnt take more than 6 seconds as initially the refresh rate is @1 data/6 seconds for some time(say half and hour).

Kindly reply if you have any suggestions.


Have you verified that the SPTimer_Tick is firing at a constant rate? Have you checked if there is something in Serial_Data each time it fires but that there is no '\r' character in it?

This might also be the problem (from the documentation):
The DataReceived event is not guaranteed to be raised for every byte received. Use the BytesToRead property to determine how much data is left to be read in the buffer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.