Skip to content

Time delay or data delay

Loh Jy

Asked Jun 4, 2015, 6:23 PM EDT1 answer
Share
LinkedInX
What should i do on the coding if i only want to capture 1 time stamp for the data I received?
As data being received bit by bit, the time is also ticking.. As a result, now a time stamp is shown after every bit of data received.
Interval between each full set of data is roughly 10s apart while interval between each bit of data is roughly... 20millisec..
 
Coding as follows:
 
TypeScript
 private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            string time = DateTime.Now.ToString("HH:mm:ss.ff");  //Display Real time per received data
            RxString = serialPort1.ReadExisting();
            this.Invoke(new EventHandler(DisplayText));
StreamWriter MyStreamWriter = new StreamWriter(@"c:\test1.txt",true); //True tell SW to append to file instead of overwriting
MyStreamWriter.Write(time + " " + RxString); //Write time + string
Code
            MyStreamWriter.Flush();
            MyStreamWriter.Close();
        }
 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Okay, solved.
     
    I managed to display 1 time stamp to 1 full set of data by changing  
    RxString = serialPort1.ReadExisting(); 
    to
    RxString = serialPort1.ReadLine(); 
     
    Hope this help others too. 
    0