//读取追溯码 public void getTraceCode(Object id) { CANSDK.VCI_CAN_OBJ obj = new CANSDK.VCI_CAN_OBJ(); obj.Init(); obj.RemoteFlag = 1; //远程帧 obj.ExternFlag = 1; //扩展帧 obj.SendType = 0; //正常发送 string slaveId = Convert.ToString(id); while (true) { for (int i = 2; i < 6; i++) { if (i == 4) { continue; } obj.ID = uint.Parse("0C2" + i.ToString("X") + "7F" + slaveId, System.Globalization.NumberStyles.HexNumber); // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2")); CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1); Thread.Sleep(20); } Thread.Sleep(200); } }
//获取从机ID public void getSalveId() { CANSDK.VCI_CAN_OBJ obj = new CANSDK.VCI_CAN_OBJ(); obj.Init(); obj.RemoteFlag = 1; //远程帧 obj.ExternFlag = 1; //扩展帧 obj.SendType = 0; //正常发送 isWaitting["getSlaveId"] = 1; //isWaitting["getSlaveId"] == 1为了防止还在发送循环中已经收到了回复,此时不需要继续发送 for (int i = 0; i < 64 && isWaitting["getSlaveId"] == 1; i++) { obj.ID = uint.Parse("0C0041" + i.ToString("X2"), System.Globalization.NumberStyles.HexNumber); // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2")); uint frameCount = CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1); } long starttime = DateTime.Now.Ticks; //等待回复 while ((DateTime.Now.Ticks - starttime) / 10000 < 2000 && isWaitting["getSlaveId"] == 1) { if (isWaitting["getSlaveId"] == 0) { break; } } if (isWaitting["getSlaveId"] == 1) { isWaitting["getSlaveId"] = 0; flushVM(new Object[] { FunCode.SHOWINFO, "getSlaveFailed" }); } }
//发送config1 public void sendConfig1Pack(Object o) { ArrayList al = (ArrayList)o; string slaveId = Convert.ToString(al[0]); Gen2SlaveConfig g = (Gen2SlaveConfig)al[1]; Gen2SlaveInfo gsi = (Gen2SlaveInfo)al[2]; if ((g.Sid == null || g.Sid.Equals("")) && (gsi.Sid != null && !gsi.Sid.Equals(""))) { g.Sid = DataConverter.string2Hex(gsi.Sid).ToString(); } if ((g.Covth == null || g.Covth.Equals("")) && (gsi.Covth != null && !gsi.Covth.Equals(""))) { g.Covth = gsi.Covth.Replace("mV", String.Empty); } if ((g.Cuvth == null || g.Cuvth.Equals("")) && (gsi.Cuvth != null && !gsi.Cuvth.Equals(""))) { g.Cuvth = gsi.Cuvth.Replace("mV", String.Empty); } if ((g.Foth == null || g.Foth.Equals("")) && (gsi.Foth != null && !gsi.Foth.Equals(""))) { g.Foth = gsi.Foth.Replace("℃", String.Empty); } if ((g.Fcth == null || g.Fcth.Equals("")) && (gsi.Fcth != null && !gsi.Fcth.Equals(""))) { g.Fcth = gsi.Fcth.Replace("℃", String.Empty); } if (!(DataConverter.canStirng2int(g.Sid) && DataConverter.canStirng2int(g.Covth) && DataConverter.canStirng2int(g.Cuvth) && DataConverter.canStirng2int(g.Foth) && DataConverter.canStirng2int(g.Fcth))) { flushVM(new Object[] { FunCode.SHOWINFO, "wrongdata" }); return; } CANSDK.VCI_CAN_OBJ obj = new CANSDK.VCI_CAN_OBJ(); obj.Init(); obj.RemoteFlag = 0; //数据帧 obj.ExternFlag = 1; //扩展帧 obj.SendType = 0; //正常发送 obj.ID = uint.Parse("0C21" + slaveId + "7F", System.Globalization.NumberStyles.HexNumber); byte[] b = new byte[8]; b[1] = (byte)Convert.ToInt32(g.Sid); short d = (short)Convert.ToInt32(g.Covth); byte[] t = System.BitConverter.GetBytes(d); b[2] = t[0]; b[3] = t[1]; d = (short)Convert.ToInt32(g.Cuvth); t = System.BitConverter.GetBytes(d); b[4] = t[0]; b[5] = t[1]; b[6] = (byte)(Convert.ToInt32(g.Foth) + 40); b[7] = (byte)(Convert.ToInt32(g.Fcth) + 40); obj.Data = b; obj.DataLen = 8; // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2")); CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1); flushVM(new Object[] { FunCode.SHOWINFO, "sendSuc" }); }
public void sendData(Object o) { tvm.IsNext = false; byte[] data = (byte[])o; CANSDK.VCI_CAN_OBJ obj = new CANSDK.VCI_CAN_OBJ(); obj.Init(); obj.RemoteFlag = 0; //数据帧 obj.ExternFlag = 1; //扩展帧 obj.SendType = 0; //正常发送 obj.DataLen = 8; obj.ID = uint.Parse(tvm.SendId, System.Globalization.NumberStyles.HexNumber); obj.Data = data; CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1); Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data) + ",ID:" + obj.ID.ToString("X2")); waitForResponse(); }
//发送均衡控制指令 public void sendBalancePack(Object o) { ArrayList al = (ArrayList)o; string slaveId = Convert.ToString(al[0]); Gen2SlaveConfig g = (Gen2SlaveConfig)al[1]; CANSDK.VCI_CAN_OBJ obj = new CANSDK.VCI_CAN_OBJ(); obj.Init(); obj.RemoteFlag = 0; //数据帧 obj.ExternFlag = 1; //扩展帧 obj.SendType = 0; //正常发送 obj.ID = uint.Parse("1815" + "41" + slaveId, System.Globalization.NumberStyles.HexNumber); obj.Data = g.getBalanceData(); obj.DataLen = 8; // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2")); CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1); flushVM(new Object[] { FunCode.SHOWINFO, "sendSuc" }); }
public void send(byte[] data) { CANSDK.VCI_CAN_OBJ obj = new CANSDK.VCI_CAN_OBJ(); obj.Init(); obj.RemoteFlag = 0; //数据帧 obj.ExternFlag = 0; //标准帧 obj.SendType = 0; //正常发送 obj.DataLen = 8; string s = SendID; //if (IsECUFun) { // s = "7DF"; //} obj.ID = uint.Parse(s, System.Globalization.NumberStyles.HexNumber); obj.Data = data; CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1); Object[] results = new Object[3]; results[0] = FunCode.SHOWUDSLOG + ""; results[1] = "sendUDSData :" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") + " " + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 3 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2"); results[2] = SENDCOLOR; //if (data[1] != 0x3E) //{ // flushVM(results); //} //每次发送数据更新心跳发送基础时间 if (isDoBootLoader) { Console.WriteLine("sendUDSData :" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") + " " + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 3 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2")); } else { flushVM(results); } results = new Object[1]; results[0] = FunCode.CHANGEHEARTTIME + ""; flushVM(results); }
public void sendRelay2Pack(Object o) { ArrayList al = (ArrayList)o; string slaveId = Convert.ToString(al[0]); Gen2SlaveConfig g = (Gen2SlaveConfig)al[1]; CANSDK.VCI_CAN_OBJ obj = new CANSDK.VCI_CAN_OBJ(); obj.Init(); obj.RemoteFlag = 0; //数据帧 obj.ExternFlag = 1; //扩展帧 obj.SendType = 0; //正常发送 obj.ID = uint.Parse("181E" + slaveId + "41", System.Globalization.NumberStyles.HexNumber); //obj.Data = DataConverter.str2ASCII(g.TraceCode.Substring(0, 8)); obj.DataLen = 8; byte[] b = new byte[8]; //b[1] =(byte)( g.Realy2 == true ? 1 : 0); b[0] = (byte)((g.Realy2 == true ? 1 : 0) << 1 | 0x00); System.DateTime currentTime = new System.DateTime(); currentTime = System.DateTime.Now; int year = currentTime.Year; int month = currentTime.Month; int day = currentTime.Day; int hour = currentTime.Hour; int minute = currentTime.Minute; int second = currentTime.Second; b[1] = DataConverter.strToHexByte((year - 2000).ToString())[0]; b[2] = DataConverter.strToHexByte(month.ToString())[0]; b[3] = DataConverter.strToHexByte(day.ToString())[0]; b[4] = DataConverter.strToHexByte(hour.ToString())[0]; b[5] = DataConverter.strToHexByte(minute.ToString())[0]; b[6] = DataConverter.strToHexByte(second.ToString())[0]; b[7] = (byte)Convert.ToInt32(g.CanLife); obj.Data = b; // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2")); CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1); }
//发送追溯码 public void sendTraceCodePack(Object o) { ArrayList al = (ArrayList)o; string slaveId = Convert.ToString(al[0]); Gen2SlaveConfig g = (Gen2SlaveConfig)al[1]; if (g.TraceCode == null || g.TraceCode.Length != 24) { flushVM(new Object[] { FunCode.SHOWINFO, "wrongdata" }); return; } CANSDK.VCI_CAN_OBJ obj = new CANSDK.VCI_CAN_OBJ(); obj.Init(); obj.RemoteFlag = 0; //数据帧 obj.ExternFlag = 1; //扩展帧 obj.SendType = 0; //正常发送 obj.ID = uint.Parse("0C22" + slaveId + "7F", System.Globalization.NumberStyles.HexNumber); obj.Data = DataConverter.str2ASCII(g.TraceCode.Substring(0, 8)); obj.DataLen = 8; // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2")); CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1); Thread.Sleep(200); obj.ID = uint.Parse("0C23" + slaveId + "7F", System.Globalization.NumberStyles.HexNumber); obj.Data = DataConverter.str2ASCII(g.TraceCode.Substring(8, 8)); obj.DataLen = 8; // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2")); CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1); Thread.Sleep(200); obj.ID = uint.Parse("0C25" + slaveId + "7F", System.Globalization.NumberStyles.HexNumber); obj.Data = DataConverter.str2ASCII(g.TraceCode.Substring(16, 8)); obj.DataLen = 8; // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2")); CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1); }
//发送config2 public void sendConfig2Pack(Object o) { ArrayList al = (ArrayList)o; string slaveId = Convert.ToString(al[0]); Gen2SlaveConfig g = (Gen2SlaveConfig)al[1]; Gen2SlaveInfo gsi = (Gen2SlaveInfo)al[2]; if ((g.Bcnt_a == null || g.Bcnt_a.Equals("")) && (gsi.Bcnt_A != null && !gsi.Bcnt_A.Equals(""))) { g.Bcnt_a = gsi.Bcnt_A; } if ((g.Bcnt_b == null || g.Bcnt_b.Equals("")) && (gsi.Bcnt_B != null && !gsi.Bcnt_B.Equals(""))) { g.Bcnt_b = gsi.Bcnt_B; } if ((g.Bcnt_c == null || g.Bcnt_c.Equals("")) && (gsi.Bcnt_C != null && !gsi.Bcnt_C.Equals(""))) { g.Bcnt_c = gsi.Bcnt_C; } if ((g.Bcnt_d == null || g.Bcnt_d.Equals("")) && (gsi.Bcnt_D != null && !gsi.Bcnt_D.Equals(""))) { g.Bcnt_d = gsi.Bcnt_D; } if ((g.Bcnt_e == null || g.Bcnt_e.Equals("")) && (gsi.Bcnt_E != null && !gsi.Bcnt_E.Equals(""))) { g.Bcnt_e = gsi.Bcnt_E; } if ((g.Bcnt_f == null || g.Bcnt_f.Equals("")) && (gsi.Bcnt_F != null && !gsi.Bcnt_F.Equals(""))) { g.Bcnt_f = gsi.Bcnt_F; } if ((g.MaxCharge == null || g.MaxCharge.Equals("")) && (gsi.MaxChargeCur != null && !gsi.MaxChargeCur.Equals(""))) { g.MaxCharge = gsi.MaxChargeCur.Replace("A", String.Empty); } if (!(DataConverter.canStirng2int(g.Bcnt_a) && DataConverter.canStirng2int(g.Bcnt_b) && DataConverter.canStirng2int(g.Bcnt_c) && DataConverter.canStirng2int(g.Bcnt_d) && DataConverter.canStirng2int(g.Bcnt_e) && DataConverter.canStirng2int(g.Bcnt_f) && DataConverter.canStirng2double(g.MaxCharge))) { flushVM(new Object[] { FunCode.SHOWINFO, "wrongdata" }); return; } CANSDK.VCI_CAN_OBJ obj = new CANSDK.VCI_CAN_OBJ(); obj.Init(); obj.RemoteFlag = 0; //数据帧 obj.ExternFlag = 1; //扩展帧 obj.SendType = 0; //正常发送 obj.ID = uint.Parse("0C24" + slaveId + "7F", System.Globalization.NumberStyles.HexNumber); byte[] b = new byte[8]; b[0] = (byte)Convert.ToInt32(g.Bcnt_a); b[1] = (byte)Convert.ToInt32(g.Bcnt_b); b[2] = (byte)Convert.ToInt32(g.Bcnt_c); b[3] = (byte)Convert.ToInt32(g.Bcnt_d); b[4] = (byte)Convert.ToInt32(g.Bcnt_e); b[5] = (byte)Convert.ToInt32(g.Bcnt_f); short d = (short)(Convert.ToInt32(g.MaxCharge) * 10); byte[] t = System.BitConverter.GetBytes(d); b[6] = t[0]; b[7] = t[1]; obj.Data = b; obj.DataLen = 8; // Console.WriteLine("发送:" + DataConverter.byteToHexStrForData(obj.Data).Substring(0, 2 * obj.DataLen) + ",ID:" + obj.ID.ToString("X2")); CANSDK.VCI_Transmit(CANSDK.m_devtype, CANSDK.m_devind, CANSDK.m_canind, ref obj, 1); flushVM(new Object[] { FunCode.SHOWINFO, "sendSuc" }); }