/// <summary> /// copy sTCANDATA to sTCAN_MSG /// </summary> /// <param name="sdata"></param> /// <param name="sMessage"></param> public void CopysTDataTosTMsg(sTCANDATA sdata, ref sTCAN_MSG sMessage) { sMessage.m_unMsgID = sdata.m_uDataInfo.m_sCANMsg.m_unMsgID; sMessage.m_ucDataLen = sdata.m_uDataInfo.m_sCANMsg.m_ucDataLen; sMessage.m_ucData = sdata.m_uDataInfo.m_sCANMsg.m_ucData; sMessage.m_ucChannel = sdata.m_uDataInfo.m_sCANMsg.m_ucChannel; sMessage.m_ucEXTENDED = sdata.m_uDataInfo.m_sCANMsg.m_ucEXTENDED; sMessage.m_ucRTR = sdata.m_uDataInfo.m_sCANMsg.m_ucRTR; sMessage.m_bCANFD = sdata.m_uDataInfo.m_sCANMsg.m_bCANFD; }
/** * \param[in] CurrSpyMsg Message polled from the bus in neoVI format * \param[out] sCanData Application specific data format * \param[in] unChannel channel * \return TRUE (always) * * This will classify the messages, which can be one of Rx, Tx or * Error messages. In case of Err messages this identifies under * what broader category (Rx / Tx) does this occur. */ public bool bClassifyMsgType(ref icsSpyMessage CurrSpyMsg, ref sTCANDATA sCanData) { if ((long.Parse(CurrSpyMsg.StatusBitField.ToString()) & long.Parse(VALUECAN_ERROR_BITS.ToString())) > 0) { sCanData.m_ucDataType = ERR_FLAG; } else if ((long.Parse(CurrSpyMsg.StatusBitField.ToString()) & long.Parse(SPY_STATUS_CAN_BUS_OFF.ToString())) > 0) { sCanData.m_ucDataType = ERR_FLAG; } else { //Check for RTR Message if ((long.Parse(CurrSpyMsg.StatusBitField.ToString()) & long.Parse(SPY_STATUS_REMOTE_FRAME.ToString())) > 0) { sCanData.m_ucDataType = RX_FLAG; sCanData.m_uDataInfo.m_sCANMsg.m_ucRTR = 1; } else { sCanData.m_uDataInfo.m_sCANMsg.m_ucRTR = 0; } if ((long.Parse(CurrSpyMsg.StatusBitField.ToString()) & long.Parse(SPY_STATUS_TX_MSG.ToString())) > 0) { sCanData.m_ucDataType = TX_FLAG; } else if ((long.Parse(CurrSpyMsg.StatusBitField.ToString()) & long.Parse(SPY_STATUS_NETWORK_MESSAGE_TYPE.ToString())) > 0) { sCanData.m_ucDataType = RX_FLAG; } // Copy data length sCanData.m_uDataInfo.m_sCANMsg.m_ucDataLen = CurrSpyMsg.NumberBytesData; // Copy the message data sCanData.m_uDataInfo.m_sCANMsg.m_ucData = CurrSpyMsg.Data; // Copy the message ID sCanData.m_uDataInfo.m_sCANMsg.m_unMsgID = (uint)CurrSpyMsg.ArbIDOrHeader; // Check for extended message indication if ((long.Parse(CurrSpyMsg.StatusBitField.ToString()) & long.Parse(SPY_STATUS_XTD_FRAME.ToString())) > 0) { sCanData.m_uDataInfo.m_sCANMsg.m_ucEXTENDED = 1; } else { sCanData.m_uDataInfo.m_sCANMsg.m_ucEXTENDED = 0; } } return(true); }
/// <summary> /// This will receive can message and trans into datagridview type array. /// </summary> public string[] CANRxMsgToString(sTCANDATA sg_asMsgBuffer) { string TypeofControl = ""; string type = "NULL"; switch (sg_asMsgBuffer.m_ucDataType) { case 0x01: type = "Tx"; break; case 0x02: type = "Rx"; break; case 0x04: type = "Error"; break; case 0x08: type = "INTR_FLAG"; break; default: break; } byte[] tmpCAN = new byte[sg_asMsgBuffer.m_uDataInfo.m_sCANMsg.m_ucDataLen]; for (int i = 0; i < sg_asMsgBuffer.m_uDataInfo.m_sCANMsg.m_ucDataLen; i++) { tmpCAN[i] = sg_asMsgBuffer.m_uDataInfo.m_sCANMsg.m_ucData[i]; } string CANData = ArrayToString(tmpCAN); GetFrameType(sg_asMsgBuffer.m_uDataInfo.m_sCANMsg.m_ucData[0]); string ID = sg_asMsgBuffer.m_uDataInfo.m_sCANMsg.m_unMsgID.ToString("X2"); if ((ID != "7E0") && ID != "7E8" && ID != "7DF") { TypeofControl = "----"; } string[] values = { DateTime.Now.ToString("HH:mm:ss.ffff"), type, sg_asMsgBuffer.m_uDataInfo.m_sCANMsg.m_ucChannel.ToString(), TypeofControl, sg_asMsgBuffer.m_uDataInfo.m_sCANMsg.m_unMsgID.ToString("X2"), sg_asMsgBuffer.m_uDataInfo.m_sCANMsg.m_ucDataLen.ToString(), CANData }; return(values); }
/** * \param[in] psCanDataArray Pointer to CAN Message Array of Structures * \param[in] nMessage Maximun number of message to read or size of the CAN Message Array * \param[out] Message Actual Messages Read * \return Returns S_OK if successful otherwise corresponding Error code. * * This function will read multiple CAN messages from the driver. * The other fuctionality is same as single message read. This * will update the variable nMessage with the actual messages * read. */ public int nReadMultiMessage(sTCANDATA[] psCanDataArray, ref int nMessage /* int nChannelIndex*/) { int i = 0; int nReturn = 0; int s_CurrIndex = 0; Int32 s_Messages = 0; Int32 nErrMsg = 0; if (s_CurrIndex == 0) { nReturn = icsneoGetMessages(m_anhObject, s_asSpyMsg, ref s_Messages, ref nErrMsg); } ushort ushRxErr = 0, ushTxErr = 0; if (nErrMsg > 0) { int nErrors = 0; nReturn = icsneoGetErrorMessages(m_anhObject, ref s_anErrorCodes, ref nErrors); if ((nReturn == NEOVI_OK) && (nErrors > 0)) { for (int j = 0; j < nErrors; j++) { switch (s_anErrorCodes[j]) { case 2: //NEOVI_ERROR_DLL_USB_SEND_DATA_ERROR { ++ushTxErr; } break; case 39: // NEOVI_ERROR_DLL_RX_MSG_FRAME_ERR case 40: //NEOVI_ERROR_DLL_RX_MSG_FIFO_OVER case 41: //NEOVI_ERROR_DLL_RX_MSG_CHK_SUM_ERR { ++ushRxErr; } break; default: { // Do nothing until further clarification is received } break; } } } } // End of first level of error message processing // START /* Create the time stamp map. This means getting the local time and assigning * offset value to the QuadPart. */ //UInt64 QuadPartRef = 0; if (CREATE_MAP_TIMESTAMP == sg_byCurrState) { icsSpyMessage CurrSpyMsg = new icsSpyMessage(); CurrSpyMsg = s_asSpyMsg[s_CurrIndex]; double dTimestamp = 0; nReturn = icsneoGetTimeStampForMsg(m_anhObject, ref CurrSpyMsg, ref dTimestamp); if (nReturn == NEOVI_OK) { sg_byCurrState = CALC_TIMESTAMP_READY; nReturn = 1; long g_QueryTickCount; g_QueryTickCount = 0; QueryPerformanceCounter(ref g_QueryTickCount); long unConnectionTimer; unConnectionTimer = ((g_QueryTickCount * 10000) / sg_lnFrequency) - sg_TimeStamp; if ((dTimestamp * 10000) >= unConnectionTimer) { sg_TimeStamp = (long)((dTimestamp * 10000) - unConnectionTimer); } else { sg_TimeStamp = (long)(unConnectionTimer - (dTimestamp * 10000)); } } else { nReturn = -1; } } //End int nLimForAppBuf = nMessage; bool bChannelCnfgrd = false; for (; (i < nLimForAppBuf) && (s_CurrIndex < s_Messages);) { sTCANDATA sCanData = new sTCANDATA(); icsSpyMessage CurrSpyMsg = new icsSpyMessage(); CurrSpyMsg = s_asSpyMsg[s_CurrIndex]; if (true) { bChannelCnfgrd = true; sCanData.m_uDataInfo.m_sCANMsg.m_ucChannel = 0x01; // tbd double dTimestamp = 0; icsneoGetTimeStampForMsg(m_anhObject, ref CurrSpyMsg, ref dTimestamp); sCanData.m_lTickCount = (long)(dTimestamp * 10000); bClassifyMsgType(ref CurrSpyMsg, ref sCanData); psCanDataArray[i] = sCanData; } s_CurrIndex++; if (bChannelCnfgrd) { i++; } } if ((s_CurrIndex == MAX_BUFFER_VALUECAN) || (s_CurrIndex == s_Messages)) { s_CurrIndex = 0; s_Messages = 0; } nMessage = i; return(1); }