#include "msw.h" #include #include "../../I8120Lib/ver_106/I8120.h" typedef struct { unsigned char Mode; unsigned char RTR; unsigned char DataLen; unsigned char Data[8]; unsigned long MsgID; unsigned long UpperTimeStamp; unsigned long LowerTimeStamp; }PacketStruct; int Kbhit(void){ int n; ioctl(0,FIONREAD,&n); return n; } int main(void) { char CANRegStatus,OverFlowStatus,OldCANRegStatus=0,OldOverFlowStatus=0; int Ret,SlotNo,i,Temp; PacketStruct RxMsg; //Select the slot where the I-8120 is plugged. printf("Input the slot (1~7) where the I-8120 is plugged."); scanf("%d",&SlotNo); if (SlotNo<1 || SlotNo>7){ printf("Slot number error, default to slot 1.\n"); SlotNo=1; } Ret = Open_Slot(SlotNo); if (Ret > 0) { printf("open Slot failed!\n"); return (-1); } printf("Baud is set to 125K\n"); //Initiate the I-8120 module Ret=I8120Init(SlotNo,125000L,0,0,0x00000000L,0xffffffffL); if (Ret){ printf("Init error Code=%d\n",Ret); return (-1); } printf("Start to receive CAN messages.(press Enter key to exit...)\n"); while(!Kbhit()){ //Get CAN Message Ret=GetCANMsg(SlotNo,&RxMsg.Mode,&RxMsg.MsgID,&RxMsg.RTR,&RxMsg.DataLen,RxMsg.Data, &RxMsg.UpperTimeStamp,&RxMsg.LowerTimeStamp); if (Ret){ if (Ret!=CAN8K_FIFO_EMPTY){ printf("Receive Message Error, Error Code=%d.\n",Ret); break; } } else{ if (RxMsg.RTR){ printf("%s,ID=%lx,RTR=%d,Dlen=%d\n", RxMsg.Mode?"2.0B":"2.0A",RxMsg.MsgID,RxMsg.RTR,RxMsg.DataLen); } else{ printf("%s,ID=%lx,RTR=%d,Dlen=%d", RxMsg.Mode?"2.0B":"2.0A",RxMsg.MsgID,RxMsg.RTR,RxMsg.DataLen); if (RxMsg.DataLen>0){ printf(",Data="); for (i=0;i