#include "..\..\..\MCU_Lib\8000e.h" #include "..\..\..\I8120Lib\ver_100\I8120.h" typedef struct { unsigned char Mode; unsigned char RTR; unsigned char DataLen; unsigned char Data[8]; unsigned long ID; unsigned long UpperTime; unsigned long LowerTime; }PacketStruct; void main(void) { unsigned char CANRegStatus,OverFlowStatus,OldCANRegStatus=0,OldOverFlowStatus=0; int Ret,SlotNo,i; PacketStruct RxMsg; //Initiate host InitLib(); //Select the slot where the I-8120 is plugged. Print("Input the slot (0~3) where the I-8120 is plugged."); Scanf("%d",&SlotNo); if (SlotNo<0 || SlotNo>7){ Print("Slot number error, default to slot 0.\n\r"); SlotNo=0; } //Initiate the I-8120 module Ret=I8120Init(SlotNo,125000UL,0,0,0x00000000UL,0xffffffffUL); if (Ret){ Print("Initiate I-8120 error, error code=%d\n\r",Ret); return; } Print("Baud is set to 125K\n\r"); Print("Start to receive CAN messages.(any key to exit...)\n\r"); while(!Kbhit()){ //Get CAN Message Ret=GetCANMsg(SlotNo,&RxMsg.Mode,&RxMsg.ID,&RxMsg.RTR,&RxMsg.DataLen,RxMsg.Data,&RxMsg.UpperTime,&RxMsg.LowerTime); if (Ret){ if (Ret!=CAN8K_FIFO_EMPTY){ Print("Receive Message Error, Error Code=%d.\n\r",Ret); break; } } else{ if (RxMsg.RTR){ Print("%s,ID=%lx,RTR=%d,Dlen=%d\n\r", RxMsg.Mode?"2.0B":"2.0A",RxMsg.ID,RxMsg.RTR,RxMsg.DataLen); } else{ Print("%s,ID=%lx,RTR=%d,Dlen=%d", RxMsg.Mode?"2.0B":"2.0A",RxMsg.ID,RxMsg.RTR,RxMsg.DataLen); if (RxMsg.DataLen>0){ Print(",Data="); for (i=0;i