#define FmtBuf "%d[w4] %d[w4] %d[w3] %d[w3] %d[w3] %d[w4] %f %f %f \n" #define RECORD_STRING "cycle#:%d[w4] Date:%s Time:%s\n" /*#define FmtBuf "%d %d %d %d %d %d %f %f %f \r\n" / 6int 3float */ #define FmtTest "TEST#:%d[w4] Date:%s Time:%s\n" /* !NOTE! SETUP.PRO FILE MUST HAVE FORMAT "0 setup.pro" !!! !!! NOTE BAR-GRAPH "HISTOGRAM" AVAIL IN "PLOTY" ETC !!! R: (Raju test)"sigma" std dev calc Geoffrey Mangers 0 is LOW speed 1 is HIGH speed this program uses files: r.uir r.h r.c a.pro h.pro setup.pro color.h "setup_profilename" format: "0 ?.pro cycle#" e.g. "0 r.pro 73" change ++++++ sigma /= 10; ++++++ use syncwait (, ); to delay off time while processing arrays std. dev. etc look: "0"=average; "-1" = all; "1",2,...=individual graphs #define LOW 0 #define HIGH 1 from F: file i/o TO DO: see [4] and [5] file i/o, use fmt to make filenames w/numbers e.g. data.1 data.2 etc time stamp and save cycle-plots that exceed "sum-of-delta-squares" binary 2048=10volts Linker needs stack 9500<-no ?<15000 --using 15000 dio board can sink 24ma. long BinDataSize; comment[81], *78 chars is one screenwidth long sum[SIZE]; #define NumOfMonBufPoints 10 / started w/ 10 increase this after finish testing / #define LOOKONE 0 12345678911234567892123456789312345678941234567895123456789612345678971234567898123456789912345678901234567891123456789212345678 MAX # LINE CHARS: 128 100 120 */ #include "color.h" #include "r.h" #include "C:\LW\include\analysis.h" #include "C:\LW\include\formatio.h" #include "C:\LW\include\lwsystem.h" #include "C:\LW\include\userint.h" #include "C:\LW\include\dataacq.h" #define CYCLES 3000 /* sigma_array, RS: RUN_SIZE--number of test runs e.g. 3000 */ /*#define RS 3000 sigma_array, RS: RUN_SIZE--number of test runs e.g. 3000 */ #define I_SAT 5.00 #define NUM_MON_BUF_PTS 500 #define SIZE 1000 #define GAIN 100 /* 1 10 100 500 */ #define Ri 19.6 #define R 21.0 #define FmtProBuf "%d %d %d %d %d %d %d %d %d %d %d %f %f %f %f %f %f" /*12int 6float*/ /* DONT DO THIS: #define FmtBuf "%4d[w6]%d[w6b4]%3f[w10]" 'REP' IS FOR ARRAYS ONLY */ #define NS 1000 /* in calibration averaging: number_of_samples=NS; */ #define CHANNEL 0 /* 0 - 7 */ #define LINE 0 #define A 0 #define B 1 #define PORT B #define BufSize 65 /* don't make this too short or longs or will misalign formatting */ #define CONSECUTIVE 1 #define SCALE 1 #define OUT 1 #define IN 0 #define BOARD 1 #define NO_HANDSHAKING 0 #define INPUT 0 #define OUTPUT 1 #define LOW 0 #define HIGH 1 #define ON LOW /* power ON when pulling current through SSR led to gnd therefor ON is LOW*/ #define OFF HIGH #define TRUE 1 #define FALSE 0 #define BINARY 0 #define ASCII 1 #define TRUNCATE 0 #define APPEND 1 #define ASIS 2 #define READWRITE 0 #define READ 1 #define WRITE 2 #define HEAD 0 #define END 2 #define CURRENT 1 #define BEGIN 0 #define AVERAGE 1 #define NORMAL 0 #define R_SHUNT .01 /* default resistance of shunt in ohms */ /* #define R_SHUNT .0333 default resistance of shunt in ohms */ char read_record_timestamp[BufSize]; long /* max int is: 32767 */ /*xxx*/ offset_calc, offset, BinDataSize, PosFromStart; int e, BytesHeader, BytesWritten, BytesRead, BytesTimestampRecord; /* if this has probs make LONG instead INT */ static char /*see info on ReadLine: has to be +1 buffer size for the ASCII nul */ pro_timestamp[BufSize], buf[BufSize], read_test_timestamp[BufSize], test_timestamp[BufSize], timestamp[BufSize], average_timestamp[BufSize], average_filename[BufSize], comment[BufSize], /*78 chars is one screenwidth */ profilename[85], setup_profilename[85], DataFileName[78]; int hpgl_plot_flag, power_flag, frf, /*first run flag for monitor*/ ptf, /* ptf=trigger_flag */ control_id, average_protect_flag, setup_type, write_flag, protect_flag, sigma_flag, sigma_write_flag, exit_flag, channel, SampBuffer[SIZE], /* buffer used in SCAN_Start call */ MonitorBuffer[NUM_MON_BUF_PTS]; /* buffer used in DAQ_Monitor call */ double sa[CYCLES], /* sa=sigma_array, RS: RUN_SIZE--number of test runs e.g. 3000 */ running_average[SIZE], current_average[SIZE], /*ooo*/ current[SIZE], sum_current[SIZE], PlotBuffer[NUM_MON_BUF_PTS], /* data to be plotted is stored here */ sigma, sigma_limit, delta_sigma, rate, off_time, on_time, cycle_time, vmax, Rs_Effective, i_sat, voltage, attenuator, max, x, high_speed_scale_factor, scale_factor; int PreNumOfMonBufPoints, NumOfMonBufPoints, state, gain, turn_off_index, cycle, cycles, file_cycles, ratio, mode, number_of_samples, size, fails, fails_out_of, control_id, n, previous_test_count, i, FileHandle, GraphPanelHandle, SetupPanelHandle, CalibrationPanelHandle, DataGraphPanelHandle, nnn, fails, /* fails = num of fails in bindata */ filenumber, /* keeps track of "test-number" e.g. "test.34, "test.35" ...etc */ dummy_gain, Err_DAQ_Monitor; /* DON'T USE Dig_Out_Line_Err etc. conflicts w/ user library !!! */ double y[SIZE]; void PopCat (char head[51], char tail[51]); void fill(int cycles_type, int sigma_fill_flag); /* fills MR_ (home) panel */ void fill_setup(void); /* fills SETUP_ panel */ void calibrate(int number_of_samples); /*vvvoid*/ void Power (int state); /*turns power on/off through SSR*/ void PlotLimit (double array[SIZE], double coefficient, int color);/* shows upper and lower limits for test*/ void WriteHeader(char filename[50]); /*writes header [test constants, etc.] in specified data file*/ /*writes record [cycle] timestamp and binary data in specified data file*/ void WriteData(char filename[50], double array[SIZE], char timestamp_string[50]); void ReadData(char filename[50], double array[SIZE], int record); /* uses ReadRealData[] */ void setup(); /* SETS UP PROFILE FILE "F.PRO" using SETUP_ panel */ void profile(int mode, char setup_filename[13]); /*read/write file I/O for test constants from setup() in "a.pro" */ void look(int look_cycle); /* reviews, reads and graphs files on disk, uses ReadRealData[] */ /*void Average(int filenumber, int io_flag); read/write to average_filename file */ void main(void) /* mmm */ { int NewestPtIndex, MonitorStatus, Status, SampleTimebase, SampleInterval; /* III: TEMPORARY INITIALISATIONS */ /* Fmt (DataFileName, "Magic.36"); change filename to DataFileName Fmt (DataFileName, "f"); i_sat = (10.0/gain)/R_SHUNT; /TEMP OMIT LATER!!/ */ i_sat = I_SAT; /* temporary setting, eliminate when doing actual cal */ /* iii: initialization */ /* power_flag = FALSE; power_flag = FALSE; power_flag = TRUE; power_flag = TRUE; */ power_flag = TRUE; e = OpenInterfaceManager (); if (e<0)breakpoint(); /*put here or will have probs later: "cant open I Mgr"*/ cls(); FillBytes (DataFileName, 0, BufSize, 0); number_of_samples=NS; high_speed_scale_factor = 3.0 / 2048; FillBytes (average_filename, 0, BufSize, 0); /* fills w/ nulls--0 */ /* Fmt (average_filename, "ave.%d", previous_test_count+1); */ /* READ SETUP FILE */ FileHandle = OpenFile ("setup.pro", READ, ASIS, BINARY); if(FileHandle==-1) MessagePopup ("Cannot read NONEXISTENT \"setup.pro\" setup file"); else { e = ScanFile (FileHandle, "%d %s %d", &setup_type, setup_profilename, &cycle); if (e<0)breakpoint(); e = CloseFile (FileHandle); if (e<0)breakpoint(); } channel = 0; gain = 100; NumOfMonBufPoints = 10; scale_factor = i_sat / 2048; /*sscc*/ if(setup_type==1) { /* NORMAL LOW SPEED */ FillBytes (average_filename, 0, BufSize, 0); /* fills w/ nulls--0 */ Fmt (average_filename, "aa"); Fmt (profilename, "a.pro"); } else if(setup_type == 2) { /* HIGH SPEED */ FillBytes (average_filename, 0, BufSize, 0); /* fills w/ nulls--0 */ Fmt (average_filename, "hsa"); Fmt (profilename, "h.pro"); channel = 7; gain = 1; NumOfMonBufPoints = 500; scale_factor = high_speed_scale_factor; } else Fmt (profilename, setup_profilename); profile(READ, profilename); /************READ IN ALL PARAMETERS HERE ***********/ Rs_Effective=R_SHUNT; size=SIZE; BinDataSize = 8*size; fails=17; exit_flag=FALSE; sigma_flag=FALSE; /* sigma_flag is std. dev. calculation flag */ cycle_time = on_time + off_time; if (cycle_time==0.0) cycle_time=1.0; if(cycle_time==0.0)cycle_time=60; rate = SIZE/cycle_time; e = DIG_Prt_Config (BOARD, A, NO_HANDSHAKING, IN); e = DIG_Prt_Config (BOARD, B, NO_HANDSHAKING, OUT); if (e<0)breakpoint(); SetupPanelHandle = LoadPanel ("r.uir", SETUP); DataGraphPanelHandle = LoadPanel ("r.uir", MR); e = DisplayPanel (DataGraphPanelHandle); if (e<0)breakpoint(); e = SetActivePanel (DataGraphPanelHandle); /* HAVE TO DO THIS SO " ESC=EXIT" BUTTON WILL WORK */ if (e<0)breakpoint(); e = DefaultCtrl (DataGraphPanelHandle, MR_SIGMA); if (e<0 && e!=-14)breakpoint(); fill(cycles, 0); /* if (power_flag) Power(OFF); V=10v/gain; 10V="2048"; I_SAT = V / R_SHUNT = (10v/gain)/R_SHUNT sf = "(I_SAT amps)/2048" = I_SAT * ( (10v/gain) / R ) / 2048 attenuator = R/(R+Ri); gain = GAIN * attenuator; i_sat = (10.0/gain)/R_SHUNT; if (i_sat != I_SAT) {FmtOut("i_sat: %f and I_SAT: %f do not align", i_sat, I_SAT); exit(0);} FmtOut (" \"setup.pro\" file is READ ONLY -- could not save new parameters to it"); */ e=DIG_In_Line (BOARD, A, LINE, &state); if (e<0)breakpoint(); e = SetCtrlVal (DataGraphPanelHandle, MR_HPGL, state); if (e<0)breakpoint(); e = Fmt (test_timestamp, FmtTest, previous_test_count+1, datestr (), timestr () ); if (e<0)breakpoint(); e = SetCtrlVal (DataGraphPanelHandle, MR_FILE_TIMESTAMP, test_timestamp); if(e<0)breakpoint(); /* write header to file for first cycle if(cycle == 1)*/ cycle = 1; e = Fmt (timestamp, RECORD_STRING, cycle, datestr (), timestr () ); if (e<0)breakpoint(); Set1D (y, SIZE, i_sat); /* dummy 'limits' */ if(dsperr)breakpoint(); /* check global variable "dsperr" for error ttt*/ NewestPtIndex = 0; /* Highlight the x-axis */ e = PlotY(DataGraphPanelHandle, MR_GRAPH, current_average, SIZE, 4, 0, 0, 1, 1); if(e)breakpoint(); hpgl_plot_flag = FALSE; e = SetCtrlVal (DataGraphPanelHandle, MR_HPGL, hpgl_plot_flag); while(TRUE) /*while(control_id!=MR_EXIT && exit_flag==FALSE)*/ { e = GetUserEvent (0, &i, &control_id); if(e<0)breakpoint(); /*ggget*/ /* { e=DIG_In_Line (BOARD, A, LINE, &state); if (e<0)breakpoint(); SetCtrlVal (DataGraphPanelHandle, MR_HPGL, state); } if(state) state=LOW; else state=HIGH; toggle state LED to indicate wait e = SetCtrlVal (DataGraphPanelHandle, MR_HPGL, state); */ switch (control_id) { /*r*/ case MR_EXIT: /*eexit*/ if (power_flag) Power(OFF); return; break; case MR_QUITSAVE: /*qquit Power(OFF); */ if (power_flag) Power(OFF); profile(WRITE, profilename); /*ssset*/ FileHandle = OpenFile ("setup.pro", WRITE, TRUNCATE, BINARY); if(FileHandle==-1) MessagePopup ("Cant write to READ-ONLY \"setup.pro\""); else { /*setup_profilename*/ e = FmtFile (FileHandle, "%d %s %d", setup_type, profilename, cycle); if (e<0)breakpoint(); e = CloseFile (FileHandle); if (e<0)breakpoint(); } /*if (setup_type!=1 && setup_type!=2)*/ return; break; case MR_RESET: if (power_flag) Power(OFF); /*rreset*/ e = DeletePlots(DataGraphPanelHandle, MR_GRAPH); if (e<0)breakpoint(); fill(cycles, 0); SetActiveCtrl (MR_START); break; case MR_START: /*ssstart*/ exit_flag = 0; e = SetCtrlVal (DataGraphPanelHandle, MR_CYCLES, cycles); if (e<0)breakpoint(); e = DefaultCtrl (DataGraphPanelHandle, MR_SIGMA); if (e<0 && e!=-14)breakpoint(); Clear1D (sum_current, size); if(dsperr)breakpoint(); /* check global variable "dsperr" for Copy1D error ttt*/ Clear1D (current, size); if(dsperr)breakpoint(); /* check global variable "dsperr" for Copy1D error ttt*/ Clear1D (running_average, size); if(dsperr)breakpoint(); /* check global variable "dsperr" for Copy1D error ttt*/ e = DeletePlots(DataGraphPanelHandle, MR_GRAPH); e = SetCtrlVal (DataGraphPanelHandle, MR_RECORD_TIMESTAMP, timestamp); if (e<0)breakpoint(); if (!average_protect_flag) WriteHeader(average_filename); /*whwhwhwh*/ if(!protect_flag) WriteHeader(DataFileName); /*if (!sigma_flag && !protect_flag) (!sigma_flag || sigma_write_flag) &&*/ turn_off_index = (on_time / cycle_time) * SIZE; /*============================================================================*/ e = DAQ_Clear (BOARD); if (e!=-74 && e!=0)breakpoint(); /* ccconfig */ /*********** ********** ********** ********** **********/ if (power_flag) /*pppre*/ { /* e = DAQ_Config (BOARD, 0, 0);*/ e = DAQ_Config (BOARD, 1, 0); if(e)breakpoint(); /* THERE IS NO "DAQ_SETUP" !! DOUBLE BUFFERING NOT NECESSARY??! */ } else { e = DAQ_Trigger_Config (BOARD, 1, 900); if(e)breakpoint(); PreNumOfMonBufPoints = 100; Status = 0; for (i=0; i turn_off_index) if (power_flag) Power(OFF); for (i=0; i sigma_limit) sigma_write_flag=TRUE; else sigma_write_flag=FALSE; e = SetCtrlVal (DataGraphPanelHandle, MR_SIGMA, sigma); if (e<0 && e!=-14)breakpoint(); } else /* regular plot w/ running average no sigma calcs ssiigma*/ for (i=0; i=NEXT =PREVIOUS =EXIT"); if (e<0)breakpoint(); /*----------------------------------------------*/ e = PromptPopup ("ENTER CYCLE NUMBER [then =CONTINUAL etc]", buf, 8); /* 50 -'s: -------------------------------------------------- max popup length */ Fmt(&e, "%d<%s", buf); /* get number of cycle from popup to start at */ if ( !StringLength (buf) ) e = 1; /* if carriage return, length of 'buf' = 0 ; -make 'e'=1 */ look(e); /*look: "0"=average; "-1" = all; "1",2,...=individual graphs */ break; case MR_SETUP: /*qqq*/ e = HidePanel (DataGraphPanelHandle ); if(e<0)breakpoint(); setup(); e = DisplayPanel (DataGraphPanelHandle); if(e<0)breakpoint(); e = SetActivePanel (DataGraphPanelHandle); if(e<0)breakpoint(); fill(cycles, sigma_flag); SetActiveCtrl (MR_START); break; case MR_SAVEPANEL: e = OutputPanel (3, "hpgl", 1, DataGraphPanelHandle); if(e)breakpoint(); break; /* case MR_SAVE: /SF2/ e = SavePanelState (SetupPanelHandle, "panel.sav"); if(e<0)breakpoint(); break; */ } /*end switch*/ } /*end while(control_id!=MR_EXIT)*/ CloseInterfaceManager (); }/************************ eee END MAIN **********************************/ /****************************************************************************/ void PlotLimit(double array[SIZE], double coefficient, int color) { /* shows upper and lower limits for test*/ /* > > > > > > > > > > > > > BEGIN > > > > > > > > > > > > > > > > > > > */ int i; for (i=0; i%*f", SIZE, SIZE, array); if (e<0)breakpoint(); CloseFile (ReadDataFileHandle); /*^ReadRealData*/ } /***************** END READFILE ******************************************/ /***************************************************************************/ void fill(int cycles_type, int sigma_fill_flag) /* fills MR_ (home) panel */ { /* e = FmtFile (FileHandle, test_timestamp); e = FmtFile (FileHandle, "%s\r\n", comment); Fmt (comment, "%s", "this is a comment"); Fmt (comment, "%s", "*comments about the test can be placed here up to 80 characters*"); if (sigma_fill_flag) {e = SetCtrlVal (DataGraphPanelHandle, MR_SIGMA, -current[SIZE-1]); if (e<0)breakpoint();} else {e = DefaultCtrl (DataGraphPanelHandle, MR_SIGMA); if (e<0 && e!=-14)breakpoint();} if (sigma_fill_flag || (current[SIZE-1]!=0.0) ) */ cycle_time = on_time + off_time; if (cycle_time==0.0) cycle_time=1.0; if (sigma_fill_flag) { e = SetCtrlVal (DataGraphPanelHandle, MR_SIGMA, -current[SIZE-1]); if (e<0)breakpoint(); } else { e = DefaultCtrl (DataGraphPanelHandle, MR_SIGMA); if (e<0 && e!=-14)breakpoint(); } e = SetCtrlVal (DataGraphPanelHandle, MR_RATE, (long) rate); if (e<0)breakpoint(); e = SetCtrlVal (DataGraphPanelHandle, MR_CYCLES, cycles_type); if (e<0)breakpoint(); e = SetCtrlVal (DataGraphPanelHandle, MR_AVERAGEFILENAME, average_filename); if (e<0)breakpoint(); e = SetCtrlVal (DataGraphPanelHandle, MR_FILENAME, DataFileName); if (e<0)breakpoint(); e = SetCtrlVal (DataGraphPanelHandle, MR_COMMENT, comment); if (e<0)breakpoint(); e = SetCtrlVal (DataGraphPanelHandle, MR_TOTALTIME, cycle_time); if (e<0)breakpoint(); e = SetCtrlVal (DataGraphPanelHandle, MR_PROTECTAVE, average_protect_flag); if (e<0)breakpoint(); e = SetCtrlVal (DataGraphPanelHandle, MR_PROTECT, protect_flag); if (e<0)breakpoint(); e = SetCtrlVal (DataGraphPanelHandle, MR_SIGMALIMIT, sigma_limit); if(e<0 && e !=-14)breakpoint(); e = SetCtrlVal (DataGraphPanelHandle, MR_RECORD_TIMESTAMP, read_record_timestamp); if (e<0)breakpoint(); } void fill_setup(void) { cycle_time = on_time + off_time; if (cycle_time==0.0) cycle_time=1.0; rate = SIZE/cycle_time; e = SetCtrlVal (SetupPanelHandle, SETUP_COMMENT, comment); if(e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_GAIN, gain); if(e<0)breakpoint(); if (rate<30000.0)e = SetCtrlVal (SetupPanelHandle, SETUP_RATE, (long) rate); if(e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_FILENAME, DataFileName); if(e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_PROFILENAME, profilename); if(e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_AVERAGE_FILENAME, average_filename); if(e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_CYCLES, cycles); if(e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_SIZE, SIZE); if(e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_TESTCOUNT, previous_test_count); if(e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_RS_EFFECTIVE, Rs_Effective); if(e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_OFFTIME, off_time); if(e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_TOTALTIME, cycle_time); if(e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_ONTIME, on_time); if(e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_ISAT, i_sat); if(e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_PROFILENAME, profilename); if (e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_CHANNEL, channel); if (e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_PROTECTAVE_LED, average_protect_flag); if (e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_PROTECT_LED, protect_flag); if (e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_SIGMALIMIT, sigma_limit); if(e<0)breakpoint(); } void setup() /*ssetup*/ /* SETS UP PROFILE FILE "F.PRO" using SETUP_ panel */ { char get_profilename[13]; char profile_buf[80]; int first_run_flag, get_flag, save_flag, select, SetupFileHandle; control_id=-1; get_flag = FALSE; first_run_flag = TRUE; FillBytes (DataFileName, 0, BufSize, 0); /* FillBytes (DataFileName, 0, BufSize, 0); / fills w/ nulls--0 / FillBytes (comment, 0, BufSize, 0); / fills w/ nulls--0 / */ profile(READ, profilename); fill_setup(); cycle_time = on_time + off_time; if (cycle_time==0.0) cycle_time=1.0; DisplayPanel (SetupPanelHandle); SetActivePanel (SetupPanelHandle); e = SetActiveCtrl (SETUP_PROFILENAME); if(e<0)breakpoint(); while(control_id!=SETUP_EXIT) { e = GetUserEvent (0, &i, &control_id); if(e<0)breakpoint(); /**/ e = GetCtrlVal (SetupPanelHandle, SETUP_CYCLES, &cycles); if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_OFFTIME, &off_time); if(e<0 && e!=-14)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_ONTIME, &on_time); if(e<0 && e!=-14)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_CYCLES, &cycles); if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_FILENAME, DataFileName);if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_PROFILENAME, profilename);if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_AVERAGE_FILENAME, average_filename);if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_COMMENT, comment);if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_TESTCOUNT, &previous_test_count);if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_GAIN, &gain); if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_SIGMALIMIT, &sigma_limit); if(e<0 && e!=-14)breakpoint(); if (get_flag == TRUE) { } /* fill_setup(); */ switch (control_id) { case SETUP_FEXIT: /* F1 */ e = HidePanel (SetupPanelHandle); if(e<0)breakpoint(); return; break; case SETUP_EXIT: cycle_time = on_time + off_time; if (cycle_time==0.0) cycle_time=1.0; rate = SIZE/cycle_time; e = HidePanel (SetupPanelHandle); if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_PROFILENAME, profilename);if(e<0)breakpoint(); profile(WRITE, profilename); if (!setup_type) /*if setup_type is zero, read the "setup.pro" file*/ { /*ssset*/ SetupFileHandle = OpenFile ("setup.pro", WRITE, TRUNCATE, BINARY); if(SetupFileHandle==-1) MessagePopup ("Cant write to READ-ONLY \"setup.pro\""); else { e = FmtFile (SetupFileHandle, "%d %s %d", setup_type, profilename, cycle); if (e<0)breakpoint(); e = CloseFile (SetupFileHandle); if (e<0)breakpoint(); } } return; /*qqq*/ break; /* break can be used as a "return" in a loop to recurse 1 level */ case SETUP_POPFILE: /*SF2 POPUP FILE sf2 ppop*/ FillBytes (profilename, 0, BufSize, 0); /* fills w/ nulls--0 */ select = FileSelectPopup ("", "v.pro", "SELECT PROFILE ('.PRO') FILE", 1, 0, 1, profile_buf); if (select) { e = SetActiveCtrl (SETUP_EXIT); if(e<0)breakpoint(); } else { e = SetCtrlVal (SetupPanelHandle, SETUP_PROFILENAME, profilename);if(e<0)breakpoint(); e = SetActiveCtrl (SETUP_PROFILENAME); if(e<0)breakpoint(); Fmt (profilename, profile_buf); fill_setup(); setup_type = 0; } break; case SETUP_PROFILENAME: e = SetCtrlVal (SetupPanelHandle, SETUP_PROFILENAME, profilename);if(e<0)breakpoint(); FillBytes (profilename, 0, BufSize, 0); /* fills w/ NULLS=0 nulls--0 */ e = GetCtrlVal (SetupPanelHandle, SETUP_PROFILENAME, profilename);if(e<0)breakpoint(); e = StringLength (profilename); /*,.,.*/ CopyBytes (profilename, e, ".pro", 0, 4); e = SetCtrlVal (SetupPanelHandle, SETUP_PROFILENAME, profilename);if(e<0)breakpoint(); if (save_flag) { profile(WRITE, profilename); save_flag = FALSE; } else { profile(READ, profilename); fill_setup(); } e = SetActiveCtrl (SETUP_PROFILENAME); if(e<0)breakpoint(); break; case SETUP_GETPREFIX: /* F9 */ e = SetActiveCtrl (SETUP_PROFILENAME); if(e<0)breakpoint(); break; case SETUP_SAVE: /*F2*/ cycle_time = on_time + off_time; if (cycle_time==0.0) cycle_time=1.0; e = SetCtrlVal (SetupPanelHandle, SETUP_TOTALTIME, cycle_time); if(e<0)breakpoint(); rate = SIZE/cycle_time; e = GetCtrlVal (SetupPanelHandle, SETUP_PROFILENAME, profilename);if(e<0)breakpoint(); profile(WRITE, profilename); if (setup_type!=1 && setup_type!=2) { n=0; setup_type = n; if (setup_type==-1) setup_type = 0; /*ssset*/ SetupFileHandle = OpenFile ("setup.pro", WRITE, TRUNCATE, BINARY); if(SetupFileHandle==-1) MessagePopup ("Setup file: \"setup.pro\" is READ ONLY"); else { e = FmtFile (SetupFileHandle, "%d %s %d", setup_type, profilename, cycle); if (e<0)breakpoint(); e = CloseFile (SetupFileHandle); if (e<0)breakpoint(); if (n==-1) setup_type = -1; } } save_flag = TRUE; break; /* break can be used as a "return" in a loop to recurse 1 level */ /* if(setup_type!=1) setup_type=2; else if (setup_type!=1) setup_type=1; */ case SETUP_SPEED: /*F10*/ if(setup_type==1) setup_type=2; else if (setup_type==2) setup_type=1; else setup_type=1; FillBytes (average_filename, 0, BufSize, 0); /* fills w/ nulls--0 */ if(setup_type==2) { /* HIGH SPEED Fmt (DataFileName, "hs"); Fmt (average_filename, "hs.ave");*/ Fmt (profilename, "h.pro"); profile(READ, profilename); /* Fmt (average_filename, "hs.ave"); */ Fmt (average_filename, "hs.ave"); channel = 7; gain = 1; NumOfMonBufPoints = 500; scale_factor = high_speed_scale_factor; } else if(setup_type==1) /*Fmt (average_filename, "ave"); Fmt (average_filename, "ave.%d", previous_test_count+1); */ {/*NORMAL LOW SPEED */ Fmt (profilename, "a.pro"); profile(READ, profilename); Fmt (average_filename, "aa"); channel = 0; gain = 100; NumOfMonBufPoints = 10; scale_factor = i_sat / 2048; } profile(READ, profilename); fill_setup(); break; case SETUP_PROTECT: /*^P*/ if(protect_flag) protect_flag=LOW; else protect_flag=HIGH; /* toggle */ e = SetCtrlVal (SetupPanelHandle, SETUP_PROTECT_LED, protect_flag); if (e<0)breakpoint(); e = SetActiveCtrl (SETUP_PROTECTAVE); if(e<0)breakpoint(); break; case SETUP_PROTECTAVE: /*^A*/ if(average_protect_flag) average_protect_flag=LOW; else average_protect_flag=HIGH; /* toggle */ e = SetCtrlVal (SetupPanelHandle, SETUP_PROTECTAVE_LED, average_protect_flag); if (e<0)breakpoint(); e = SetActiveCtrl (SETUP_PROTECT); if(e<0)breakpoint(); break; case SETUP_SAVEPANEL: /*SF1*/ e = OutputPanel (3, "hpgl", 1, SetupPanelHandle); if(e<0)breakpoint(); break; case SETUP_SETSAVE: /*SF3*/ e = SavePanelState (SetupPanelHandle, "setpanel.sav"); if(e<0)breakpoint(); break; case SETUP_SETRECALL: /*SF4*/ e = RecallPanelState(SetupPanelHandle, "setpanel.sav"); if(e<0)breakpoint(); break; case SETUP_SETOFFTIME: e = SetActiveCtrl (SETUP_OFFTIME); if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_OFFTIME, &off_time);if(e<0)breakpoint(); break; case SETUP_SETONTIME: e = SetActiveCtrl (SETUP_ONTIME); if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_ONTIME, &on_time);if(e<0)breakpoint(); break; case SETUP_SETSIGMALIMIT: e = SetActiveCtrl (SETUP_SIGMALIMIT); if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_SIGMALIMIT, &sigma_limit);if(e<0)breakpoint(); break; case SETUP_SETCYCLES: e = SetActiveCtrl (SETUP_CYCLES); if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_CYCLES, &cycles); if(e<0)breakpoint(); break; case SETUP_SETFILENAME: e = SetActiveCtrl (SETUP_FILENAME); if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_FILENAME, DataFileName);if(e<0)breakpoint(); setup_type = 0; break; case SETUP_SETAVERAGEFILENAME: e = SetActiveCtrl (SETUP_AVERAGE_FILENAME); if(e<0)breakpoint(); FillBytes (average_filename, 0, BufSize, 0); /* fills w/ nulls--0 */ e = GetCtrlVal (SetupPanelHandle, SETUP_AVERAGE_FILENAME, average_filename);if(e<0)breakpoint(); break; case SETUP_SETCOMMENT: /*78 chars is one screenwidth */ e = SetActiveCtrl (SETUP_COMMENT); if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_COMMENT, comment);if(e<0)breakpoint(); break; case SETUP_SETTESTCOUNT: e = SetActiveCtrl (SETUP_TESTCOUNT); if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_TESTCOUNT, &previous_test_count);if(e<0)breakpoint(); break; case SETUP_SETGAIN: e = SetActiveCtrl (SETUP_GAIN); if(e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_GAIN, &gain); if(e<0)breakpoint(); break; case SETUP_CALIBRATION: e = HidePanel (DataGraphPanelHandle); if(e<0)breakpoint(); calibrate(300); /*ggg*/ e = HidePanel (CalibrationPanelHandle); if(e<0)breakpoint(); e = DisplayPanel (SetupPanelHandle); if(e)breakpoint(); /**/ e = SetActivePanel (SetupPanelHandle); if(e)breakpoint(); break; case SETUP_LIMITS: /*limits*/ Set1D (y, SIZE, i_sat); /* dummy 'limits' */ if(dsperr)breakpoint(); /* check global variable "dsperr" for error ttt*/ PlotLimit (y, .6, RED); /* [2] plot out upper limit */ PlotLimit (y, .1, RED); /* [2] plot out lower limit */ break; /* e = SetCtrlVal (SetupPanelHandle, SETUP_, ); if (e<0)breakpoint(); e = GetCtrlVal (SetupPanelHandle, SETUP_, ); if(e<0)breakpoint(); case SETUP_SET: e = SetActiveCtrl (SETUP_); if(e<0)breakpoint(); break; use this for direct to printer: e = OutputPanel (0, "", 1, SetupPanelHandle); e = OutputPanel (0, "", 1, SetupPanelHandle); if(e<0)breakpoint(); mode: WRITE=0 READ=1 */ } } } /* END SETUP() END SETUP() END SETUP() END SETUP() */ void profile(int mode, char setup_filename[13]) /* read/write PROFILE FILE "F.PRO" in setup() */ { /*read/write file I/O for test constants from setup() in "a.pro" */ int PosFromStart, LocalFileHandle, items_read_write; if (setup_type == -1) return; if (setup_type==1 || setup_type==2) Fmt (profilename, setup_filename); if (mode==READ) /* READ READ READ READ READ READ READ READ */ { LocalFileHandle = OpenFile (setup_filename, READ, ASIS, ASCII); if( LocalFileHandle<0 ) { PopCat (" Cannot read NONEXISTENT file: ", setup_filename); e =DefaultCtrl (SetupPanelHandle, SETUP_PROFILENAME); return; /**/ } PosFromStart = SetFilePtr (LocalFileHandle, 0L, 0); /*"REWIND" */ if (PosFromStart < 0) breakpoint(); /*read [single] timestamp of entire test [file] */ e = ReadLine (LocalFileHandle, pro_timestamp, BufSize-1); if(e<=0)breakpoint(); e = ReadLine (LocalFileHandle, comment, BufSize-1); if(e<=0)breakpoint(); e = ReadLine (LocalFileHandle, DataFileName, BufSize-1); if(e<=0)breakpoint(); FillBytes (average_filename, 0, BufSize, 0); /* fills w/ nulls--0 */ e = ReadLine (LocalFileHandle, average_filename, BufSize-1); if(e<=0)breakpoint(); items_read_write = ScanFile (LocalFileHandle, FmtProBuf, &previous_test_count, &cycles, &fails, &fails_out_of, &gain, &number_of_samples, &BytesHeader, &BytesTimestampRecord, &size, &protect_flag, &average_protect_flag, &sigma_limit, &rate, &Rs_Effective, &i_sat, &off_time, &on_time); /*11int, 6f*/ if (items_read_write < 0)breakpoint(); BinDataSize = 8 * size; n=0; while (n!=-1) { /* deletes CR's in string */ n = FindPattern (comment, 0, -1, " ", 1, 0); if (n!=-1)FillBytes (comment, n, 1, ' '); } e = CloseFile (LocalFileHandle); if (e<0)breakpoint(); return; } /***************** END READFILE ****************************************/ if (mode==WRITE) /* WRITE WRITE WRITE WRITE WRITE */ { LocalFileHandle = OpenFile (setup_filename, WRITE, TRUNCATE, ASCII); if(LocalFileHandle==-1) PopCat (setup_filename, " IS READ ONLY, CANT WRITE DATA"); else { e = Fmt (pro_timestamp, "PROFILE FILE: Date:%s Time:%s", datestr (), timestr () ); if(e<0)breakpoint(); e = WriteLine (LocalFileHandle, pro_timestamp, BufSize-1); if(e<=0)breakpoint(); e = FmtFile (LocalFileHandle, "%s\n", comment); if (e<0)breakpoint(); /* DON'T USE: e = WriteLine (FileHandle, comment, BufSize); */ e = FmtFile (LocalFileHandle, "%s\n", DataFileName); if (e<0)breakpoint(); e = FmtFile (LocalFileHandle, "%s\n", average_filename); if (e<0)breakpoint(); /* e = FmtFile (LocalFileHandle, "%s\r\n", ); if (e<0)breakpoint(); / DON'T USE: e = WriteLine (FileHandle, comment, BufSize); / e = WriteLine (LocalFileHandle, comment, BufSize-1); if(e<=0)breakpoint(); e = WriteLine (LocalFileHandle, , BufSize); if(e<=0)breakpoint(); e = WriteLine (LocalFileHandle, , BufSize); if(e<=0)breakpoint(); */ items_read_write = FmtFile (LocalFileHandle, FmtProBuf, previous_test_count, cycles, fails, fails_out_of, gain, number_of_samples, BytesHeader, BytesTimestampRecord, size, protect_flag, average_protect_flag, sigma_limit, rate, Rs_Effective, i_sat, off_time, on_time); /*11int, 5f*/ if (items_read_write < 0)breakpoint(); e = CloseFile (LocalFileHandle); if (e<0)breakpoint(); } /***************** END IF LocalFileHandle ***************************/ } /***************** END WRITE IF **************************************/ } /* END FILE END FILE END FILE END FILE END FILE END FILE */ /***************************************************************************/ void PlotHPGL (int plot_cycle) /*hhh*/ { CopyString (buf, 0, "", 0, 1); Fmt (buf, "%s 0) k = look_cycle; while (k<=file_cycles) /* cycle loop */ { /* look_cycle */ if (look_cycle==0) k = file_cycles + 1; ReadData(DataFileName, current, k); /* nnn is record number ReadData(DataFileName, DATA); */ fill(cycles, (current[SIZE-1]<0.0) ); e = DeletePlots(DataGraphPanelHandle, MR_GRAPH); if (e<0)breakpoint(); e = SetCtrlVal (DataGraphPanelHandle, MR_RECORD_TIMESTAMP, read_record_timestamp); if (e<0)breakpoint(); e = PlotY (DataGraphPanelHandle, MR_GRAPH, current, SIZE-2, 4, 0, 0, 1, LTCYAN); if(e)breakpoint(); if (hpgl_plot_flag) PlotHPGL (k); if (continual_flag) { e = GetUserEvent (0, &i, &control_id); if (control_id==-1) /* if control_id==-1 no event has occurred */ k += 1; else continual_flag = FALSE; } else /* "NOT"--continual_flag */ { e = getkey (); /*lllook*/ /* exit test */ if (e == 8) k -= 1; /* BACKSPACE */ if (e == 13) k += 1; /* CARRIAGE RETURN */ if (e == 27) { SetActiveCtrl (MR_EXIT); /*MR_EXIT RESET llxx */ return; } if (e == 32) continual_flag = TRUE; /* SPACEBAR activates continual read */ }/*end (continual_flag) loop */ } /* end "while (k<=file_cycles)" cycle loop */ /*BLACK0 BLUE1 GREEN2 CYAN3 RED4 MAGENTA5 BROWN6 LTGRAY7 DKGRAY8 LTBLUE9 LTGREEN10 LTCYAN11 LTRED12 LTMAGENTA13 YELLOW14 WHITE15*/ /* SetActiveCtrl (MR_EXIT); /MR_EXIT RESET llxx / if (control_id==MR_EXIT || control_id==MR_RESET) /if (e == 27) k = file_cycles; ESC: end the loop last_cycle = k; k = last_cycle; if (control_id==MR_EXIT || control_id==MR_RESET) k=file_cycles; control_id=MR_LOOKALL; if (file_cycles!=1 && k!=file_cycles || look_cycle >0) e = GetUserEvent (1, & j, &control_id); if(e<0)breakpoint(); /if (continual_flag) if (keyhit()) if (getkey()==9) return; / / TAB = 9 / if (control_id==MR_EXIT) k = file_cycles; if (!hold) */ e = DeletePlots(DataGraphPanelHandle, MR_GRAPH); e = SetCtrlVal (DataGraphPanelHandle, MR_RECORD_TIMESTAMP, ""); if (e<0)breakpoint(); }/***************************** end look **********************************/ void Power(int state) /*turns power on/off through SSR*/ { /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ /* power is on when pulling current through SSR led to digout 'ground'--LOW therefor ON has to be LOW*/ /**/ if (setup_type==2) state = HIGH; e = DIG_Out_Line (BOARD, PORT, LINE, state); if (e<0)breakpoint(); } /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ /* V=10v/gain; 10V="2048"; I_SAT = V / R_SHUNT = (10v/gain)/R_SHUNT sf = "(I_SAT amps)/2048" = I_SAT * ( (10v/gain) / R ) / 2048 if (i_sat != I_SAT) FmtOut("i_sat: %f and I_SAT: %f do not align", i_sat, I_SAT); exit(0);} */ void calibrate(int number_of_samples) { double cur, scale_factor, calibration_current, attenuator; int quit_hit, /* loop control flag */ ctrl, /* control ID */ i, bin, channel; long bin_current; /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* attenuator = R/(R+Ri); gain = GAIN * attenuator; scale_factor = i_sat / 2048; */ /* initialization */ if (Rs_Effective==0) Rs_Effective = R_SHUNT; /* have to set or divide by zero */ calibration_current = 2.00; vmax = (10.0/gain); if (number_of_samples==0.0) { breakpoint(); number_of_samples = 100; } e = HidePanel (SetupPanelHandle); if(e<0)breakpoint(); CalibrationPanelHandle = LoadPanel ("r.uir", CALIBRATE); e = DisplayPanel (CalibrationPanelHandle); if(e)breakpoint(); /* e = SetActiveCtrl (CALIBRATE_EXIT); if(e)breakpoint(); */ e = SetActivePanel (CalibrationPanelHandle); if(e)breakpoint(); e = SetCtrlVal (CalibrationPanelHandle, CALIBRATE_CURRENT, calibration_current); e = SetCtrlVal (CalibrationPanelHandle, CALIBRATE_NS, NS); if(e)breakpoint(); e = SetCtrlVal (CalibrationPanelHandle, CALIBRATE_GAIN, gain); if(e)breakpoint(); if (Rs_Effective>20) Rs_Effective=R_SHUNT; e = SetCtrlVal (CalibrationPanelHandle, CALIBRATE_RS_NOW, Rs_Effective); if (e<0&&e!=-14)breakpoint(); ctrl=-1; while (ctrl!=CALIBRATE_EXIT) { bin_current = 0; for (i=0; i represents .1v FS w/ gain = 100 */ /* i.e. ".1v = 2048" so 1v=20480 */ voltage = (double)bin_current/(double)number_of_samples / 20480; e = SetCtrlVal (CalibrationPanelHandle, CALIBRATE_VOLTAGE, voltage); if (e<0&&e!=-14)breakpoint(); Rs_Effective = fabs(voltage / calibration_current); if (voltage<.001) Rs_Effective = R_SHUNT; e = SetCtrlVal (CalibrationPanelHandle, CALIBRATE_RS_EFFECTIVE, Rs_Effective); if (e)breakpoint(); i_sat = vmax/Rs_Effective; e = SetCtrlVal (CalibrationPanelHandle, CALIBRATE_IMAX, i_sat); if (e<0&&e!=-14)breakpoint(); if (ctrl==CALIBRATE_SAVEPANEL) e = OutputPanel (3, "hpgl", 1, CalibrationPanelHandle); if (e<0&&e!=-14)breakpoint(); e = GetUserEvent (0, &i, &ctrl); if(e<0)breakpoint(); /**/ /* Rs_Effective = .03333333; */ i_sat = I_SAT; /* temporary setting, eliminate when doing actual cal */ } /* END "while (ctrl!==CALIBRATE_EXIT)" LOOP */ /*ggg*/ Rs_Effective = R_SHUNT; } /*лллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллллл*/ void PopCat (char head[51], char tail[51]) { /* MESSAGE STRING CONCATENATION POPUP */ int s, t; t = StringLength (head); Fmt (buf, "%s", head); s = StringLength (tail); CopyBytes (buf, t, tail, 0, s); MessagePopup (buf); } /* if(FileHandle==-1) MessagePopup ("NONEXISTENT \"setup.pro\" setup file"); if(FileHandle==-1) MessagePopup ("Can"t write to READ-ONLY \"setup.pro\""); */ /* void PopNofile (char file[50]) { Fmt (buf, "READ ONLY OR NONEXISTANT \"%s\" FILE:", file); MessagePopup (buf); } */ /***************************************************************************/ /***************************************************************************/ /* END SUBROUTINES */ /***************************************************************************/ /***************************************************************************/ /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ /* > > > > > > > > > > > > > BEGIN > > > > > > > > > > > > > > > > > > > */ /* < < < < < < < < < < < < < END < < < < < < < < < < < < < < < < < < < */ /* COLORS: BLACK0 BLUE1 GREEN2 CYAN3 RED4 MAGENTA5 BROWN6 LTGRAY7 DKGRAY8 LTBLUE9 LTGREEN10 LTCYAN11 LTRED12 LTMAGENTA13 YELLOW14 WHITE15 [1] real real --orig-- sum_current[i] += urrentBuffer[i]; unning_aerage[i] = um_curent[i]/cycle; unning_aerage[i] += urrentBuffer[i]; unning_aerage[i] += unning_aveage[i] / (double) cycle; Copy1D (ReadRealData, size, current_average); /copy readrealdata to cur_ave if(dsperr)breakpoint(); check global variable "dsperr" for Copy1D error ttt e = SetCtrlVal (SetupPanelHandle, SETUP_RATE, (int)rate); if (e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_GAIN, gain); if(e<0)breakpoint(); e = SetCtrlVal (SetupPanelHandle, SETUP_PROFILE, profilename); if (e<0)breakpoint(); case SETUP_GET: /SF5/ /GET SETUP.PRO SETUP FILE/ /ssset/ FileHandle = OpenFile ("setup.pro", READ, ASIS, BINARY); if(FileHandle==-1) MessagePopup ("NONEXISTENT \"setup.pro\" setup file"); e = ScanFile (FileHandle, "%d %s %d", &setup_type, profilename, &cycle); if (e<0)breakpoint(); e = CloseFile (FileHandle); if (e<0)breakpoint(); profile(READ, profilename); e = SetCtrlVal (SetupPanelHandle, SETUP_PROFILENAME, profilename);if(e<0)breakpoint(); fill_setup(); first_run_flag = FALSE; setup_type = 0; e = SetActiveCtrl (SETUP_PROFILENAME); if(e<0)breakpoint(); break; */