/// <summary> /// 处理闭合查询错误回告 /// </summary> public IEnumerable <TestBox> ProcessCloseCheckForFalse() { List <TestBox> boxes = new List <TestBox>(); if (receiveData[7].Count != 0) { CAN_MSG_T msg = receiveData[7].Dequeue(); if (msg.data[2] == 0x01) { for (int i = 0; i < 3; i++) { TestBox box = new TestBox(msg.data[0] & 0x0f, msg.data[4 + i]); boxes.Add(box); } } else { for (int i = 0; i < 4; i++) { TestBox box = new TestBox(msg.data[0] & 0x0f, msg.data[3 + i]); boxes.Add(box); } } return(boxes); } return(null); }
/// <summary> /// 处理真值表错误信息反馈 /// </summary> public Tuple <byte, byte[]> ProcessTruthTableForFalse() { if (receiveData[9].Count != 0) { CAN_MSG_T msg = receiveData[9].Dequeue(); return(Tuple.Create <byte, byte[]>((byte)(msg.data[0] & 0x0f), new byte[4] { msg.data[3], msg.data[4], msg.data[5], msg.data[6] })); } return(null); }
/// <summary> /// 处理故障终止指令 /// </summary> public bool ProcessFaultEnd() { if (receiveData[14].Count != 0) { CAN_MSG_T msg = receiveData[14].Dequeue(); if (msg.data[1] == 0xCC) { return(true); } } return(false); }
/// <summary> /// 处理程序停止指令 /// </summary> public bool ProcessStopApplication() { if (receiveData[10].Count != 0) { CAN_MSG_T msg = receiveData[10].Dequeue(); if (msg.data[1] == 0xC8) { return(true); } } return(false); }
/// <summary> /// 发送握手指令 /// </summary> public int SendShakehand(uint deviceId) { CAN_MSG_T msg = new CAN_MSG_T(); msg.rtr = 0; msg.dlen = 2; msg.id = deviceId; msg.data = new byte[8]; msg.data[0] = (byte)(0x10 + deviceId & 0x0F); msg.data[1] = InstructNum; return(CanBusApi.CANWriteFile(m_nPort, ref ready, ref msg)); }
/// <summary> /// 开启监听Can总线的线程 /// </summary> public void BeginListen() { ThreadPool.QueueUserWorkItem(o => { CAN_MSG_T cMsg = new CAN_MSG_T(); cMsg.data = new byte[8]; int returnNum = 0; CanBusApi.CANReadFile(m_nPort, 1, ref cMsg, ref returnNum); if (returnNum > 0) { receiveData[(cMsg.data[0] >> 4) - 1].Enqueue(cMsg); } }); }
/// <summary> /// 处理24V控制指令回告指令 /// </summary> public byte Process24VCtrl(byte serialNum, byte packageNum) { if (receiveData[1].Count != 0) { CAN_MSG_T msg = receiveData[1].Dequeue(); if (msg.data[1] == serialNum && msg.data[2] == packageNum) { return(msg.data[3]); } else { return(0); } } return(0); }
/// <summary> /// 处理握手状态检测回告指令 /// </summary> public byte ProcessShakehand(byte serialNum) { if (receiveData[0].Count != 0) { CAN_MSG_T msg = receiveData[0].Dequeue(); if (msg.data[1] == serialNum) { return(msg.data[2]); } else { return(0); } } return(0); }
/// <summary> /// 处理测试类型指令回告 /// </summary> public byte ProcessSelectTestType(byte type) { if (receiveData[12].Count != 0) { CAN_MSG_T msg = receiveData[12].Dequeue(); if (msg.data[1] == type) { return(msg.data[2]); } else { return(0); } } return(0); }
/// <summary> /// 处理真值表正确信息反馈 /// </summary> public byte ProcessTruthTableForTrue(byte serialNum) { if (receiveData[8].Count != 0) { CAN_MSG_T msg = receiveData[8].Dequeue(); if (msg.data[1] == serialNum) { return(msg.data[2]); } else { return(0); } } return(0); }
/// <summary> /// 初始化24V控制指令 /// </summary> public Queue <CAN_MSG_T> Init24VCtrl(List <TestBox> inputPts) { Queue <CAN_MSG_T> instructs = new Queue <CAN_MSG_T>(); ILookup <int, TestBox> lookupPts = inputPts.ToLookup(p => p.BoxNum); CAN_MSG_T msgtemp = new CAN_MSG_T(); msgtemp.rtr = 0; msgtemp.dlen = 8; msgtemp.data = new byte[8]; for (int i = 1; i <= 6; i++) { /*同一块控制板上注入点的总个数*/ int ptsCount = lookupPts[i].Count(p => true); /*电压点号*/ Queue <int> pts = new Queue <int>(); foreach (var pt in lookupPts[i]) { pts.Enqueue(pt.TestBoxPort); } /*同一块控制板的指令包个数*/ byte msgNum = (byte)(ptsCount <= 3 ? 1 : ((ptsCount - 2) / 4) + 1); if (ptsCount > 0) { /*第一包*/ CAN_MSG_T msg = msgtemp; msg.id = (byte)(lookupPts[i].First().BoxNum + 0x80); msg.data[0] = (byte)(0x20 + lookupPts[i].First().BoxNum); msg.data[1] = InstructNum; msg.data[2] = 1; msg.data[3] = msgNum; for (int j = 0; j < 3; j++) { if (pts.Count > 0) { byte num = (byte)pts.Dequeue(); msg.data[j + 4] = num; } else { msg.data[j + 4] = 0xEF; } } /*校验码*/ msg.data[7] = (byte)(msg.data[1] ^ msg.data[2] ^ msg.data[3] ^ msg.data[4] ^ msg.data[5] ^ msg.data[6]); instructs.Enqueue(msg); } /*其余几包*/ for (int j = 1; j < msgNum; j++) { CAN_MSG_T msg = msgtemp; msg.id = (byte)(lookupPts[i].First().BoxNum + 0x80); msg.data[0] = (byte)(0x20 + lookupPts[i].First().BoxNum); msg.data[1] = InstructNum; msg.data[2] = (byte)(j + 1); for (int k = 0; k < 4; k++) { if (pts.Count > 0) { byte num = (byte)pts.Dequeue(); msg.data[k + 3] = num; } else { msg.data[k + 3] = 0xEF; } } msg.data[7] = (byte)(msg.data[1] ^ msg.data[2] ^ msg.data[3] ^ msg.data[4] ^ msg.data[5] ^ msg.data[6]); instructs.Enqueue(msg); } } return(instructs); }