#include "msw.h" #include #include #include "../../I8120Lib/ver_106/I8120.h" int Kbhit(void){ int n; ioctl(0,FIONREAD,&n); return n; } int main(void) { char Mode=1,RTR=0,DataLen=8,Data[8]={0x12,0x23,0x34,0x45,0x56,0x67,0x78,0x89}; int Ret,i,SlotNo; long MsgID=0x12345678L; //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 send CAN messages.(press Enter key to exit...)\n"); while(!Kbhit()){ //Send CAN message per second Ret=SendCANMsg(SlotNo,Mode,MsgID,RTR,DataLen,Data); if (Ret){ printf("Send Message Error, Error Code=%d.\n",Ret); break; } sleep(1); } Close_SlotAll(); RecoverI8120(); printf("Exit Program.\n\r"); return 0; }