/* 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\7188el.lib Hardware: 7188EX + 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\7188e.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("\n\r"); Print("****************************************\n\r"); Print("| 7188EX + X505 |\n\r"); Print("****************************************\n\r"); while(iAction!=4) { quit=0; Print("\n\r"); Print("1) Test COM3 (5-wire RS-232)\n\r"); Print("2) Test COM4 (5-wire RS-232)\n\r"); Print("3) Test COM5 (5-wire RS-232)\n\r"); Print("\n\r"); Print("4) Quits Demo program\n\r\n\r"); Print("Choose an option and press [Enter]:"); iAction=0; Scanf("%d",&iAction); switch(iAction) { // FOR COM3 case 1: for(;;) { Print("\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("%d", &iValue); switch(iValue) { case 1: Print("\n\r"); Print("Send & Receive data to/from COM1\n\r"); 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("\n\r"); Print("Input 0 or 1? "); Scanf("%d", &iValue); if(iValue) SetRtsActive_3(); else SetRtsInactive_3(); Print("\n\rThe RTS status is %d\n\r", iValue); break; case 3: Print("\n\rCTS status of COM3 is:%d\n\r", GetCtsStatus_3()); break; case 4: quit=1; break; default: break; } if(quit==1) break; else { Print("\n\rPress any key to continue...\n\r"); Getch(); } } break; // FOR COM4 case 2: for(;;) { Print("\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 COM4 test\n\r"); Print("Choose an option:"); Scanf("%d", &iValue); switch(iValue) { case 1: Print("\n\r"); Print("Send & Receive data to/from COM1\n\r"); 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\n\r"); else Print("Send COM4 <==> Receiv COM4 -->Test error\n\r"); break; case 2: Print("\n\r"); Print("Input 0 or 1? "); Scanf("%d", &iValue); if(iValue) SetRtsActive_4(); else SetRtsInactive_4(); Print("\n\rThe RTS status is %d\n\r", iValue); break; case 3: Print("\n\rCTS status of COM4 is:%d\n\r", GetCtsStatus_4()); break; case 4: quit=1; break; default: break; } if(quit==1) break; else { Print("\n\rPress any key to continue...\n\r"); Getch(); } } break; // FOR COM5 case 3: for(;;) { Print("\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 COM5 test\n\r"); Print("Choose an option:"); Scanf("%d", &iValue); switch(iValue) { case 1: Print("\n\rSend & Receive data to/from COM1\n\r"); 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\n\r"); else Print("Send COM5 <==> Receiv COM5 -->Test error\n\r"); break; case 2: Print("\n\r"); Print("Input 0 or 1? "); Scanf("%d", &iValue); if(iValue) SetRtsActive_5(); else SetRtsInactive_5(); Print("\n\rThe RTS status is %d\n\r", iValue); break; case 3: Print("\n\rCTS status of COM5 is:%d\n\r", GetCtsStatus_5()); break; case 4: quit=1; break; default: break; } if(quit==1) break; else { Print("\n\rPress any key to continue...\n\r"); Getch(); } } break; case 4: quit=1; RestoreCom(3); RestoreCom(4); RestoreCom(5); break; default : break; } if(quit!=1){ Print("\n\rPress any key to continue...\n\r"); Getch(); } } }