/* X518Demo.c: Demo program for X518 Compiler: MSC 6.0 MSVC 1.52 Compile mode: large Project: X518Demo.c ..\..\Lib\7188xbl.lib ..\..\lib\Xboard\X518.lib Hardware: 7188XB + X518 X518: Digital Output: 8 Channels COM3 (5-wire RS-232) [15/July/2005] by Liam */ #include #include #include #include #include "..\..\lib\7188xb.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; char buf[100]; InitLib(); X518_Init(); //Initialize the X518 Print("\r\n"); Print("****************************************\r\n"); Print("| 7188XB + X518 |\r\n"); Print("****************************************\r\n"); while(iAction!=6) { iAction=0; quit=0; Puts("\r\n"); Puts("1) Write DO (all channels)\r\n"); Puts("2) Write DO (one channel)\r\n"); Puts("3) DO Readback (all channels)\r\n"); Puts("4) DO Readback (one channel)\r\n"); Puts("5) Test COM3 (5-wire RS-232)\r\n"); Puts("\r\n"); Puts("6) Quits Demo program\r\n\r\n"); Puts("Choose an option and press [Enter]:"); LineInput(buf, 99); sscanf(buf, "%d", &iAction); Puts("\r\n"); switch(iAction) { // Write DO (all channels) case 1: Print("Please input Output value(0 ~ 0x00ff): "); LineInput(buf, 99); sscanf(buf, "%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)\r\n"); Print("Channel number and status:"); LineInput(buf, 99); sscanf(buf, "%d %d", &iOutChannel, &iStatus); if(iOutChannel>7) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } 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): "); LineInput(buf,99); sscanf(buf, "%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: // FOR COM3 InstallCom3(115200L, 8, 0, 1); for(;;) { cValue=0x00; quit=0; Puts("\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("4) Quit COM3 test\r\n"); Print("Choose an option:"); LineInput(buf, 99); sscanf(buf, "%c", &cValue); Print("\r\n"); switch(cValue) { case '1': Print("Enter a string to COM port:"); LineInput(buf, 99); sscanf(buf, "%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("Input 0 or 1?\r\n"); LineInput(buf, 99); sscanf(buf, "%d", &cValue); if(cValue) SetRtsActive_3(); else SetRtsInactive_3(); Print("The RTS status is %d\r\n", cValue); break; case '3': Print("CTS status of COM3 is:%d\r\n", 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(); } } }