/* X324Demo.c: Demo program for X324 Compiler: BC++ 3.1 Turbo C++ 1.01 Compile mode: large Project: X324Demo.c 7188el.lib X324.lib Hardware: I-7188EX + X324 [May 10, 2023] */ /*************************************************************/ /* X324: 4 channel 12-Bit D/A (Analog output) 0 ~ 5.0V */ /* 4 channel D/O */ /*************************************************************/ #include #include "..\..\lib\7188e.h" #include "..\..\lib\xboard\X324.h" void main(void) { char option, dbuf[32]; int outpstus, stus; int i, n, ret; float val; InitLib(); Print("\n"); Print("****************************************\n"); Print("| Demo program for I-7188EX + X324 |\n"); Print("| |\n"); Print("| [May 31, 2023] |\n"); Print("****************************************\n"); ret = X324_Init(); if(ret != 0) { for(i = 0; i < 4; i++) { if((ret >> (i << 1)) & 0x03) { Print(" The calibration parameters of channel %d are not available\n", i); } } } do { Print("\n"); Print(" 1) Analog output\n"); Print(" 2) Write all digital outputs\n"); Print(" 3) Write a single digital output\n"); Print(" 4) Read the states of all digital outputs\n"); Print(" 5) Read the state of a single digital output\n"); Print(" 0) Quit\n\n"); Print(" Choose an option: "); option = Getch(); Print("%c\n", option); switch(option) { /* Analog output */ case '1': Print(" Channel (0 ~ 3): "); n = Getch(); Print("%c\n", n); Print(" Voltage (0 ~ +5.0): "); LineInput(dbuf, 16); if((n = n ^ 0x30) >= 4) { Print(" [!] Unknown Channel Number\n\n"); } else if(sscanf(dbuf, "%f", &val) == 0) { Print(" [!] %.15s is not accepted\n\n", dbuf); } else { X324_AnalogOut(n, val); Print(" -> AO%d = %.4f V\n\n", n, val); } break; /* Write all digital outputs */ case '2': Print(" Output value (0 ~ f): "); LineInput(dbuf, 16); if(sscanf(dbuf, "%x", &outpstus) == 1) { X324_Write_All_DO(outpstus); Print(" -> Output value = %02xh\n\n", outpstus); } break; /* Write a single digital output */ case '3': Print(" Channel (0 ~ 3): "); n = Getch(); Print("%c\n", n); Print(" Status (0:OFF, 1:ON): "); LineInput(dbuf, 16); if((n = n ^ 0x30) >= 4) { Print(" [!] Unknown Channel Number\n\n"); } else if(sscanf(dbuf, "%d", &stus) == 0) { Print(" [!] %.15s is not accepted\n\n", dbuf); } else { X324_Write_One_DO(n, stus); Print(" -> DO%d = %s\n\n", n, (stus == 1) ? "ON" : "OFF"); } break; /* Read the states of all digital outputs */ case '4': outpstus = X324_Read_All_DO(); Print(" -> Digital Output ReadBack => %02xh\n\n", outpstus); break; /* Read the state of a single digital output */ case '5': Print(" Select output channel (0 ~ 3): "); n = Getch(); Print("%c\n", n); if((n = n ^ 0x30) >= 4) { Print(" [!] Unknown Channel Number\n\n"); } else { ret = X324_Read_One_DO(n); Print(" -> DO%d = %s\n\n", n, (ret == 1 ? "ON" : "OFF")); } break; } if(option != '0') { Print(" Press any key to continue ...\n"); Getch(); } Print("\n"); } while(option != '0'); }