| 1,4 → 1,3 |
| #include <tcpsupp.h> |
| #include "H1D.h" |
| #include "H2D.h" |
| #include <formatio.h> |
| 7,34 → 6,18 |
| #include <cvirte.h> |
| #include <userint.h> |
| #include "drs4.h" |
| #include "scaler.h" |
| #include "drsread.h" |
| #include "K6517.h" |
| |
| K6517STATUS K6517Stat; |
| static int K6517_Interface,K6517_Port,K6517_Gdev; |
| //#define MIKRO |
| #define MIKRO |
| |
| #ifdef MIKRO |
| #include "MIKRO.h" |
| #endif |
| |
| |
| /*---------------------------------------------------------------------------*/ |
| /* Module-globals */ |
| /*---------------------------------------------------------------------------*/ |
| static unsigned int g_hconversation; |
| static int g_hmainPanel; |
| static int g_connected = 0; |
| static int g_TCPError = 0; |
| |
| |
| int daq_on; |
| int ph, p2,p3,p4, plothandle[4]= {0,0,0,0}; |
| static int qdcplothandle[4]= {0,0,0,0}; |
| static int daq_on; |
| static int ph, p2,plothandle[4]= {0,0,0,0}; |
| static int scanplothandle; |
| static int tfID; |
| static int rID; |
| static int controlID; |
| |
| #define MAX_THREADS 10 |
| 42,13 → 25,6 |
| static CmtThreadPoolHandle poolHandle = 0; |
| |
| static float gSum[4]={0,0,0,0}; |
| |
| |
| int gActive[4]= {0,0,0,0}; |
| double gTwinMin[4]= {0,0,0,0}; |
| double gTwinMax[4]= {0,0,0,0}; |
| double gFx[4]= {0,0,0,0}; |
| |
| int main (int argc, char *argv[]) { |
| short port; |
| if (InitCVIRTE (0, argv, 0) == 0) |
| 57,12 → 33,6 |
| return -1; |
| if ((p2 = LoadPanel (0, "drs4.uir", SCAN)) < 0) |
| return -1; |
| if ((p3 = LoadPanel (0, "drs4.uir", QDC)) < 0) |
| return -1; |
| if ((p4 = LoadPanel (0, "scaler.uir", SCALER)) < 0) |
| return -1; |
| |
| DisableBreakOnLibraryErrors(); |
| SetStdioPort (CVI_STDIO_WINDOW); |
| SetSleepPolicy(VAL_SLEEP_MORE); |
| CmtNewThreadPool (MAX_THREADS, &poolHandle); |
| 69,8 → 39,7 |
| |
| DisplayPanel (ph); |
| DisplayPanel (p2); |
| DisplayPanel (p3); |
| DisplayPanel (p4); |
| |
| #ifdef MIKRO |
| GetCtrlVal(p2, SCAN_PORT, &port); |
| if (MIKRO_Open (port)) MessagePopup ("Error", "Mikro Port Not found !\n Change in the GUI") ; |
| 78,17 → 47,11 |
| MIKRO_Init(2,0); |
| #endif |
| |
| K6517_open (1,4,3,0,13); |
| |
| RunUserInterface (); |
| DiscardPanel (ph); |
| DiscardPanel (p2); |
| DiscardPanel (p3); |
| DiscardPanel (p4); |
| CmtDiscardThreadPool (poolHandle); |
| #ifdef MIKRO |
| MIKRO_Close (); |
| #endif |
| MIKRO_Close (); |
| return 0; |
| } |
| |
| 129,14 → 92,7 |
| |
| |
| |
| void CVICALLBACK EndOfThresholdScanThread ( CmtThreadPoolHandle poolhandle, |
| CmtThreadFunctionID functionID, unsigned int event, |
| int value, void *callbackData ) { |
| printf("End of Threshold Scan Thread \n"); |
| return ; |
| |
| } |
| |
| void CVICALLBACK EndOfThread ( CmtThreadPoolHandle poolhandle, |
| CmtThreadFunctionID functionID, unsigned int event, |
| int value, void *callbackData ) { |
| 150,7 → 106,6 |
| |
| |
| static float xs[4][1024]; |
| |
| int CVICALLBACK daq(void *functionData) { |
| |
| |
| 171,28 → 126,20 |
| int neveold = 0; |
| double rate; |
| int *args = (int *) functionData; |
| double twin[2]; |
| |
| int wfm=0; |
| const int init[4] = { QDC_INIT_1 ,QDC_INIT_2 ,QDC_INIT_3 ,QDC_INIT_4 }; |
| const int fx[4] = { PANEL_SCALE_1 ,PANEL_SCALE_2 ,PANEL_SCALE_3 ,PANEL_SCALE_4 }; |
| const int active[4] = { QDC_ACTIVE_1 ,QDC_ACTIVE_2 ,QDC_ACTIVE_3 ,QDC_ACTIVE_4 }; |
| |
| |
| GetCtrlVal(ph, PANEL_CH0, &imask[0] ); |
| GetCtrlVal(ph, PANEL_CH1, &imask[1] ); |
| GetCtrlVal(ph, PANEL_CH2, &imask[2] ); |
| GetCtrlVal(ph, PANEL_CH3, &imask[3] ); |
| GetCtrlVal(p3, QDC_WFM, &wfm ); |
| mask = 0; |
| for (int i=0; i<4; i++) { |
| if (imask[i]) { |
| mask |= (1<<i); |
| ScaleCB(ph,fx[i],EVENT_COMMIT,NULL, 0,0); |
| SetActiveCB(p3,active[i],EVENT_COMMIT,NULL, 0,0); |
| InitQdcHistogramCB(p3, init[i],EVENT_COMMIT,NULL, 0,0); |
| } |
| if (imask[i]) mask |= (1<<i); |
| } |
| LogScaleCB(p3, QDC_LOGY,EVENT_COMMIT,NULL, 0,0); |
| |
| |
| |
| GetCtrlVal(ph,PANEL_NEVE, &neve); |
| GetCtrlVal(ph,PANEL_DEBUG, &verbose); |
| 209,7 → 156,8 |
| GetCtrlVal(ph,PANEL_TRGPOLARITY, &trgpolarity); |
| GetCtrlVal(ph,PANEL_RANGE, &range); |
| |
| |
| GetCtrlVal(ph,PANEL_TWIN0, &twin[0]); |
| GetCtrlVal(ph,PANEL_TWIN1, &twin[1]); |
| //printf("mask=0x%x\n",mask); |
| |
| DRSSetMask( (unsigned char)( mask & 0xF ) ); |
| 228,14 → 176,12 |
| FILE *fp= NULL; |
| |
| if (enabledoutput) { |
| if (1==1) { |
| if (args[0]) { |
| GetCtrlVal(ph, PANEL_FILENAME, filename ); |
| printf("%s\n", filename); |
| fp = fopen(filename,"wb"); |
| } else { |
| GetCtrlVal(p2, SCAN_FILENAME, filename ); |
| fp = fopen(filename,"ab"); |
| printf("%s\n", filename); |
| } |
| } |
| |
| 273,7 → 219,6 |
| if (!daq_on) break; |
| time(&t); |
| if (t!=told ) { |
| PlotQdcHistogramCB(0,0,EVENT_COMMIT,NULL, 0,0); |
| rate = (i-neveold); |
| printf("%d events in %2.2f min (%d s) Rate %f Hz %s ",i+1, (double)(t-tstart)/60.,(t-tstart), rate , ctime(&t)); |
| GetCtrlVal(ph,PANEL_PFREQ, &pfreq); |
| 281,37 → 226,23 |
| } |
| told=t; |
| // Save data |
| |
| if (nb>0 && fp) fwrite(buffer, 1,nb ,fp); |
| // Plot Data |
| |
| for (int k=0; k<4; k++) { |
| if ( (mask & ( 0x1<<k )) ){ |
| double fSum= 0; |
| float *t=DRSGetTime(k); |
| float *x=DRSGetWave(k); |
| ; |
| for (int j=0 ; j<1024 ; j++) { |
| xs[k][j]= x[j]*1e-3*gFx[k]; |
| if (gActive[k]){ |
| if (t[j]> gTwinMin[k] && t[j] < gTwinMax[k]) { |
| fSum+= fabs(xs[k][j]); |
| } |
| if (wfm){ |
| H2D_Fill(200+k,t[j], xs[k][j],1); |
| } |
| //if (verbose) printf("[%d] %d. x= %3.2f y=%3.2f\n", k, i, t[j], x[j] ); |
| } |
| xs[k][j]= x[j]*1e-3; |
| |
| if (t[j]> twin[0] && t[j] < twin[1]) gSum[k]+= fabs(xs[k][j]); |
| if (verbose) printf("[%d] %d. x= %3.2f y=%3.2f\n", k, i, t[j], x[j] ); |
| //h[k]->Fill( t[i], x[i]*1e-3); |
| } |
| if (verbose) printf("qdc[%d] %3.2f active=%d\n", k, fSum ,gActive[k]); |
| if (gActive[k]) { |
| if (!wfm) { |
| H1D_Fill(200+k,fSum,1.); |
| } |
| } |
| gSum[k]+=fSum; |
| |
| |
| if (i % pfreq == 0) { |
| |
| const int col[4]= {VAL_WHITE,VAL_RED,VAL_GREEN,VAL_BLUE}; |
| if (plothandle[k]) DeleteGraphPlot (ph, PANEL_GRAPH, plothandle[k], VAL_IMMEDIATE_DRAW); |
| plothandle[k] = PlotXY (ph, PANEL_GRAPH, t, xs[k], 1024, VAL_FLOAT, VAL_FLOAT, VAL_THIN_LINE, VAL_NO_POINT, VAL_SOLID, 1, col[k]); |
| 336,271 → 267,7 |
| } |
| |
| |
| void CVICALLBACK EndOfThrScan ( CmtThreadPoolHandle poolhandle, |
| CmtThreadFunctionID functionID, unsigned int event, |
| int value, void *callbackData ) { |
| |
| |
| //SetDimming(0); |
| printf("End of thrscan \n"); |
| return ; |
| |
| } |
| |
| |
| |
| int scaler(int min, int max, int dx, int time_set, char *filename); |
| |
| int CVICALLBACK thrscan(void *functionData) { |
| char str[0xFF]; |
| char path[0xFF]; |
| |
| int step,min,max, mtime; |
| GetCtrlVal(p4, SCALER_STEP,&step); |
| GetCtrlVal(p4, SCALER_TIME,&mtime); |
| GetCtrlVal(p4, SCALER_MAX,&max); |
| GetCtrlVal(p4, SCALER_MIN,&min); |
| GetCtrlVal(ph, PANEL_FILENAME,path); |
| |
| sprintf(str, "%s.thr", path); |
| scaler(min,max,step,mtime,str); |
| return 0; |
| |
| |
| } |
| |
| |
| int CVICALLBACK acquire_data (void *arg) { |
| |
| |
| char *sarg = (char *) arg; |
| printf("sarg %s\n", sarg); |
| char str[0xFF]; |
| char path[0xFF]; |
| GetCtrlVal(ph,PANEL_PATH,path); |
| sprintf(str, "%s%s.dat", path, sarg); |
| SetCtrlVal(ph, PANEL_FILENAME,str); |
| |
| int flag=0; |
| ThreadFunctionPtr mythread = thrscan; |
| int data; |
| int threadhandle; |
| CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &data, |
| DEFAULT_THREAD_PRIORITY, |
| EndOfThresholdScanThread, |
| EVENT_TP_THREAD_FUNCTION_END, |
| NULL, RUN_IN_SCHEDULED_THREAD, |
| &threadhandle); |
| daq(&flag); |
| CmtWaitForThreadPoolFunctionCompletionEx (poolHandle, threadhandle, OPT_TP_PROCESS_EVENTS_WHILE_WAITING, CMT_WAIT_FOREVER); |
| return 0; |
| } |
| |
| int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) |
| { |
| unsigned char state; |
| switch (event) |
| { |
| case EVENT_COMMIT: |
| GetCtrlVal(panel, control, &state); |
| K6517_vsource_operate (state); |
| break; |
| } |
| return 0; |
| } |
| |
| |
| int CVICALLBACK SetVoltageCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| double vbr; |
| switch (event) { |
| case EVENT_COMMIT: |
| GetCtrlVal (ph, PANEL_VBR, &vbr ); |
| K6517_vsource_set (vbr+2); |
| break; |
| } |
| return 0; |
| } |
| |
| |
| |
| int TScan () { |
| |
| double temp; |
| double volt,vbr; |
| int n=0; |
| int led; |
| GetNumTableRows (ph, PANEL_TABLE, &n ); |
| daq_on = 1; |
| for(int i=0; i<n; i++) { |
| if (!daq_on) break; |
| GetTableCellVal (ph, PANEL_TABLE, MakePoint (1,i+1), &temp); |
| GetTableCellVal (ph, PANEL_TABLE, MakePoint (2,i+1), &vbr); |
| if (temp>100) break; |
| char transmitBuf[512]= {0}; |
| sprintf(transmitBuf, "1 %f\n", temp); |
| |
| |
| if (g_connected) |
| if ( ClientTCPWrite (g_hconversation, transmitBuf, strlen (transmitBuf), 1000) < 0) printf("Transmit Error\n"); else printf("%s\n", transmitBuf); |
| SetCtrlVal(ph,PANEL_LED, 0); |
| do { |
| time_t t0 = time(NULL); |
| SetCtrlVal(ph,PANEL_TIME, ctime(&t0)); |
| Delay(1); |
| GetCtrlVal(ph,PANEL_LED, &led); |
| if (led) { |
| for (int k=0;k<10;k++){ |
| Delay(1); |
| if (!daq_on) break; |
| } |
| GetCtrlVal(ph,PANEL_LED, &led); |
| } |
| if (!daq_on) break; |
| } while (!led); |
| if (!daq_on) break; |
| |
| int itemp = (int) temp; |
| int n1=0; |
| GetNumTableRows (ph, PANEL_VTABLE, &n1 ); |
| |
| for(int k=0; k<n1; k++) { |
| if (!daq_on) break; |
| GetTableCellVal (ph, PANEL_VTABLE, MakePoint (1,k+1), &volt); |
| if (volt<-100) break; |
| double voltage = vbr + volt; |
| int ivolt=(int)(volt*100); |
| K6517_vsource_set (voltage); |
| K6517_vsource_operate (1); |
| char str[0xFF]; |
| sprintf(str,"%d_%d", itemp, ivolt); |
| printf("%d %d %s\n",i,k, str); |
| acquire_data(str); |
| K6517_vsource_operate (0); |
| } |
| } |
| |
| return 0; |
| } |
| |
| int CVICALLBACK TScanCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| |
| switch (event) { |
| case EVENT_COMMIT:{ |
| ThreadFunctionPtr mythread = TScan; |
| CmtScheduleThreadPoolFunctionAdv (poolHandle, mythread, &rID, |
| DEFAULT_THREAD_PRIORITY, |
| EndOfThread, |
| EVENT_TP_THREAD_FUNCTION_END, |
| NULL, RUN_IN_SCHEDULED_THREAD, |
| &tfID); |
| } |
| break; |
| } |
| return 0; |
| } |
| |
| int CVICALLBACK LogScaleCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| |
| |
| const unsigned int gr[4] = { QDC_GRAPH_1 ,QDC_GRAPH_2 ,QDC_GRAPH_3 ,QDC_GRAPH_4 }; |
| int wfm=0; |
| int attr, logy, selected; |
| switch (event) { |
| case EVENT_COMMIT: |
| GetCtrlVal(p3,QDC_WFM,&wfm); |
| GetCtrlVal(panel, control, &selected); |
| |
| attr= ATTR_YMAP_MODE; |
| if(selected) logy=VAL_LOG; else logy=VAL_LINEAR; |
| if (wfm) logy=VAL_LINEAR; |
| for (int i=0;i<4;i++) SetCtrlAttribute (panel, gr[i],attr, logy); |
| break; |
| } |
| |
| return 0; |
| } |
| |
| int CVICALLBACK ExecRootCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| switch (event) { |
| case EVENT_COMMIT:{ |
| char fileName[100]; |
| char fname[100]; |
| char path[100]; |
| int trgchannel; |
| GetCtrlVal(panel, PANEL_FILENAME, fileName); |
| GetCtrlVal(panel,PANEL_TRGCHANNEL, &trgchannel); |
| GetCtrlVal(panel, PANEL_PATH, path); |
| sprintf(fname, "%s/%s", path, fileName); |
| //sprintf(fname, "%s", fileName); |
| int status; |
| char name[MAX_PATHNAME_LEN]; |
| // char dfile[MAX_PATHNAME_LEN]; |
| // char efile[MAX_PATHNAME_LEN]; |
| // status = FileSelectPopup ("dat", "*.dat", ".dat", |
| // "Izberi datoteko s podatki", |
| // VAL_LOAD_BUTTON, 0, 0, 1, 0, efile); |
| // EscapeString(efile,dfile); |
| sprintf(name ,"C:/home/dominik/runroot.bat \"C:/home/dominik/AnalyseWaveForms.cxx(-1,1000,\\\"%s\\\",%d)\" ", fname, trgchannel); |
| |
| printf("%s\n",name); |
| LaunchExecutable(name); |
| break; |
| } |
| } |
| return 0; |
| } |
| |
| |
| int CVICALLBACK TempTableCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| switch (event) { |
| case EVENT_COMMIT: { |
| int status; |
| char name[MAX_PATHNAME_LEN]; |
| char dfile[MAX_PATHNAME_LEN]; |
| char efile[MAX_PATHNAME_LEN]; |
| status = FileSelectPopup ("dat", "*.dat", ".dat", |
| "Izberi datoteko s podatki", |
| VAL_LOAD_BUTTON, 0, 0, 1, 0, efile); |
| printf("%s", efile); |
| |
| |
| FILE *fp=fopen(efile,"r"); |
| float I; |
| float V; |
| int temp; |
| int ndim=400; |
| char line[400]; |
| if (fp) { |
| int k=0; |
| while (fgets(line,ndim,fp)!=NULL) { |
| k++; |
| sscanf(line,"%*s%d%f%f",&temp,&I,&V); |
| printf("%d %f %f\n", temp, I, V); |
| SetTableCellVal (ph, PANEL_TABLE, MakePoint (1,k), (double)temp); |
| SetTableCellVal (ph, PANEL_TABLE, MakePoint (2,k), V); |
| |
| } |
| |
| SetTableCellVal (ph, PANEL_TABLE, MakePoint (1,k+1), 1000.0); |
| fclose(fp); |
| |
| |
| } |
| break; |
| } |
| } |
| return 0; |
| } |
| |
| |
| |
| |
| int CVICALLBACK scan(void *functionData) { |
| |
| int dx[3]={0,0,0}; |
| 705,8 → 372,6 |
| } |
| |
| |
| |
| |
| int CVICALLBACK StartCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| ThreadFunctionPtr mythread = NULL; |
| 720,12 → 385,6 |
| controlID= control; |
| } |
| if (panel == p2 && control == SCAN_SCAN) mythread = scan; |
| if (panel == p4 && control == SCALER_START) mythread = thrscan; |
| if (panel == ph && control == PANEL_ACQUIRE) { |
| mythread = acquire_data; |
| controlID=50; |
| } |
| |
| if (mythread!=NULL) { |
| printf("New Thread panel=%d button=%d\n", panel, control); |
| |
| 875,61 → 534,6 |
| return 0; |
| } |
| |
| int CVICALLBACK InitQdcHistogramCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| const int min[4] = { QDC_MIN_1 ,QDC_MIN_2 ,QDC_MIN_3 ,QDC_MIN_4 }; |
| const int max[4] = { QDC_MAX_1 ,QDC_MAX_2 ,QDC_MAX_3 ,QDC_MAX_4 }; |
| const int nbin[4] = { QDC_NBIN_1 ,QDC_NBIN_2 ,QDC_NBIN_3 ,QDC_NBIN_4 }; |
| |
| const int init[4] = { QDC_INIT_1 ,QDC_INIT_2 ,QDC_INIT_3 ,QDC_INIT_4 }; |
| char title[0xFF]; |
| char name[0xFF]; |
| switch (event) { |
| case EVENT_COMMIT:{ |
| int ctrl=-1; |
| for (int k=0;k<4;k++) if ( init[k]==control & panel==p3 ) ctrl=k; |
| if (ctrl<0) break; |
| double minx; |
| double maxx; |
| int nbins; |
| int wfm; |
| int frq; |
| GetCtrlVal(p3,min[ctrl],&minx); |
| GetCtrlVal(p3,max[ctrl],&maxx); |
| GetCtrlVal(p3,nbin[ctrl],&nbins); |
| GetCtrlVal(p3,QDC_WFM,&wfm); |
| GetCtrlVal(ph,PANEL_FREQUENCY,&frq); |
| sprintf(name,"qdc%d", ctrl); |
| sprintf(title,"QDC ch %d", ctrl); |
| H1D_Init(200+ctrl, name, title, nbins, minx,maxx); |
| sprintf(name,"avgwfm%d", ctrl); |
| sprintf(title,"Average waveform ch %d", ctrl); |
| H2D_Init(200+ctrl, name, title, 1024, 0,1024/frq, 100, -0.5,0.5); |
| break; |
| } |
| } |
| return 0; |
| |
| } |
| |
| |
| int CVICALLBACK PlotQdcHistogramCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| int hid=0; |
| int nx; |
| int ny; |
| const unsigned int gr[4] = { QDC_GRAPH_1 ,QDC_GRAPH_2 ,QDC_GRAPH_3 ,QDC_GRAPH_4 }; |
| int wfm=0; |
| switch (event) { |
| case EVENT_COMMIT: |
| GetCtrlVal(p3,QDC_WFM,&wfm); |
| for (int i=0;i<4;i++) if (wfm) H2D_Draw(200+i,p3,gr[i],&qdcplothandle[i]); else H1D_Draw(200+i,p3,gr[i],&qdcplothandle[i]); |
| break; |
| } |
| return 0; |
| } |
| |
| |
| int CVICALLBACK PlotScanHistogramCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| int hid=0; |
| 969,19 → 573,6 |
| return 0; |
| } |
| |
| |
| int CVICALLBACK OpenQdcCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| switch (event) { |
| case EVENT_COMMIT: |
| DisplayPanel (ph); |
| DisplayPanel (p3); |
| break; |
| } |
| return 0; |
| } |
| |
| |
| int CVICALLBACK CalibrateCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| int status = 0; |
| 993,162 → 584,3 |
| } |
| return 0; |
| } |
| |
| int CVICALLBACK SetActiveCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| const int c[4] = { QDC_ACTIVE_1 ,QDC_ACTIVE_2 ,QDC_ACTIVE_3 ,QDC_ACTIVE_4 }; |
| const double twin0[4] = { QDC_TWIN0_1 ,QDC_TWIN0_2 ,QDC_TWIN0_3 ,QDC_TWIN0_4 }; |
| const double twin1[4] = { QDC_TWIN1_1 ,QDC_TWIN1_2 ,QDC_TWIN1_3 ,QDC_TWIN1_4 }; |
| int val=0; |
| switch (event) { |
| case EVENT_COMMIT: |
| GetCtrlVal(panel, control, &val); |
| int ctrl=-1; |
| for (int k=0;k<4;k++) if ( c[k]==control & panel==p3 ) ctrl=k; |
| if (ctrl<0) break; |
| |
| gActive[ctrl] = val; |
| GetCtrlVal(panel, twin0[ctrl], &gTwinMin[ctrl]); |
| GetCtrlVal(panel, twin1[ctrl], &gTwinMax[ctrl]); |
| printf("Channel gActive[%d]=%d tmin %f tmax %f\n", ctrl,gActive[ctrl], gTwinMin[ctrl], gTwinMax[ctrl]); |
| break; |
| } |
| return 0; |
| } |
| |
| int CVICALLBACK ScaleCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| const int c[4] = { PANEL_SCALE_1 ,PANEL_SCALE_2 ,PANEL_SCALE_3 ,PANEL_SCALE_4 }; |
| switch (event) { |
| case EVENT_COMMIT: { |
| double val; |
| GetCtrlVal(panel, control, &val); |
| int ctrl=-1; |
| for (int k=0;k<4;k++) if ( c[k]==control & panel==ph ) ctrl=k; |
| if (ctrl<0) break; |
| gFx[ctrl] = val; |
| printf("Scaling factor gFx[%d]=%f\n", ctrl,gFx[ctrl]); |
| |
| break; |
| } |
| } |
| return 0; |
| } |
| |
| |
| |
| |
| /*---------------------------------------------------------------------------*/ |
| /* Macros */ |
| /*---------------------------------------------------------------------------*/ |
| #define tcpChk(f) if ((g_TCPError=(f)) < 0) {ReportTCPError();} |
| |
| |
| /*---------------------------------------------------------------------------*/ |
| /* Internal function prototypes */ |
| /*---------------------------------------------------------------------------*/ |
| int CVICALLBACK ClientTCPCB (unsigned handle, int event, int error, |
| void *callbackData); |
| static void ReportTCPError (void); |
| |
| |
| /*---------------------------------------------------------------------------*/ |
| /* Report TCP Errors if any */ |
| /*---------------------------------------------------------------------------*/ |
| static void ReportTCPError(void) |
| { |
| if (g_TCPError < 0) |
| { |
| char messageBuffer[1024]; |
| sprintf(messageBuffer, |
| "TCP library error message: %s\nSystem error message: %s", |
| GetTCPErrorString (g_TCPError), GetTCPSystemErrorString()); |
| MessagePopup ("Error", messageBuffer); |
| g_TCPError = 0; |
| } |
| } |
| /*---------------------------------------------------------------------------*/ |
| |
| |
| int CVICALLBACK DisconnectCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| switch (event) { |
| case EVENT_COMMIT: |
| if (g_connected) |
| DisconnectFromTCPServer (g_hconversation); |
| g_hconversation = 0; |
| g_connected = 0; |
| break; |
| } |
| return 0; |
| } |
| |
| int CVICALLBACK ConnectCB (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { |
| int portNum=10000; |
| char tempBuf[512]; |
| sprintf(tempBuf,"localhost"); |
| switch (event) { |
| case EVENT_COMMIT: |
| if (g_connected) return 0; |
| if (ConnectToTCPServer (&g_hconversation, portNum, tempBuf, ClientTCPCB, NULL, 5000) < 0) |
| MessagePopup("TCP Client", "Connection to server failed !"); |
| else |
| { |
| SetWaitCursor (0); |
| g_connected = 1; |
| |
| /* We are successfully connected -- gather info */ |
| |
| if (GetTCPHostAddr (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
| if (GetTCPHostName (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
| |
| tcpChk (GetTCPPeerAddr (g_hconversation, tempBuf, 256)); |
| printf("%s\n" ,tempBuf); |
| tcpChk (GetTCPPeerName (g_hconversation, tempBuf, 256)); |
| printf("%s\n" ,tempBuf); |
| } |
| break; |
| } |
| return 0; |
| } |
| |
| |
| int CVICALLBACK ClientTCPCB (unsigned handle, int event, int error, void *callbackData) |
| { |
| char receiveBuf[256] = {0}; |
| ssize_t dataSize = sizeof (receiveBuf) - 1; |
| |
| switch (event) |
| { |
| case TCP_DATAREADY: |
| if ((dataSize = ClientTCPRead (g_hconversation, receiveBuf, |
| dataSize, 1000)) |
| < 0) |
| { |
| printf( "Receive Error\n"); |
| } |
| else |
| { |
| receiveBuf[dataSize] = '\0'; |
| //printf("%s", receiveBuf); |
| float temp = 0; |
| float humidity = 0; |
| float dt=0; |
| float tdiff=0; |
| int t0 = 0; |
| sscanf(receiveBuf, "%d%f%f%f%f", &t0,&humidity,&temp, &tdiff, &dt); |
| SetCtrlVal(ph,PANEL_TMON, temp); |
| SetCtrlVal(ph,PANEL_HUMIDITY, humidity); |
| if (fabs(tdiff)<0.2 && fabs(dt) < 0.05) SetCtrlVal(ph,PANEL_LED, 1); |
| else SetCtrlVal(ph,PANEL_LED, 0); |
| } |
| break; |
| case TCP_DISCONNECT: |
| MessagePopup ("TCP Client", "Server has closed connection!"); |
| |
| g_connected = 0; |
| |
| break; |
| } |
| return 0; |
| } |