/* X502Demo.c: Demo program for X502 Compiler: BC++ 3.1, Turbo C ++ 1.01(3.01) (free from http://community.borland.com/museum) Compile mode: large Project: X502Demo.c ..\..\Lib\7188xcl.lib Hardware: 7188XC + X502 X502: COM3 (5-wire RS-232) COM4 (3-wire RS-232) [14/July/2005] by Liam */ #include #include #include "..\..\lib\7188xc.h" #define BUFSIZE 1024 char OutpBuf[BUFSIZE], InpBuf[BUFSIZE]; void main(void) { int idata, iAction, iValue, quit; InitLib(); InstallCom(3, 115200L, 8, 0, 1); InstallCom(4, 115200L, 8, 0, 1); Print("\r\n"); Print("****************************************\r\n"); Print("| 7188XC + X502 |\r\n"); Print("****************************************\r\n"); while(iAction!=3) { iAction=0; quit=0; Print("\r\n"); Print("1) Test COM3 (5-wire RS-232)\r\n"); Print("2) Test COM4 (3-wire RS-232)\r\n"); Print("\r\n"); Print("3) Quits Demo program\r\n\r\n"); Print("Choose an option and press [Enter]:"); Scanf("%d", &iAction); switch(iAction) { // FOR COM3 case 1: for(;;) { iValue=0; quit=0; Print("\r\n"); Print("1) Send & Receive data to/from COM3:\r\n"); Print("2) Set RTS status \r\n"); Print("3) Get CTS status (0: CTS off, 1: CTS ON)\r\n"); Print("\r\n"); Print("4) Quit COM3 test\r\n"); Print("Choose an option:"); Scanf("%d", &iValue); switch(iValue) { case 1: Print("\r\n"); Print("Send & Receive data to/from COM3\r\n"); 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\r\n"); else Print("Send COM3 <==> Receiv COM3 -->Test error\r\n"); break; case 2: Print("\r\n"); Print("Input 0 or 1? "); Scanf("%d", &iValue); if(iValue) SetRtsActive_3(); else SetRtsInactive_3(); Print("\r\nThe RTS status is %d\r\n", iValue); break; case 3: Print("\r\nCTS status of COM3 is:%d\r\n", GetCtsStatus_3()); break; case 4: default: quit=1; break; } if(!quit==1) { Print("\r\nPress any key to continue...\r\n"); Getch(); } else if(iValue==4) break; } break; // FOR COM4 case 2: Print("\r\n"); Print("Send & Receive data to/from COM4\r\n"); Print("Enter a string to COM port:"); Scanf("%s", &OutpBuf); ToComStr(4, OutpBuf); Delay(2); idata=ReadComn(4, InpBuf, BUFSIZE); InpBuf[idata]=0x0; Print("Read COM port==>%s, idata=%d\r\n", InpBuf, idata); if(!strcmp(OutpBuf,InpBuf)) Print("Send COM4 <==> Receiv COM4 -->Test OK\r\n"); else Print("Send COM4 <==> Receiv COM4 -->Test error\r\n"); break; case 3: quit=1; RestoreCom(3); RestoreCom(4); break; default: quit=1; break; } if(!quit) { Print("\r\nPress any key to continue...\r\n"); Getch(); } } }