/* X508Demo.c: Demo program for X508 Compiler: BC++ 3.1, Turbo C ++ 1.01(3.01) (free from http://community.borland.com/museum) Compile mode: large Project: X508Demo.c ..\..\Lib\7188el.lib ..\..\lib\Xboard\X508.lib Hardware: 7188EX + X508 X508: Digital Input : 4 Channels Digital Output: 4 Channels COM3 (5-wire RS-232) [07/July/2005] by Liam */ #include #include #include #include #include "..\..\lib\7188e.h" #include "..\..\lib\Xboard\X508.h" #define BUFSIZE 1024 char InpBuf[BUFSIZE],OutpBuf[BUFSIZE]; void main(void) { int iRet, iAction, i, quit, idata; int iValue, iInChannel, iDIValue, iOutChannel, iDOValue, iStatus; unsigned char cValue; InitLib(); X508_Init(); Print("\n\r"); Print("****************************************\n\r"); Print("| 7188EX + X508 |\n\r"); Print("****************************************\n\r"); while(iAction!=9) { iAction=0; quit=0; Puts("\n\r"); Puts("1) DI and DO test\n\r"); Puts("2) Read DI (all channels)\n\r"); Puts("3) Read DI (one channel)\n\r"); Puts("4) Write DO (all channels)\n\r"); Puts("5) Write DO (one channel)\n\r"); Puts("6) DO Readback (all channels)\n\r"); Puts("7) DO Readback (one channel)\n\r"); Puts("8) Test COM3 (5-wire RS-232)\n\r"); Puts("\n\r"); Puts("9) Quits Demo program\n\r\n\r"); Puts("Choose an option and press [Enter]:"); Scanf("%d",&iAction); Puts("\n\r"); switch(iAction) { /***********************/ /* DIO test */ /***********************/ /* DO0 <==> DI0 */ /* DO1 <==> DI1 */ /* DO2 <==> DI2 */ /* DO3 <==> DI3 */ /***********************/ case 1: iValue=0; //no error iDOValue=1; outp(0, iDOValue); Delay(10); // DI is normal hi, low active. // When DI is floating or +5V, DI logic is 1 // When DI is GND, DI logic is 0 // When DO is logic 1 ==> DO low // Ch0 iRet=(~inp(0))&0xf; if(iRet!=iDOValue) { Puts("DO0 <==> DI0 error!!!\n\r"); iValue=1; //error } // Ch1~Ch3 for(i=1;i<4;i++) { iDOValue=1< DI%d error!!!\n\r",i,i); iValue=1; //error } } if(iValue==0) Print("DIO testing ok.\n\r\n\r"); Puts("\n\r"); X508_Init(); break; // Read DI (all channels) case 2: iDIValue=X508_Read_All_DI(); Print("Input value=> 0x%02x\r\n\r\n", iDIValue); break; // Read DI (one channel) case 3: Print("Please select inport channel(0~3): "); Scanf("%d", &iInChannel); if(iInChannel>3) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } iDIValue=X508_Read_One_DI(iInChannel); if(iDIValue) Print("Channel %d ==> OFF\r\n\r\n", iInChannel); else Print("Channel %d ==> ON\r\n\r\n", iInChannel); break; // Write DO (all channels) case 4: Print("Please input Output value(0 ~ 0x0f): "); Scanf("%x", &iDOValue); X508_Write_All_DO(iDOValue); Print("Output value=> 0x%02x\r\n\r\n", iDOValue); break; // Write DO (one channels) case 5: Print("Please select outport channel(0~3) and status(0:OFF, 1:ON)\n\r"); Print("Channel number and status:"); Scanf("%d %d", &iOutChannel, &iStatus); if(iOutChannel>3) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } X508_Write_One_DO(iOutChannel, iStatus); Print("Channel %d ==> %s\r\n\r\n", iOutChannel, (iStatus>=1)?"ON":"OFF"); break; // DO Readback (all channels) case 6: iDOValue=X508_Read_All_DO(); Print("Digital Output ReadBack=> 0x%02x\r\n\r\n", iDOValue); break; // DO Readback (one channel) case 7: Print("Please select outport channel(0~3): "); Scanf("%d", &iOutChannel); if(iOutChannel>3) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } iRet=X508_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 8: 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 9: default: quit=1; break; } if(!quit) { Puts("Please press any key to continue...\r\n"); Getch(); } } }