/* X518Demo.c: Demo program for X518 Compiler: BC++ 3.1, Turbo C ++ 1.01(3.01) (free from http://community.borland.com/museum) Compile mode: large Project: X518Demo.c ..\..\Lib\7188el.lib ..\..\lib\Xboard\X518.lib Hardware: 7188EX + X518 X518: Digital Output: 8 Channels COM3 (5-wire RS-232) [15/July/2005] by Liam */ #include #include #include #include #include "..\..\lib\7188e.h" #include "..\..\lib\Xboard\X518.h" #define BUFSIZE 1024 char InpBuf[BUFSIZE],OutpBuf[BUFSIZE]; void main(void) { int iRet, iAction, quit, idata; int iValue, iOutChannel, iDOValue, iStatus; unsigned char cValue; InitLib(); X518_Init(); Print("\n\r"); Print("****************************************\n\r"); Print("| 7188EX + X518 |\n\r"); Print("****************************************\n\r"); while(iAction!=6) { iAction=0; quit=0; Puts("\n\r"); Puts("1) Write DO (all channels)\n\r"); Puts("2) Write DO (one channel)\n\r"); Puts("3) DO Readback (all channels)\n\r"); Puts("4) DO Readback (one channel)\n\r"); Puts("5) Test COM3 (5-wire RS-232)\n\r"); Puts("\n\r"); Puts("6) Quits Demo program\n\r\n\r"); Puts("Choose an option and press [Enter]:"); Scanf("%d",&iAction); Puts("\n\r"); switch(iAction) { // Write DO (all channels) case 1: Print("Please input Output value(0 ~ 0x00ff): "); Scanf("%x", &iDOValue); X518_Write_All_DO(iDOValue); Print("Output value=> 0x%04x\r\n\r\n", iDOValue); break; // Write DO (one channel) case 2: Print("Please select outport channel(0~7) and status(0:OFF, 1:ON)\n\r"); Print("Channel number and status:"); if(iOutChannel>7) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } Scanf("%d %d", &iOutChannel, &iStatus); X518_Write_One_DO(iOutChannel, iStatus); Print("Channel %d ==> %s\r\n\r\n", iOutChannel, (iStatus>=1)?"ON":"OFF"); break; // DO Readback (all channels) case 3: iDOValue=X518_Read_All_DO(); Print("Digital Output ReadBack=> 0x%04x\r\n\r\n", iDOValue); break; // DO Readback (one channel) case 4: Print("Please select outport channel(0~7): "); Scanf("%d", &iOutChannel); if(iOutChannel>7) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } iRet=X518_Read_One_DO(iOutChannel); if(iRet) Print("Channel %d ==> ON\r\n\r\n", iOutChannel); else Print("Channel %d ==> OFF\r\n\r\n", iOutChannel); break; // COM3 TEST case 5: InstallCom3(115200L,8,0,1); for(;;) { cValue=0x00; quit=0; Puts("\n\r"); Print("1) Send & Receive data to/from COM1:\n\r"); Print("2) Set RTS status \n\r"); Print("3) Get CTS status (0: CTS off, 1: CTS ON)\n\r"); Print("4) Quit COM3 test\n\r"); Print("Choose an option:"); Scanf("%c",&cValue); Print("\r\n"); switch(cValue) { case '1': Print("Enter a string to COM port:"); Scanf("%s",&OutpBuf); ToComStr(3,OutpBuf); Delay(2); idata=ReadComn(3,InpBuf,BUFSIZE); InpBuf[idata]=0x0; Print("Read COM port==>%s,idata=%d\r\n",InpBuf,idata); if(!strcmp(OutpBuf,InpBuf)) Print("Send COM3 <==> Receiv COM3 -->Test OK\n\r"); else Print("Send COM3 <==> Receiv COM3 -->Test error\n\r"); break; case '2': Print("Input 0 or 1?\n\r"); Scanf("%d",&cValue); if(cValue) SetRtsActive_3(); else SetRtsInactive_3(); Print("The RTS status is %d\n\r",cValue); break; case '3': Print("CTS status of COM3 is:%d\n\r",GetCtsStatus_3()); break; case '4': default : quit=1; break; } if(!quit) { Puts("\r\nPlease press any key to continue...\r\n"); Getch(); } else if(cValue=='4') break; } RestoreCom3(); break; case 6: default: quit=1; break; } if(!quit) { Puts("Please press any key to continue...\r\n"); Getch(); } } }