public TimeSpan?GetTimeToSplit(DateTime startTime, int splitCode, int passing = -1) { PostPass postPass = null; if (passing == -1) { postPass = PostPasses.LastOrDefault(x => x.PostCode == splitCode); } else { //Else we want a specific passing-no var passes = PostPasses.Where(x => x.PostCode == splitCode).ToArray(); if (passes.Length >= passing) { postPass = passes[passing - 1]; } } if (postPass == null) { return(null); } else { var readOutTime = PostPasses.Last(x => x.PostCode >= 250 && x.PostCode <= 254); DateTime timeOfPostPass = TimeOfReadout.AddMilliseconds((postPass.Time - readOutTime.Time).TotalMilliseconds); return(timeOfPostPass - startTime); } }
void ParseMessage(string msg) { var parts = msg.Split('\t'); TagReadOut ro = new TagReadOut(); string messageTime = ""; string hardwareId = ""; int punchCode = 0; string unitSerialNo = ""; foreach (var p in parts) { if (p.StartsWith("I")) { hardwareId = p.Substring(1); } else if (p.StartsWith("W")) { //m_unitClocktime = p.Substring(1); messageTime = p.Substring(1); } else if (p.StartsWith("C")) { m_ecuCode = int.Parse(p.Substring(1)); } else if (p.StartsWith("Y")) { unitSerialNo = p.Substring(1); } else if (p.StartsWith("N")) { ro.TagNo = int.Parse(p.Substring(1)); } else if (p.StartsWith("R")) { ro.TagText = p.Substring(1); } else if (p.StartsWith("P")) { string[] passParts = p.Substring(1).Split('-'); PostPass pp = new PostPass(); pp.PostNo = int.Parse(passParts[0]); pp.PostCode = int.Parse(passParts[1]); var timeParts = passParts[2].Split(':'); var time = int.Parse(timeParts[0]) * 1000 * 3600 + int.Parse(timeParts[1]) * 1000 * 60 + Math.Round(double.Parse(timeParts[2], CultureInfo.InvariantCulture), 3) * 1000; pp.Time = TimeSpan.FromMilliseconds(time); ro.PostPasses.Add(pp); } } if (ro.TagNo >= 0 && ro.PostPasses.Count > 0 && ro.PostPasses.Last().PostCode == m_ecuCode) { ro.TimeOfReadout = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd") + " " + messageTime, "yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture); ListBox lst = ro.TagNo < 1000 ? lstCard1 : lstCard2; lst.Invoke(new MethodInvoker(delegate { lst.Items.Clear(); foreach (var p in ro.PostPasses) { lst.Items.Add(p.PostNo.ToString().PadLeft(2) + " " + p.PostCode.ToString().PadLeft(3) + " " + p.Time); } })); /* var tr = OnTagRead; * if (tr != null) * tr(ro);*/ } else { txtEcuTime.Invoke(new MethodInvoker(delegate { txtEcuTime.Text = messageTime; })); } }