#include "..\..\..\MCU_Lib\8000.h" #include "..\..\..\87CANLib\ver_103\I87KCAN.h" typedef struct { unsigned char Mode; unsigned char RTR; unsigned char DataLen; unsigned char Data[8]; unsigned long ID; }PacketStruct; void main(void) { unsigned char CANRegStatus,OverFlowStatus,OldCANRegStatus=0,OldOverFlowStatus=0; int Ret,SlotNo,i; PacketStruct RxMsg; //Initiate host InitLib(); //Open COM 0 InstallCom0(115200UL,8,0,1); //Select the slot where the I-87KCAN is plugged. Print("Input the slot (0~7) where the I-87KCAN is plugged."); Scanf("%d",&SlotNo); if (SlotNo<0 || SlotNo>7){ Print("Slot number error, default to slot 0.\n\r"); SlotNo=0; } Print("Baud is set to 125K\n\r"); ChangeToSlot(SlotNo); //Initiate the I-87KCAN module I87KCANInit(125000UL,0,0,0x00000000UL,0xffffffffUL,0,0); Print("Start to receive CAN messages.(any key to exit...)\n\r"); while(!Kbhit()){ //Get CAN Message Ret=GetCANMsg(&RxMsg.Mode,&RxMsg.ID,&RxMsg.RTR,&RxMsg.DataLen,RxMsg.Data); if (Ret){ if (Ret!=CAN87K_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