void GetErrorInfo() { CAN_ERR_INFO errorInfo = new CAN_ERR_INFO(); ECANStatus readErrResult = ECANDLL.ReadErrInfo(deviceType, useCANIndex, useCANIndex, out errorInfo); if (readErrResult != ECANStatus.STATUS_OK) { Logger.logError("无法读取CAN错误!"); return; } if (errorInfo.ErrCode == 0) { Logger.logError("存在未知CAN错误!"); } else { Logger.logError("存在以下CAN错误:"); Logger.print("------------ECAN错误开始------------"); foreach (uint errKey in errExplain.Keys) { if ((errKey & errorInfo.ErrCode) > 0) { Logger.print(errExplain[errKey]); } } Logger.print("------------ECAN错误结束------------"); } }
private void sendMsg(CAN_OBJ frameinfo, CanDataWithInfo bi) { if (ECANDLL.Transmit(4, 0, 0, ref frameinfo, (ushort)1) != ECANStatus.STATUS_OK) { Console.WriteLine("Transmit : fault"); ERR_INFO info = new ERR_INFO(); if (ECANDLL.ReadErrInfo(4, 0, 0, out info) != ECANStatus.STATUS_OK) { Console.WriteLine("ReadErrInfo : fault"); } else { Console.WriteLine("ReadErrInfo : code " + info.ErrCode); } } else { //写入文件记录 //logger.Info(Untils.ToHexString(frameinfo.data) + bi.info); eventSended?.Invoke(this, new ByteEventArgs(DateTime.Now, new BytesWithInfo(frameinfo.data, bi.info))); } }
public bool ReadErrorInfo(out CAN_ERR_INFO info) { return(ECANStatus.STATUS_OK == ECANDLL.ReadErrInfo(DefaultDeviceType, 0, 0, out info)); }