/* X507Demo.c: Demo program for X507 Compiler: BC++ 3.1, Turbo C ++ 1.01(3.01) (free from http://community.borland.com/museum) Compile mode: large Project: X507Demo.c ..\..\Lib\7188xbl.lib ..\..\lib\Xboard\X507.lib Hardware: 7188XB + X507 X507: Digital Input : 4 Channels Digital Output: 4 Channels COM3 (RS-422) [14/July/2005] by Liam */ #include #include #include #include #include "..\..\lib\7188xb.h" #include "..\..\lib\Xboard\X507.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(); X507_Init(); //Initialize the X507 Print("\r\n"); Print("****************************************\n\r"); Print("| 7188XB + X507 |\n\r"); Print("****************************************\n\r"); while(iAction!=9) { iAction=0; quit=0; Puts("\r\n"); Puts("1) DI and DO test\r\n"); Puts("2) Read DI (all channels)\r\n"); Puts("3) Read DI (one channel)\r\n"); Puts("4) Write DO (all channels)\r\n"); Puts("5) Write DO (one channel)\r\n"); Puts("6) DO Readback (all channels)\r\n"); Puts("7) DO Readback (one channel)\r\n"); Puts("8) Test COM3 (5-wire RS-232)\r\n"); Puts("\r\n"); Puts("9) Quits Demo program\r\n\r\n"); Puts("Choose an option and press [Enter]:"); Scanf("%d",&iAction); Puts("\r\n"); switch(iAction) { /***********************/ /* DIO test */ /***********************/ /* DO0 <==> DI0 */ /* DO1 <==> DI1 */ /* DO2 <==> DI2 */ /* DO3 <==> DI3 */ /***********************/ case 1: iValue=0; //no error iDOValue=1; X507_Write_All_DO(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=(~X507_Read_All_DI())&0xf; if(iRet!=iDOValue) { Puts("DO0 <==> DI0 error!!!\r\n"); iValue=1; //error } // Ch1~Ch3 for(i=1; i<4; i++) { iDOValue=1< DI%d error!!!\r\n", i, i); iValue=1; //error } } if(iValue==0) Print("DIO testing ok.\r\n\r\n"); X507_Write_All_DO(0); break; // Read DI (all channels) case 2: iDIValue=X507_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=X507_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); X507_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)\r\n"); Print("Channel number and status:"); Scanf("%d %d", &iOutChannel, &iStatus); if(iOutChannel>3) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } X507_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=X507_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=X507_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); 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"); RestoreCom3(); break; case 9: default: quit=1; break; } if(!quit) { Puts("Please press any key to continue...\r\n"); Getch(); } } }