/* This program calculates calibration constants for the Dataq DI194RS serial */ /* data acquisition device. */ #include #include "DI194RS.h" int main(void) { dataqsdk DI194; int ChannelList[MAXCHANNELS] = { 0, 1, 2, 3 }; int MethodList[MAXCHANNELS] = { 0, 0, 0, 0 }; short int offsets[MAXCHANNELS]; short int samplebuf[MAXCHANNELS]; float scalefactors[MAXCHANNELS]; bool status; long int count; int i; /* Display startup banner */ printf("Dataq DI194RS Calibrator\n"); /* Set up for the data acquisition */ DI194.ProductName(PRODUCTNAME); SDKerror(&DI194, "ProductName", TRUE); DI194.DeviceFile(SERIALPORT); SDKerror(&DI194, "DeviceFile", TRUE); DI194.ADChannelCount(4); SDKerror(&DI194, "ADChannelCount", TRUE); DI194.ADChannelList(ChannelList); SDKerror(&DI194, "ADChannelList", TRUE); DI194.ADMethodList(MethodList); SDKerror(&DI194, "ADMethodList", TRUE); DI194.SampleRate(1.0); SDKerror(&DI194, "SampleRate", TRUE); DI194.EventPoint(1); SDKerror(&DI194, "EventPoint", TRUE); /******************************************************************************/ /* Calibrate with 0.0 V input */ printf("\nConnect all analog inputs to 0.0V (GROUND) and press ENTER..."); fflush(stdout); getchar(); /* Start data acquisition */ DI194.Start(); SDKerror(&DI194, "Start", TRUE); /* Read analog inputs */ status = DI194.NewData(count); SDKerror(&DI194, "NewData", TRUE); if (status) { DI194.GetDataEx(offsets, MAXCHANNELS); SDKerror(&DI194, "GetDataEx", TRUE); for (i = 0; i < MAXCHANNELS; i++) offsets[i] &= DATAMASK; } /* Stop data acquisition */ DI194.Stop(); SDKerror(&DI194, "Stop", TRUE); printf("Sampled values are: %d %d %d %d\n", offsets[0], offsets[1], offsets[2], offsets[3]); fflush(stdout); /******************************************************************************/ /* Calibrate with 9.0 V input */ printf("\nConnect all analog inputs to 9.0V and press ENTER..."); fflush(stdout); getchar(); /* Start data acquisition */ DI194.Start(); SDKerror(&DI194, "Start", TRUE); /* Read analog inputs */ status = DI194.NewData(count); SDKerror(&DI194, "NewData", TRUE); if (status) { DI194.GetDataEx(samplebuf, MAXCHANNELS); SDKerror(&DI194, "GetDataEx", TRUE); for (i = 0; i < MAXCHANNELS; i++) samplebuf[i] &= DATAMASK; } /* Stop data acquisition */ DI194.Stop(); SDKerror(&DI194, "Stop", TRUE); printf("Sampled values are: %d %d %d %d\n", offsets[0], offsets[1], offsets[2], offsets[3]); fflush(stdout); /* Calculate scale factors */ for (i = 0; i < MAXCHANNELS; i++) scalefactors[i] = 9.0/(samplebuf[i] - offsets[i]); printf("Calculated scale factors are: %e %e %e %e\n", scalefactors[0], scalefactors[1], scalefactors[2], scalefactors[3]); fflush(stdout); SaveCalibration(offsets, scalefactors); exit(0); }