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