/// <summary> /// 0165 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { String _0165 = preWriteValue(60); String cmd165 = "3b0165" + _0165; byte[] cmdSend165 = StringToSendBytes.bytesToSend(cmd165 + "\n"); GobalSerialPort.WriteByMessage(cmdSend165, 0, cmdSend165.Length); String result = GobalSerialPort.ResultBackString; String _0166 = preWriteValue(40); String cmd166 = "3b0166" + _0166; byte[] cmdSend166 = StringToSendBytes.bytesToSend(cmd166 + "\n"); GobalSerialPort.WriteByMessage(cmdSend166, 0, cmdSend166.Length); String result166 = GobalSerialPort.ResultBackString; String _0167 = preWriteValue(96); String cmd167 = "3b0167" + _0167; byte[] cmdSend167 = StringToSendBytes.bytesToSend(cmd167 + "\n"); GobalSerialPort.WriteByMessage(cmdSend167, 0, cmdSend167.Length); String result167 = GobalSerialPort.ResultBackString; String _0168 = preWriteValue(144); String cmd168 = "3b0168" + _0168; byte[] cmdSend168 = StringToSendBytes.bytesToSend(cmd168 + "\n"); GobalSerialPort.WriteByMessage(cmdSend168, 0, cmdSend168.Length); String result168 = GobalSerialPort.ResultBackString; String _0169 = preWriteValue(144); String cmd169 = "3b0169" + _0169; byte[] cmdSend169 = StringToSendBytes.bytesToSend(cmd169 + "\n"); GobalSerialPort.WriteByMessage(cmdSend169, 0, cmdSend169.Length); String result169 = GobalSerialPort.ResultBackString; String _016c = preWriteValue(40); String cmd16c = "3b016c" + _0169; byte[] cmdSend16c = StringToSendBytes.bytesToSend(cmd16c + "\n"); GobalSerialPort.WriteByMessage(cmdSend16c, 0, cmdSend16c.Length); String result16c = GobalSerialPort.ResultBackString; if (result.Contains("7B")) { // this.textBox1.Text = "ok"; } }
/// <summary> /// 16个字节长度 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { String writeValue = this.textBox1.Text.Trim(); int count = Convert.ToInt32(writeValue); String all = Convert.ToString(count, 16).PadLeft(32, '0'); String cmd = "3b016E" + StringUtil.Reverse(all); byte[] cmdSend = StringToSendBytes.bytesToSend(cmd + "\n"); GobalSerialPort.WriteByMessage(cmdSend, 0, cmdSend.Length); String result = GobalSerialPort.ResultBackString; if (result.Contains("7B")) { this.textBox1.Text = "ok"; Read(); } }
private void button1_Click(object sender, EventArgs e) { this.button1.Text = "测试中"; try { String startValue = this.richTextBox1.Text; String endtValue = this.richTextBox2.Text; if ("".Equals(startValue) || startValue == null || ("".Equals(endtValue) || endtValue == null)) { MessageBox.Show("请输入数据"); return; } long start = long.Parse(startValue); long end = long.Parse(endtValue); if (end < start) { MessageBox.Show("结束速度需要大于开始速度"); return; } // 开始速度 String startValue16 = Convert.ToString(start * 2, 16).PadLeft(4, '0'); // 结束速度 String endtValue16 = Convert.ToString(end * 2, 16).PadLeft(4, '0'); String speedValue = CommonCmd.speedprefix + startValue16 + endtValue16 + CommonCmd.speedsuffix + "\n"; byte[] speedValueByte = StringToSendBytes.bytesToSend(startValue); if (WriteVale(speedValueByte)) { Thread.Sleep(500); //延时半分钟 readValue(); } } catch (Exception) { } this.button1.Text = "开始"; }
private void send_Click(object sender, EventArgs e) { String sendText = this.skinChatRichTextBox2.Text.Trim(); Byte[] sendCmd = StringToSendBytes.bytesToSend(sendText + "\n"); GobalSerialPort.WriteByMessage(sendCmd, 0, sendCmd.Length); String backString = GobalSerialPort.ResultBackString; //if (backString.Contains("10") && backString.Contains("78")) //{ // GobalSerialPort.WriteByMessage(CommonCmd.ATSTD6, 0, CommonCmd.ATSTD6.Length); // GobalSerialPort.WriteByMessage(CommonCmd._830300D610140A, 0, CommonCmd._830300D610140A.Length); // GobalSerialPort.WriteByMessage(CommonCmd.ATSW00, 0, CommonCmd.ATSW00.Length); //} // backString = GobalSerialPort.ResultBackString; //释放 this.richTextBox1.Invoke(maifText, backString); // this.skinChatRichTextBox1.Text = GobalSerialPort.ResultBackString; }
/// <summary> /// 测试开始 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { this.button1.Text = "测试中"; if (this.checkBox1.Checked) { String cmd = CommonCmd.shutprefix + "00" + "FFFFFFFFFF"; byte[] cmdbyte = StringToSendBytes.bytesToSend(cmd + "\n"); //serialPort.GobalSerialPort.WriteByMessage(cmdbyte,0,cmdbyte.Length); if (WriteVale(cmdbyte)) { readValue(); } } if (this.checkBox2.Checked) { String cmd = CommonCmd.shutprefix + "FF" + "00" + "FFFFFFFF"; byte[] cmdbyte = StringToSendBytes.bytesToSend(cmd + "\n"); //serialPort.GobalSerialPort.WriteByMessage(cmdbyte,0,cmdbyte.Length); if (WriteVale(cmdbyte)) { readValue(); } } if (this.checkBox3.Checked) { String cmd = CommonCmd.shutprefix + "FFFF00FFFFFF"; byte[] cmdbyte = StringToSendBytes.bytesToSend(cmd + "\n"); //serialPort.GobalSerialPort.WriteByMessage(cmdbyte,0,cmdbyte.Length); if (WriteVale(cmdbyte)) { readValue(); } } if (this.checkBox5.Checked) { String cmd = CommonCmd.shutprefix + "FFFFFF00FFFF"; byte[] cmdbyte = StringToSendBytes.bytesToSend(cmd + "\n"); //serialPort.GobalSerialPort.WriteByMessage(cmdbyte,0,cmdbyte.Length); if (WriteVale(cmdbyte)) { readValue(); } } if (this.checkBox7.Checked) { String cmd = CommonCmd.shutprefix + "FFFFFFFF00FF"; byte[] cmdbyte = StringToSendBytes.bytesToSend(cmd + "\n"); //serialPort.GobalSerialPort.WriteByMessage(cmdbyte,0,cmdbyte.Length); if (WriteVale(cmdbyte)) { readValue(); } } if (this.checkBox8.Checked) { String cmd = CommonCmd.shutprefix + "FFFFFFFFFF00"; byte[] cmdbyte = StringToSendBytes.bytesToSend(cmd + "\n"); //serialPort.GobalSerialPort.WriteByMessage(cmdbyte,0,cmdbyte.Length); if (WriteVale(cmdbyte)) { readValue(); } } else { String cmd = CommonCmd.shutprefix + "FFFFFFFFFFFF"; byte[] cmdbyte = StringToSendBytes.bytesToSend(cmd + "\n"); //serialPort.GobalSerialPort.WriteByMessage(cmdbyte,0,cmdbyte.Length); if (WriteVale(cmdbyte)) { readValue(); } } this.button1.Text = "开始"; }
/// <summary> /// /// </summary> public void isConnet() { while (true) { if (EcuConnectionF.ECULINKStatus == true) { break; } } try { byte[] _210213 = StringToSendBytes.bytesToSend("210213\n"); GobalSerialPort.WriteByMessage(_210213, 0, _210213.Length); String result213 = GobalSerialPort.ResultBackString; String[] resultA = result213.Split('\r'); result213 = resultA[1].Replace(" ", ""); byte[] _210214 = StringToSendBytes.bytesToSend("210214\n"); GobalSerialPort.WriteByMessage(_210214, 0, _210214.Length); String result214 = GobalSerialPort.ResultBackString; String[] result14A = result214.Split('\r'); result214 = result14A[1].Replace(" ", ""); byte[] _210215 = StringToSendBytes.bytesToSend("210215\n"); GobalSerialPort.WriteByMessage(_210215, 0, _210215.Length); String result215 = GobalSerialPort.ResultBackString; String[] result15A = result215.Split('\r'); result215 = result15A[1].Replace(" ", ""); byte[] _210241 = StringToSendBytes.bytesToSend("210241\n"); GobalSerialPort.WriteByMessage(_210241, 0, _210241.Length); String result210241 = GobalSerialPort.ResultBackString; String[] result210241A = result210241.Split('\r'); result210241 = result210241A[1].Replace(" ", ""); byte[] _210240 = StringToSendBytes.bytesToSend("210240\n"); GobalSerialPort.WriteByMessage(_210240, 0, _210240.Length); String result210240 = GobalSerialPort.ResultBackString; String[] result210240A = result210240.Split('\r'); result210240 = result210240A[1].Replace(" ", ""); //展示数据格式 show(result213, result214, result215, result210241, result210240); //mode 1086 //log.Info("ECUMODE 1086 " + " "); //CommonConstant.mode = "1086"; //Tp_KeyMethodFuntion.Con(); //GobalSerialPort.WriteByMessage(CommonCmd._1086, 0, CommonCmd._1086.Length); //String backString = GobalSerialPort.ResultBackString; //if (!backString.Contains("86")) //{ // GobalSerialPort.WriteByMessage(CommonCmd._1086, 0, CommonCmd._1086.Length); // backString = GobalSerialPort.ResultBackString; //} //else //{ // GobalSerialPort.WriteByMessage(CommonCmd.ATST00, 0, CommonCmd.ATST00.Length); // //write // String tl718code = result214.Substring(8 + 89 * 2, 12); // String time = result214.Substring(8 + 96 * 2, 8); // result214.Replace(tl718code, "0000" + CommonConstant.TL718CODE); // result214.Replace(time, DateUtil.getDate()); // String address = "3b0214" + result214.Substring(8, 200); // byte[] cmdSend = StringToSendBytes.bytesToSend(address + "\n"); // GobalSerialPort.WriteByMessage(cmdSend, 0, cmdSend.Length); // String result = GobalSerialPort.ResultBackString; // //if () { // //} // GobalSerialPort.WriteByMessage(CommonCmd.ATST0F, 0, CommonCmd.ATST0F.Length); // GobalSerialPort.WriteByMessage(CommonCmd._1081,0,CommonCmd._1081.Length); //} } catch (IndexOutOfRangeException) { byte[] _210213 = StringToSendBytes.bytesToSend("210213\n"); GobalSerialPort.WriteByMessage(_210213, 0, _210213.Length); String result213 = GobalSerialPort.ResultBackString; String[] resultA = result213.Split('\r'); result213 = resultA[1].Replace(" ", ""); byte[] _210214 = StringToSendBytes.bytesToSend("210214\n"); GobalSerialPort.WriteByMessage(_210214, 0, _210214.Length); String result214 = GobalSerialPort.ResultBackString; String[] result14A = result214.Split('\r'); result214 = result14A[1].Replace(" ", ""); byte[] _210215 = StringToSendBytes.bytesToSend("210215\n"); GobalSerialPort.WriteByMessage(_210215, 0, _210215.Length); String result215 = GobalSerialPort.ResultBackString; String[] result15A = result215.Split('\r'); result215 = result15A[1].Replace(" ", ""); byte[] _210241 = StringToSendBytes.bytesToSend("210241\n"); GobalSerialPort.WriteByMessage(_210241, 0, _210241.Length); String result210241 = GobalSerialPort.ResultBackString; String[] result210241A = result210241.Split('\r'); result210241 = result210241A[1].Replace(" ", ""); byte[] _210240 = StringToSendBytes.bytesToSend("210240\n"); GobalSerialPort.WriteByMessage(_210240, 0, _210240.Length); String result210240 = GobalSerialPort.ResultBackString; String[] result210240A = result210240.Split('\r'); result210240 = result210240A[1].Replace(" ", ""); show(result213, result214, result215, result210241, result210240); } catch (Exception) { } finally { // return null; } }
/// <summary> /// read dtc code /// </summary> public static void ReadECU13DTC() { CommonCmd.SendATE1(); GobalSerialPort.ClearSendAndRecive(); try { byte[] stringToalldtccodeA = StringToSendBytes.bytesToSend("1800FF00\n"); //发送命令的一个转化 GobalSerialPort.WriteByMessage(stringToalldtccodeA, 0, stringToalldtccodeA.Length); StringOfGets = GobalSerialPort.ResultBackString; string[] splitstring = StringOfGets.Split('\r'); if (splitstring[1] != null && (!splitstring[1].Contains("NO"))) { string result = splitstring[1]; string ss = result; ss = result.Replace(" ", ""); //这里是将空格改为空的字符串,但是还有其他的方法 string sub = ss.Substring(2, 2); string subtostr = sub.ToString(); int subtoint = Convert.ToInt32(subtostr, 16); //subint 是表示有多少个故障代码 string[] strsubtring = new string[subtoint]; //strsubtring 表示要开辟多少个字符串数组 ECU13DTC = new string[subtoint]; int[] strsubtint = new int[subtoint]; Console.WriteLine(subtoint); byte[][] C13DTwrite = new byte[subtoint][]; Save13BackDTC = new string[subtoint]; C13BackTDNumCode = new string[subtoint]; for (int i = 0; i < subtoint; i++) { C13DTwrite[i] = new byte[8]; } //初始化数据 SingleDtcFunction singleDtcFunction = new SingleDtcFunction(); MyMeans.DropDTC(); //清除原先数据 MyMeans.AccessLink(); int x = 4; for (int i = 0; i < subtoint; i++) { strsubtring[i] = ss.Substring(x, 6); x = x + 6; strsubtring[i] = strsubtring[i].Substring(0, 4); C13BackTDNumCode[i] = strsubtring[i]; int TheoneString = Convert.ToInt32(strsubtring[i].Substring(0, 1), 16); int _16TheoneString = int.Parse(TheoneString.ToString("X"), System.Globalization.NumberStyles.HexNumber); string ThethreeString = strsubtring[i].Substring(1, 3); //将前面的一个数据去掉前面的两位 string SUBba = Convert.ToString(_16TheoneString, 2).PadLeft(4, '0'); string C = SUBba.Substring(2, 2); string D = "00" + C; string Fianba = (Convert.ToInt32("00" + C)).ToString("X"); string Fianba1 = Convert.ToInt32(D, 2).ToString(); strsubtring[i] = Fianba1 + ThethreeString; ECU13DTC[i] = strsubtring[i]; ECU13DTCSingle = strsubtring[i]; strsubtring[i] = "17" + strsubtring[i]; C13DTwrite[i] = StringToSendBytes.bytesToSend(strsubtring[i] + "\n"); try { GobalSerialPort.WriteByMessage(C13DTwrite[i], 0, C13DTwrite[0].Length); StringOfGets = GobalSerialPort.ResultBackString; Save13BackDTC[i] = StringOfGets; Save13BackDTCSingle = StringOfGets; //Date int count = i + 1; singleDtcFunction.ShowDtcCodeF(count); } catch (Exception e) { log.Info("the error fo message is :" + e.Message); continue; } } MainF.ShowBoxTex("读取故障完毕"); MyMeans.AccessBreak(); SaveFileFunction.Dtc_SaveExcel(); } } catch (Exception e) { SaveFileFunction.Dtc_SaveExcel(); log.Info("Dtc final error :" + e.Message); } }
//public static String speedsuffix = "012C00020010"; //public static byte[] _speed; //public static byte[] _331A; /// <summary> /// 静态变量 /// </summary> static CommonCmd() { //1086 _1086 = StringToSendBytes.bytesToSend("1086\n"); /// _allOilCost = StringToSendBytes.bytesToSend("210171\n"); _allTrip = StringToSendBytes.bytesToSend("21016D\n"); _allEngineTime = StringToSendBytes.bytesToSend("21016E\n"); _ecuAllTime = StringToSendBytes.bytesToSend("21016F\n"); _ecuRevolutions = StringToSendBytes.bytesToSend("210170\n"); /// hiByte = StringToSendBytes.bytesToSend("2102F4\n"); hiOneByte = StringToSendBytes.bytesToSend("2102F5\n"); /// trip165 = StringToSendBytes.bytesToSend("210165\n"); trip166 = StringToSendBytes.bytesToSend("210166\n"); trip167 = StringToSendBytes.bytesToSend("210167\n"); trip168 = StringToSendBytes.bytesToSend("210168\n"); trip169 = StringToSendBytes.bytesToSend("210169\n"); trip16c = StringToSendBytes.bytesToSend("21016c\n"); /// ATE0 = StringToSendBytes.bytesToSend("ATE0\n"); ATE1 = StringToSendBytes.bytesToSend("ATE1\n"); ClearCmd = StringToSendBytes.bytesToSend("2CF004\n"); //_21f0 = StringToSendBytes.bytesToSend("2cf004\n"); /// _21f0 = StringToSendBytes.bytesToSend("21F0\n"); ecuVersionCmd = StringToSendBytes.bytesToSend("1A94\n"); _1081 = StringToSendBytes.bytesToSend("1081\n"); ClearDtcCmd = StringToSendBytes.bytesToSend("14FF00\n"); ATR = StringToSendBytes.bytesToSend("AT@R\n"); ATST0F = StringToSendBytes.bytesToSend("ATST0F\n"); ATST00 = StringToSendBytes.bytesToSend("ATST00\n"); ATSTD6 = StringToSendBytes.bytesToSend("ATSTFF\n"); _830300D610140A = StringToSendBytes.bytesToSend("830300D610140A\n"); ATSW00 = StringToSendBytes.bytesToSend("ATSW00\n"); ATSW19 = StringToSendBytes.bytesToSend("ATSW19\n"); ATSTFF = StringToSendBytes.bytesToSend("ATSTFF\n"); ATSW30 = StringToSendBytes.bytesToSend("ATSW30\n"); //8303 _830300D600140A = StringToSendBytes.bytesToSend("830300D600140A\n"); _109214 = StringToSendBytes.bytesToSend("109214\n"); _808002 = StringToSendBytes.bytesToSend("808002\n"); _808001 = StringToSendBytes.bytesToSend("808001\n"); ATBD = StringToSendBytes.bytesToSend("ATBD\n"); _36 = StringToSendBytes.bytesToSend("36\n"); _37 = StringToSendBytes.bytesToSend("37\n"); _1101 = StringToSendBytes.bytesToSend("1101\n"); _3180 = StringToSendBytes.bytesToSend("3180\n"); _3380 = StringToSendBytes.bytesToSend("3380\n"); ATSH81_10_F1 = StringToSendBytes.bytesToSend("ATSH8110F1\n"); _331bfe = StringToSendBytes.bytesToSend("311B00000000000000FE00" + "\n"); _331bfd = StringToSendBytes.bytesToSend("311B00000000000000FD00" + "\n"); _331bce = StringToSendBytes.bytesToSend("311B00000000000000FE00" + "\n"); _331bcf = StringToSendBytes.bytesToSend("311B00000000000000FE00" + "\n"); _331b = StringToSendBytes.bytesToSend("331b\n"); _CompressionTest = StringToSendBytes.bytesToSend("31180000C8001401110222F667F334" + "\n"); _3318 = StringToSendBytes.bytesToSend("3318\n"); // _HighPressureTest = StringToSendBytes.bytesToSend("311400010030D40DAC11940DAC03E82CEC1F4006A407D00D480ED80AF0012C" + "\n"); _3314 = StringToSendBytes.bytesToSend("3314\n"); _3316 = StringToSendBytes.bytesToSend("3316\n"); _331A = StringToSendBytes.bytesToSend("331A\n"); _3315 = StringToSendBytes.bytesToSend("3315\n"); }
/// <summary> /// 字符串 写入初始化 /// </summary> private static void ToSendEcu13IdF() { int C13ecunum1 = 128; int C13ecunum2 = 134; int C13ecunum3 = 137; int C13ecunum4 = 140; int C13ecunum5 = 142; int C13ecunum6 = 144; int C13ecunum7 = 151; for (int i = 0; i < 2; i++) { C13ecuIdstring1Tobyte[i] = new byte[6]; //这里是ecu数据的第一段 } for (int i = 0; i < 2; i++) { C13ecuIdstrCmd1[i] = "1A" + C13ecunum1.ToString("X"); C13ecunum1++; C13ecuIdstring1Tobyte[i] = StringToSendBytes.bytesToSend(C13ecuIdstrCmd1[i] + "\n"); } //这里是ecu数据的第二段,两个循环的数据 for (int i = 0; i < 2; i++) { C13ecuIdstring2Tobyte[i] = new byte[6]; //这里是ecu数据的第二段 } for (int i = 0; i < 2; i++) { C13ecuIdstrCmd2[i] = "1A" + C13ecunum2.ToString("X"); C13ecunum2++; C13ecuIdstring2Tobyte[i] = StringToSendBytes.bytesToSend(C13ecuIdstrCmd2[i] + "\n"); } //three for (int i = 0; i < 2; i++) { C13ecuIdstring3Tobyte[i] = new byte[6]; //这里是ecu数据的第san段 } for (int i = 0; i < 2; i++) { C13ecuIdstrCmd3[i] = "1A" + C13ecunum3.ToString("X"); C13ecunum3++; C13ecuIdstring3Tobyte[i] = StringToSendBytes.bytesToSend(C13ecuIdstrCmd3[i] + "\n"); } //这里是第四段程序 for (int i = 0; i < 1; i++) { C13ecuIdstring4Tobyte[i] = new byte[6]; } for (int i = 0; i < 1; i++) { // Ecustring1Tobyte[i]=new byte[6]; C13ecuIdstrCmd4[i] = "1A" + C13ecunum4.ToString("X"); C13ecunum4++; C13ecuIdstring4Tobyte[i] = StringToSendBytes.bytesToSend(C13ecuIdstrCmd4[i] + "\n"); } //这里是第五段程序 for (int i = 0; i < 1; i++) { C13ecuIdstring5Tobyte[i] = new byte[6]; } for (int i = 0; i < 1; i++) { C13ecuIdstrCmd5[i] = "1A" + C13ecunum5.ToString("X"); C13ecunum5++; C13ecuIdstring5Tobyte[i] = StringToSendBytes.bytesToSend(C13ecuIdstrCmd5[i] + "\n"); } for (int i = 0; i < 6; i++) { C13ecuIdstring6Tobyte[i] = new byte[6]; } for (int i = 0; i < 6; i++) { C13ecuIdstrCmd6[i] = "1A" + C13ecunum6.ToString("X"); C13ecunum6++; C13ecuIdstring6Tobyte[i] = StringToSendBytes.bytesToSend(C13ecuIdstrCmd6[i] + "\n"); } for (int i = 0; i < 9; i++) { C13ecuIdstring7Tobyte[i] = new byte[6]; } for (int i = 0; i < 9; i++) { C13ecuIdstrCmd7[i] = "1A" + C13ecunum7.ToString("X"); C13ecunum7++; C13ecuIdstring7Tobyte[i] = StringToSendBytes.bytesToSend(C13ecuIdstrCmd7[i] + "\n"); } }