在我的Windows窗体应用程序中,我使用stopwatch
计算事件之间的经过时间,但我想从NMEA(GPRMC句子)获取时间,并希望将其用作已用时间。我怎么能这样做?
这是我的代码;
Stopwatch watch=new Stopwatch();
Textbox1.Text=gsaat.Substring(4,2);
//gsaat is the UTC time part of the GPRMC;
private void timer2_Tick(object sender, EventArgs e)
{
if ((Convert.ToDouble(textBox2.Text) >= Convert.ToDouble(label1.Text) && Convert.ToDouble(label1.Text) >= Convert.ToDouble(textBox1.Text)))
{
watch.Start();
var time = watch.Elapsed.TotalSeconds;
//I want to use gsaat as elapsed time in here instead of stopwatch
label2.Text = String.Format("{0:00.00}", time);
}
}
EDIT;
在我的应用程序中,我正在使用GNSS模块进行加速测试。在应用中,我设置速度Textbox1
和Textbox2
的边界条件,label1
表示汽车的当前速度,label2
表示汽车当前速度的经过时间进入这些边界。例如;我设置Textbox1.text=10
和Textbox2.text=100
并开始加速汽车,我想测量汽车从10到100之间的时差。为此,我使用了stopwatch
但我遇到了一些问题。现在我想用UTC时间测量汽车速度为10和100之间的时间。我可以从GPRMC的句子得到UTC时间,我也解析了它。但是我无法从零开始当汽车速度为10时,当汽车速度超过100时停止。
答案 0 :(得分:1)
不是很清楚你想要实现什么,而是猜测:
解析NMEA时间并将其另存为DateTime对象。然后做
var timeSpan = DateTime.UtcNow - nmeaTimestamp;
获取自传输时间戳以来的时间。
请查看NMEA documentation此时间戳的含义:定位的UTC:发送电台接近发送位置的时间。
如果您想在特定时间段后发出警报,请使用Timer。它将在时间结束时引发事件。
编辑:选择接近速度10的数据包和接近速度100的数据包,解析时间戳并减去它们:
var accelerationTimeMilliseconds = (timestampAt100 - timestampAt10).ElapsedMilliseconds;