public PowertrainVersion ReadVersion() { try { int length = Channel.SendAndRecv(readEcuVersion, 0, readEcuVersion.Length, rData); if (!CheckIfPositive(rData, readEcuVersion)) { throw new DiagException(Database.QueryText("Read ECU Version Fail", "System")); } PowertrainVersion ver = new PowertrainVersion(); ver.Model = ""; ver.Hardware = ""; ver.Software = Encoding.ASCII.GetString(rData, 1, length - 1); return ver; } catch (ChannelException e) { throw new DiagException(e.Message); } }
private static PowertrainVersion FormatVersion(string hex) { PowertrainVersion ver = new PowertrainVersion(); StringBuilder temp = new StringBuilder(); temp.Append("ECU"); for (int i = 0; i < 6; i += 2) { string e = hex.Substring(i, 2); byte h = Convert.ToByte(e, 16); char c = Convert.ToChar(h); if (Char.IsLetterOrDigit(c)) temp.Append(c); } temp.Append('-'); int beginOfSoftware = 18; for (int i = 6; i < 16; i += 2) { string e = hex.Substring(i, 2); byte h = Convert.ToByte(e, 16); char c = Convert.ToChar(h); if (Char.IsLetterOrDigit(c)) { temp.Append(c); } else { beginOfSoftware -= 2; } } ver.Hardware = temp.ToString(); temp.Clear(); for (int i = beginOfSoftware; i < (beginOfSoftware + 12); i += 2) { string e = hex.Substring(i, 2); byte h = Convert.ToByte(e, 16); char c = Convert.ToChar(h); if (Char.IsLetterOrDigit(c)) temp.Append(c); } ver.Software = temp.ToString(); return ver; }