/* X116Demo.c: Demo program for X116 Compiler: BC++ 3.1, Turbo C ++ 1.01(3.01) (free from http://community.borland.com/museum) Compile mode: large Project: X116Demo.c ..\..\Lib\7188el.lib ..\..\lib\Xboard\X116.lib Hardware: 7188EX + X116 X116: 4 channels Digital Input 6 channels Relay Output [09/Oct/2003] [14/July/2005] by Liam */ #include #include "..\..\lib\7188e.h" #include "..\..\lib\Xboard\X116.h" void main(void) { int iAction, iStatus, iDIValue, iDOValue=0, iRet, quit; int iInChannel, iOutChannel; InitLib(); X116_Init(); //Initialize the X116 Print("\n\r"); Print(" ****************************************\n\r"); Print(" | Demo program for 7188EX + X116 |\n\r"); Print(" | |\n\r"); Print(" | [14/July/2005] |\n\r"); Print(" ****************************************\n\r"); while(iAction!=7) { iAction=0; quit=0; Puts("\n\r"); Puts("1) Read DI (all channels)\n\r"); Puts("2) Read DI (one channel)\n\r"); Puts("3) Write Relay output (all channels)\n\r"); Puts("4) Write Relay output (one channels)\n\r"); Puts("5) Relay output Readback (all channels)\n\r"); Puts("6) Relay output Readback (one channel)\n\r"); Puts("\n\r"); Puts("7) Quits demo program\n\r\n\r"); Puts("Choose an option and press [Enter]:"); Scanf("%d",&iAction); Puts("\n\r"); switch(iAction) { // Read DI (all channels) case 1: iDIValue=X116_Read_All_DI(); Print("Input value=> 0x%02x\r\n\r\n", iDIValue); break; // Read DI (one channel) case 2: Print("Please select inport channel(0~3): "); Scanf("%d", &iInChannel); if(iInChannel>3) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } iDIValue=X116_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 Relay output (all channels) case 3: Print("Please input Output value(0 ~ 0x3f): "); Scanf("%x", &iDOValue); X116_Write_All_DO(iDOValue); Print("Output value=> 0x%02x\r\n\r\n", iDOValue); break; // Write Relay output (one channels) case 4: Print("Please select outport channel(0~5) and status(0:OFF, 1:ON)\n\r"); Print("Channel number and status:"); Scanf("%d %d", &iOutChannel, &iStatus); if(iOutChannel>5) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } X116_Write_One_DO(iOutChannel, iStatus); Print("Channel %d ==> %s\r\n\r\n", iOutChannel, (iStatus>0)?"ON":"OFF"); break; // Relay output Readback (all channels) case 5: iDOValue=X116_Read_All_DO(); Print("Digital Output ReadBack=> 0x%02x\r\n\r\n", iDOValue); break; // Relay output Readback (one channels) case 6: Print("Please select outport channel(0~5): "); Scanf("%d", &iOutChannel); if(iOutChannel>5) { Puts("Unknow Channel Number!!\r\n\r\n"); break; } iRet=X116_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; case 7: default: quit=1; break; } if(!quit) { Puts("Press any key to continue...\n\r"); Getch(); } } }