void NetShrVarInterface::setValueCNV(const std::string& name, CNVData value)
{
    int wait_ms = CNVWaitForever/*CNVDoNotWait*/, b_wait_ms = CNVDoNotWait/*CNVWaitForever*/;
	NvItem* item = m_params[name];
	int error = 0;
	if (item->field != -1)
	{
        throw std::runtime_error("setValueCNV: unable to update struct variable via param \"" + name + "\"");
	}
	if (item->access & NvItem::Write)
	{
	    error = CNVWrite(item->writer, value, wait_ms);
	}
	else if (item->access & NvItem::BufferedWrite)
	{
	    error = CNVPutDataInBuffer(item->b_writer, value, b_wait_ms);
	}
	else
	{
        throw std::runtime_error("setValueCNV: param \""  + name + "\" does not define a writer for \"" + item->nv_name + "\"");
	}
	ERROR_CHECK("setValue", error);
}
Esempio n. 2
0
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);
}