public void SendCommunicationMessage(byte[] bytes, List <UpdateInformation> infoList, object lockobj) { int nFrameLen = 0; if ((bytes.Length) % 8 == 0) { nFrameLen = (bytes.Length) / 8; } else { nFrameLen = (bytes.Length) / 8 + 1; } m_bIsSendMultiFrame = true; int nSendIndex = 0; for (int n = nFrameLen; n > 0; n--) { byte[] byteCmdBuf = new byte[8]; if (nSendIndex + 8 > bytes.Length) { Buffer.BlockCopy(bytes, nSendIndex, byteCmdBuf, 0, (bytes.Length - nSendIndex)); } else { Buffer.BlockCopy(bytes, nSendIndex, byteCmdBuf, 0, 8); } uint BqProtID = (uint)(BqProtocolID | (n - 1)); DataLinkLayer.SendCanFrame(BqProtID, byteCmdBuf); nSendIndex += 8; UpdateInformation info = new UpdateInformation(); info.DirectionStr = "发送"; info.Length = byteCmdBuf.Length.ToString(); info.TimeStr = DateTime.Now.ToString("MM/dd HH:mm:ss") + string.Format(":{0}", DateTime.Now.Millisecond); info.ID = string.Format("0x{0}", BqProtID.ToString("X")); info.Content = BitConverter.ToString(byteCmdBuf); if (nFrameLen > 1) { info.Comments = string.Format("多帧第{0}帧,共{1}帧", nFrameLen - n + 1, nFrameLen); } else { info.Comments = string.Format("第{0}帧,共{1}帧", nFrameLen - n + 1, nFrameLen); } lock (lockobj) { infoList.Add(info); } } m_bIsSendMultiFrame = false; }
public void EraseDidiRecord() { byte[] rdBuf = new byte[] { m_bSourceAddress, 0x03, 0xDD, 0xBD, 0x00, 0x06, 0x00, 0x00 }; byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2); rdBuf[rdBuf.Length - 2] = crc16[1]; rdBuf[rdBuf.Length - 1] = crc16[0]; byte[] cmdBuf = new byte[6]; Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, rdBuf.Length - 2); DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf); }
public void ReadDidiCurrentRecordData() { byte[] rdBuf = new byte[] { m_bSourceAddress, 0x03, 0xCC, 0xA4, 0x00, 0x08, 0x00, 0x02, 0x00, 0x00 }; byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2); rdBuf[rdBuf.Length - 2] = crc16[1]; rdBuf[rdBuf.Length - 1] = crc16[0]; byte[] cmdBuf = new byte[8]; Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, rdBuf.Length - 2); DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf); }
public void DD_ReleyEvent() { byte[] Buf = new byte[] { m_bSourceAddress, 0x03, 0x46, 0x02, 0x00, 0x00, 0x00, 0x00 }; byte[] crc16 = CRC_Check.CRC16(Buf, 0, Buf.Length - 2); Buf[Buf.Length - 2] = crc16[1]; Buf[Buf.Length - 1] = crc16[0]; byte[] cmdBuf = new byte[6]; Buffer.BlockCopy(Buf, 2, cmdBuf, 0, 6); DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf); }
public void DD_SettingBrakeStatus(byte status) { byte[] Buf = new byte[] { m_bSourceAddress, 0x03, 0x10, 0xA2, 0x68, 0x01, status, 0x00, 0x00, 0x00 }; byte[] crc16 = CRC_Check.CRC16(Buf, 0, Buf.Length - 2); Buf[Buf.Length - 2] = crc16[1]; Buf[Buf.Length - 1] = crc16[0]; byte[] cmdBuf = new byte[8]; Buffer.BlockCopy(Buf, 2, cmdBuf, 0, 8); DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf); }
public void DD_ReadFeedbackInfo() { byte[] rdBuf = new byte[] { m_bSourceAddress, 0x03, 0x03, 0xA2, 0xA0, 0x03, 0x00, 0x00 }; byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2); rdBuf[rdBuf.Length - 2] = crc16[1]; rdBuf[rdBuf.Length - 1] = crc16[0]; byte[] cmdBuf = new byte[6]; Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, rdBuf.Length - 2); DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf); }
public void DD_PowerOff() { byte[] poBuf = new byte[] { m_bSourceAddress, 0x03, 0x10, 0xA2, 0x00, 0x01, 0x00, 0x00, 0x5A, 0xE9 }; byte[] crc16 = CRC_Check.CRC16(poBuf, 0, poBuf.Length - 2); poBuf[poBuf.Length - 2] = crc16[1]; poBuf[poBuf.Length - 1] = crc16[0]; byte[] cmdBuf = new byte[8]; Buffer.BlockCopy(poBuf, 2, cmdBuf, 0, 8); DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf); }
private void CheckConnectReadSOH() { byte[] rdBuf = new byte[] { m_bSourceAddress, 0x03, 0x03, 0xA2, 0x00, 0x01, 0x00, 0x00 }; byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2); rdBuf[rdBuf.Length - 2] = crc16[1]; rdBuf[rdBuf.Length - 1] = crc16[0]; byte[] cmdBuf = new byte[6]; Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, 6); DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf); }
public void SendMultiFrame(byte[] dataBuf, int len, byte nCmd) { byte[] cmdBuf = new byte[len + 8]; cmdBuf[0] = m_bSourceAddress; cmdBuf[1] = 0x03; cmdBuf[2] = 0xDD; cmdBuf[3] = nCmd; byte[] lenBuf = BitConverter.GetBytes((short)cmdBuf.Length - 2); cmdBuf[4] = lenBuf[1]; cmdBuf[5] = lenBuf[0]; Buffer.BlockCopy(dataBuf, 0, cmdBuf, 6, len); byte[] crc16 = CRC_Check.CRC16(cmdBuf, 0, cmdBuf.Length - 2); cmdBuf[cmdBuf.Length - 2] = crc16[1]; cmdBuf[cmdBuf.Length - 1] = crc16[0]; int nFrameLen = 0; if ((cmdBuf.Length - 2) % 8 == 0) { nFrameLen = (cmdBuf.Length - 2) / 8; } else { nFrameLen = (cmdBuf.Length - 2) / 8 + 1; } m_bIsSendMultiFrame = true; int nSendIndex = 2; for (int n = nFrameLen; n > 0; n--) { byte[] byteCmdBuf = new byte[8]; if (nSendIndex + 8 > cmdBuf.Length) { Buffer.BlockCopy(cmdBuf, nSendIndex, byteCmdBuf, 0, (cmdBuf.Length - nSendIndex)); } else { Buffer.BlockCopy(cmdBuf, nSendIndex, byteCmdBuf, 0, 8); } uint BqProtID = (uint)(BqProtocolID | (n - 1)); DataLinkLayer.SendCanFrame(BqProtID, byteCmdBuf); nSendIndex += 8; Thread.Sleep(5); } m_bIsSendMultiFrame = false; }
private void SendSingleFrameData(byte[] rdBuf) { byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2); rdBuf[rdBuf.Length - 2] = crc16[1]; rdBuf[rdBuf.Length - 1] = crc16[0]; byte[] cmdBuf = new byte[rdBuf.Length - 2]; Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, rdBuf.Length - 2); DataLinkLayer.SendCanFrame(BqProtocolID, cmdBuf); bReadBqBmsResp = false; }
public void DD_ReadRegister(byte[] addr, byte num) { byte[] rdBuf = new byte[] { m_bSourceAddress, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }; Buffer.BlockCopy(addr, 0, rdBuf, 3, addr.Length); rdBuf[addr.Length + 3] = num; byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2); rdBuf[rdBuf.Length - 2] = crc16[1]; rdBuf[rdBuf.Length - 1] = crc16[0]; byte[] cmdBuf = new byte[6]; Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, rdBuf.Length - 2); DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf); }
public void Didi_ReadRTC() { if (m_bIsStopCommunication) { return; } byte[] rdBuf = new byte[] { m_bSourceAddress, 0x03, 0x03, 0xA2, 0x48, 0x02, 0x00, 0x00 }; byte[] crc16 = CRC_Check.CRC16(rdBuf, 0, rdBuf.Length - 2); rdBuf[rdBuf.Length - 2] = crc16[1]; rdBuf[rdBuf.Length - 1] = crc16[0]; byte[] cmdBuf = new byte[6]; Buffer.BlockCopy(rdBuf, 2, cmdBuf, 0, rdBuf.Length - 2); DataLinkLayer.SendCanFrame(DidiProtocolID, cmdBuf); }
public void SendMultiFrame(byte[] dataBuf, int len) { int nFrameLen = 0; if ((dataBuf.Length) % 8 == 0) { nFrameLen = (dataBuf.Length) / 8; } else { nFrameLen = (dataBuf.Length) / 8 + 1; } int nSendIndex = 0; for (int n = nFrameLen; n > 0; n--) { byte[] byteCmdBuf; if (nSendIndex + 8 > dataBuf.Length) { byteCmdBuf = new byte[dataBuf.Length - nSendIndex]; Buffer.BlockCopy(dataBuf, nSendIndex, byteCmdBuf, 0, (dataBuf.Length - nSendIndex)); } else { byteCmdBuf = new byte[8]; Buffer.BlockCopy(dataBuf, nSendIndex, byteCmdBuf, 0, 8); } uint ProtID = (uint)(DidiProtocolID | (n - 1)); DataLinkLayer.SendCanFrame(ProtID, byteCmdBuf); nSendIndex += 8; Thread.Sleep(5); } }
public void SendUpdateAppMultiFrame(byte[] dataBuf, int len, byte nCmd, List <UpdateInformation> queue, bool isAddQueue, object lockobj) { byte[] cmdBuf = new byte[len + 8]; cmdBuf[0] = m_bSourceAddress; cmdBuf[1] = 0x03; cmdBuf[2] = 0x45; cmdBuf[3] = nCmd; byte[] lenBuf = BitConverter.GetBytes((short)len); cmdBuf[4] = lenBuf[1]; cmdBuf[5] = lenBuf[0]; Buffer.BlockCopy(dataBuf, 0, cmdBuf, 6, len); byte[] crc16 = CRC_Check.CRC16(cmdBuf, 0, cmdBuf.Length - 2); cmdBuf[cmdBuf.Length - 2] = crc16[1]; cmdBuf[cmdBuf.Length - 1] = crc16[0]; int nFrameLen = 0; if ((cmdBuf.Length - 2) % 8 == 0) { nFrameLen = (cmdBuf.Length - 2) / 8; } else { nFrameLen = (cmdBuf.Length - 2) / 8 + 1; } m_bIsSendMultiFrame = true; int nSendIndex = 2; for (int n = nFrameLen; n > 0; n--) { byte[] byteCmdBuf = new byte[8]; if (nSendIndex + 8 > cmdBuf.Length) { Buffer.BlockCopy(cmdBuf, nSendIndex, byteCmdBuf, 0, (cmdBuf.Length - nSendIndex)); } else { Buffer.BlockCopy(cmdBuf, nSendIndex, byteCmdBuf, 0, 8); } uint BqProtID = (uint)(BqProtocolID | (n - 1)); DataLinkLayer.SendCanFrame(BqProtID, byteCmdBuf); nSendIndex += 8; //Thread.Sleep(5); if (isAddQueue) { UpdateInformation info = new UpdateInformation(); info.DirectionStr = "发送"; info.Length = byteCmdBuf.Length.ToString(); info.TimeStr = DateTime.Now.ToString("MM/dd HH:mm:ss") + string.Format(":{0}", DateTime.Now.Millisecond); info.ID = string.Format("0x{0}", BqProtID.ToString("X")); info.Content = BitConverter.ToString(byteCmdBuf); if (n == nFrameLen) { if (nCmd == 0x13) { info.Comments = string.Format("根据最新固件信息获取固件状态—多帧第{0}帧,共{1}帧", nFrameLen - n + 1, nFrameLen); } else if (nCmd == 0x15) { uint index = (uint)(dataBuf[4] << 8 | dataBuf[5]); info.Comments = string.Format("第{0}块从机升级包—多帧第{1}帧,共{2}帧", index, nFrameLen - n + 1, nFrameLen); } } else { info.Comments = string.Format("第{0}帧,共{1}帧", nFrameLen - n + 1, nFrameLen); } //queue.Enqueue(info); lock (lockobj) { queue.Add(info); } } } m_bIsSendMultiFrame = false; }