/* XW107.c: Demo program for XW107/XW107i Compiler: BC++ 3.1 Turbo C++ 1.01 (3.01) Compile mode: large Project: XW107.c ..\..\lib\upac5000.lib ..\..\lib\XWBoard\XW107.lib Hardware: uPAC-5000 + XW107/XW107i [Mar 29, 2012] by Liam */ /*****************************************************************/ /* XW107: 8 channel D/I (Dry Contact, Source) */ /* 8 channel D/O (Open Collector, Sink) */ /* XW107i: 8 channel D/I (Wet Contact, Sink/Source) */ /* 8 channel D/O (Open Collector, Sink) */ /*****************************************************************/ #include #include "..\..\lib\uPAC5000.h" #include "..\lib\XW107.h" void main(void) { int i, iRet, iOption, iQuit=0; unsigned uLibVersion; char szLibDate[16]; int iChannel, iDOValue, iState; InitLib(); /* Initiate the XW107 library */ if((iRet=XW107_Init())!=0) { Print("XW107/XW107i initiate failed [%X]\r\n", iRet); return; } Puts("\r\n"); Puts("************************************************\r\n"); Puts("| Demo program for uPAC-5000 + XW107/XW107i |\r\n"); Puts("| |\r\n"); Puts("| [Mar 29, 2012] |\r\n"); Puts("************************************************\r\n"); /* Read the version information of XW107 library */ uLibVersion=XW107_GetLibVersion(); XW107_GetLibDate(szLibDate); Print("\nXW107.lib version %X.%02X, %s\r\n", uLibVersion>>8, uLibVersion&0xFF, szLibDate); while(!iQuit) { Puts("\r\n"); Puts("1) Read DI (all channels)\r\n"); Puts("2) Read DI (one channel)\r\n"); Puts("3) Write DO (all channels)\r\n"); Puts("4) Write DO (one channel)\r\n"); Puts("5) DO Readback (all channels)\r\n"); Puts("6) DO Readback (one channel)\r\n"); Puts("\r\n"); Puts("0) Quit demo program\r\n\r\n"); Puts("Choose an option and press [Enter]: "); Scanf("%d", &iOption); Puts("\r\n"); switch(iOption) { case 1: Print("Input state => 0x%02X\r\n", XW107_Read_All_DI()); break; case 2: Print("DI Channel (0~7): "); Scanf("%d", &iChannel); if(iChannel>7) { Puts("Unknow Channel Number!!\r\n"); break; } iDOValue=XW107_Read_One_DI(iChannel); Print("DI%d => %s\r\n", iChannel, iDOValue==0?"ON":"OFF"); break; case 3: Print("DO Output state (0~ff): "); Scanf("%x", &iDOValue); XW107_Write_All_DO(iDOValue); Print("Output state => 0x%02X\r\n", iDOValue); break; case 4: Print("DO Channel (0~7) and status (0:OFF, 1:ON): "); Scanf("%d %d", &iChannel, &iState); if(iChannel>7) { Puts("Unknow Channel Number!!\r\n"); break; } XW107_Write_One_DO(iChannel, iState); Print("DO%d => %s\r\n", iChannel, iState==0?"OFF":"ON"); break; case 5: Print("DO ReadBack => 0x%02X\r\n", XW107_Read_All_DO()); break; case 6: Print("DO Channel (0~7): "); Scanf("%d", &iChannel); if(iChannel>7) { Puts("Unknow Channel Number!!\r\n"); break; } iDOValue=XW107_Read_One_DO(iChannel); Print("DO%d => %s\r\n", iChannel, iDOValue==0?"OFF":"ON"); break; case 0: iQuit=1; break; default: break; } if(!iQuit) { Puts("\r\nPress any key to continue...\r\n"); Getch(); } } }