private void UpdateUIInfo_8Byte(List <byte> listRecv, int nUiIndex) { int nByteIndex_8 = (ListBmsInfo[nUiIndex].Address - nStartAddr) * 2; if (0xA238 == ListBmsInfo[nUiIndex].Address) { byte[] byteArrStat = new byte[ListBmsInfo[nUiIndex].RegisterNum * 2]; string strStat = null; for (int n = 0; n < byteArrStat.Length; n++) { byteArrStat[n] = listRecv[nByteIndex_8 + n]; strStat += byteArrStat[n].ToString("X2") + " "; } isProtect = false; isWarning = false; UpdateBatteryStatusInfo(byteArrStat, listBmsStatusInfo); UpdateBatteryStatusInfo(byteArrStat, listBmsErrInfo); UpdateBatteryStatusInfo(byteArrStat, listBmsWarnInfo); RefreshStatusEvent?.Invoke(this, new EventArgs <List <bool> >(new List <bool>() { isWarning, isProtect })); byte[] byteArrBalance = new byte[2] { byteArrStat[12], byteArrStat[13] }; UpdateBalanceStatus(byteArrBalance); ListBmsInfo[nUiIndex].StrValue = strStat; } else if (0xA240 == ListBmsInfo[nUiIndex].Address) { byte[] byCellType = new byte[ListBmsInfo[nUiIndex].RegisterNum * 2]; for (int i = 0; i < ListBmsInfo[nUiIndex].RegisterNum * 2; i++) { byCellType[i] = listRecv[nByteIndex_8 + i]; } string strVal = System.Text.Encoding.ASCII.GetString(byCellType); strVal = strVal.Substring(0, strVal.IndexOf('\0')); ListBmsInfo[nUiIndex].StrValue = strVal; } else { } }
public void BqUpdateBmsInfo(List <byte> rdBuf) { if (rdBuf[0] != 0xCC || rdBuf[1] != 0xA2) { return; } int len = rdBuf[2] << 8 | rdBuf[3]; if (rdBuf.Count < len) { return; } //byte[] bytes = new byte[len - 2]; //Buffer.BlockCopy(rdBuf.ToArray(), 0, bytes, 0, len - 2); //byte[] crc16 = CRC_Check.CRC16(bytes, 0, len - 2); //if(crc16[0] == rdBuf[len - 1] && crc16[1] == rdBuf[len - 2]) { BqProtocol.bReadBqBmsResp = true; isWarning = false; isProtect = false; nBqByteIndex = 4; UpdateCellInfo(rdBuf); UpdateBmsInfo(rdBuf); UpdateStatusInfo(btPackStatus, m_ListPackStatus); UpdateStatusInfo(btMOSStatus, m_ListMosStatus); UpdateStatusInfo(btVoltageStatus, m_ListVoltageProtectStatus); UpdateStatusInfo(btCurrentStatus, m_ListCurrentProtectStatus); UpdateStatusInfo(btTemperatureStatus, m_ListTemperatureProtectStatus); UpdateStatusInfo(btHumidityStatus, m_ListHumidityProtectStatus); UpdateStatusInfo(btConfigStatus, m_ListConfigStatus); UpdateStatusInfo(btCommunicationStatus, m_ListCommunicationStatus); UpdateStatusInfo(btModeStatus, m_ListModeStatus); UpdateStatusInfo(btLogicStatus, m_ListLogicStatus); Array.Reverse(btHBalanceStatus); UpdateBalanceStatus(btHBalanceStatus, m_ListCellVoltage, true); Array.Reverse(btLBalanceStatus); UpdateBalanceStatus(btLBalanceStatus, m_ListCellVoltage, false); RefreshStatusEvent?.Invoke(this, new EventArgs <List <bool> >(new List <bool>() { isWarning, isProtect })); if (cbSimpleMode.IsChecked == true) { m_ListErrorSysStatus.Clear(); foreach (var item in m_ListSysStatus) { if (item.IsSwitchOn == true) { m_ListErrorSysStatus.Add(item); } } m_ListErrorProtectStatus.Clear(); foreach (var item in m_ListProtectStatus) { if (item.IsSwitchOn == true) { m_ListErrorProtectStatus.Add(item); } } } } }