void NetShrVarInterface::setValue(const char* param, const T& value) { ScopedCNVData cvalue; int status = CNVCreateScalarDataValue(&cvalue, static_cast<CNVDataType>(C2CNV<T>::nvtype), value); ERROR_CHECK("CNVCreateScalarDataValue", status); setValueCNV(param, cvalue); }
void NetShrVarInterface::setValue(const char* param, const std::string& value) { ScopedCNVData cvalue; int status = CNVCreateScalarDataValue(&cvalue, CNVString, value.c_str()); ERROR_CHECK("CNVCreateScalarDataValue", status); setValueCNV(param, cvalue); }
void fit_data (void) { int Npoints, num; double slope, intercept, residue, coef[4], value; GetCtrlVal (ERG_panel, ERG_panel_start_val, &start); GetCtrlVal (ERG_panel, ERG_panel_points_num, &Npoints); double fit[Npoints]; int maximumIndex, minimumIndex; CNVData data=0; CNVWriter writer = 0; for (int k = 0; k < Npoints; k++) fit[k] = 0; /////////////////////////////////////////////////////////////// //////////////mto do : create specific function for background subtraction int pix_num,bckgrd_satus; double bckgrd_val; GetCtrlVal (ERG_panel, ERG_panel_bckgrd_sub, &bckgrd_satus); if (bckgrd_satus==1) { GetCtrlVal (ERG_panel, ERG_panel_bckgrd, &pix_num); Mean (&data2fit[pix_num-50], 100, &bckgrd_val); j=0; while (j<10000) { buffer[j] = data2fit[j]-bckgrd_val; j++; } } else { j=0; while (j<10000) { buffer[j] = data2fit[j]; j++; } } ////////////////////////////////////////////////////////////// generate_xarray (); PlotXY (ERG_panel, ERG_panel_scope, &xarray[start], &buffer[start], Npoints, VAL_DOUBLE, VAL_DOUBLE, VAL_THIN_LINE, VAL_SOLID_SQUARE, VAL_SOLID, 1, VAL_GREEN); GetCtrlVal (ERG_panel, ERG_panel_fit_function, &j); if (j==0) { MaxMin1D(&buffer[start], Npoints, &maximumValue, &maximumIndex, &minimumValue, &minimumIndex); Npoints= minimumIndex; LinearFitEx (&xarray[start], &buffer[start], NULL, Npoints, LEAST_SQUARE, 0.0001, fit, &slope, &intercept, &residue); ////////////to do: create separated function for uploading network variable///////////// //write optimization value (slope) as a network variable CNVCreateWriter ("\\\\localhost\\ERG\\optimisation_value", 0, 0, 10000, 0, &writer); CNVCreateScalarDataValue (&data, CNVDouble, slope); // Delay(0.5); CNVWrite (writer, data, 5000); CNVDisposeData (data); Delay(0.5); // printf("Slope=%f\n", slope); } if (j==1) { Mean (&buffer[start-100], 100, &baseline); MaxMin1D(&buffer[start], Npoints, &maximumValue, &maximumIndex, &minimumValue, &minimumIndex); Npoints= minimumIndex; Mean (&buffer[start+minimumIndex-5], 10, &minimumValue); coef[0]= start+minimumIndex; coef[1]= minimumIndex/2; // printf("base=%f, min=%f\n",baseline, minimumValue); NonLinearFitWithMaxIters (&xarray[start], &buffer[start], fit, Npoints, 100, ModelFunct, coef, 2, &residue); // printf("coef1=%f, coef2=%f\n",coef[0], coef[1]); //write optimization value (rise time; coef[1]) as a network variable // coef[1]=coef[1]/10; CNVCreateWriter ("\\\\localhost\\ERG\\optimisation_value", 0, 0, 10000, 0, &writer); CNVCreateScalarDataValue (&data, CNVDouble, coef[1]/10000); CNVWrite (writer, data, 5000); CNVDisposeData (data); Delay(0.5); } if (j==2) { MaxMin1D(&buffer[start], Npoints, &maximumValue, &maximumIndex, &minimumValue, &minimumIndex); value= maximumValue - minimumValue; if (minimumIndex < maximumIndex) { Npoints=maximumIndex-minimumIndex; Copy1D (&buffer[minimumIndex+start], Npoints, fit); start= minimumIndex+start; value= maximumValue - minimumValue; } else { value= 0; } CNVCreateWriter ("\\\\localhost\\ERG\\optimisation_value", 0, 0, 10000, 0, &writer); CNVCreateScalarDataValue (&data, CNVDouble, value); CNVWrite (writer, data, 5000); CNVDisposeData (data); Delay(0.5); } PlotXY (ERG_panel, ERG_panel_scope, &xarray[start], fit, Npoints, VAL_DOUBLE, VAL_DOUBLE, VAL_THIN_LINE, VAL_SOLID_SQUARE, VAL_SOLID, 1, VAL_RED); }
int CVICALLBACK threadFunc (void *functionData) { char textline[1024]; volatile int stop = 0, loop = 0; double value = 0.0; CNVBufferedWriter bufferedWriter; CNVData data = 0; int error; char buffer[MAX_PATHNAME_LEN]; // wait for tread lock CmtGetLock (lock); // release the lock CmtReleaseLock (lock); status = 2; // run while loop SetCtrlVal (panelHandle, PANEL_STATUS, status); SetCtrlVal(panelHandle, PANEL_TEXTSTRING, "Nice! thread() has been started!"); Delay (1.0); error = NetworkVariablePopup (buffer); if (error < 0) { MessagePopup ("Error", GetGeneralErrorString(error)); return 0; } else if (error > 0) { SetCtrlVal (panelHandle, PANEL_NAME, buffer); SetWaitCursor (1); error = CNVCreateBufferedWriter (buffer, DataTransferredCallback, StatusCallback, 0, 10, 10000, 0, &bufferedWriter); SetWaitCursor (0); if (error < 0) { MessagePopup ("Error", CNVGetErrorDescription(error)); return 0; } else { SetCtrlVal (panelHandle, PANEL_CNVSTATUS, "Connected"); } } CNVCreateScalarDataValue (&data, CNVDouble, value); while (stop == 0) { SetCtrlVal (panelHandle, PANEL_LED, 0); GetCtrlVal (panelHandle, PANEL_STOPBUTTON, &stop); Delay (0.2); sprintf (textline, "%i, %i", loop++, stop); SetCtrlVal (panelHandle, PANEL_TEXTSTRING, textline); value = loop; CNVSetScalarDataValue (data, CNVDouble, value); CNVPutDataInBuffer (bufferedWriter, data, CNVDoNotWait); } SetCtrlVal(panelHandle, PANEL_TEXTSTRING, "Nice! thread() has been stopped!"); Delay (1.0); CNVDisposeData (data); CNVDispose (bufferedWriter); CNVFinish (); status = 3; // exit threadFunc() SetCtrlVal (panelHandle, PANEL_STATUS, status); return 0; }