main()
{
	string systemName = getSystemName();
	
	//this is IV curve command
	dpConnect("requestIVCurve", systemName+"requestIVCurve.trigger:_online.._value");
}

void requestIVCurve(string dpeTrigger, bool trigger)
{
	int crate, channel, Twait, response;
	unsigned startIVCurve;
	float Vstart, Vstop, Vstep, Vend, Imax;
	string parameters;
	string allChannels;
	dyn_string para_split;
 
 	string systemName = getSystemName();
	
	//command executed on trigger value TRUE
	if(trigger)
		{
		  //get the command parameters
		  dpGet(systemName+"requestIVCurve.parameters:_online.._value", parameters);
		  para_split=strsplit(parameters,"|");
		  //DebugN("==================== para_split = ", para_split);

		  //sscanf(para_split[1],"%f", mod_ID);
		  sscanf(para_split[1],"%d", crate);
		  sscanf(para_split[2],"%s", allChannels);
 		  sscanf(para_split[3],"%f", Vstart);
		  sscanf(para_split[4],"%f", Vstop);DebugN("==================== Vstop = ", Vstop);
		  sscanf(para_split[5],"%f", Vstep);
		  sscanf(para_split[6],"%f", Vend);
		  sscanf(para_split[7],"%f", Imax);
		  sscanf(para_split[8],"%d", Twait);DebugN("==================== Twait = ", Twait);

		  if(allChannels == "ALL")
			{
				//IV curve for all channels
	 	  		channel = 255;
			}
	  	  else
			{
	   			sscanf(allChannels,"%d", channel);
	   			
			}
			
		  //sey the IV curve parameters
		  dpSet(systemName+"IVCurve.Crate.Send:_original.._value",    crate);
		  dpSet(systemName+"IVCurve.Channel.Send:_original.._value",  channel);
		  dpSet(systemName+"IVCurve.HV_Start.Send:_original.._value", Vstart);
		  dpSet(systemName+"IVCurve.HV_Stop.Send:_original.._value",  Vstop);
		  dpSet(systemName+"IVCurve.HV_Step.Send:_original.._value",  Vstep);
		  dpSet(systemName+"IVCurve.HV_End.Send:_original.._value",   Vend);
		  dpSet(systemName+"IVCurve.Curr_Max.Send:_original.._value", Imax);
		  dpSet(systemName+"IVCurve.TimeWait.Send:_original.._value", Twait);
		  
		  // start time of the IV curve
		  dpSet(systemName+"IVCurve.StartTime:_original.._value", getCurrentTime());
		  //trigger the IV curve start
		  dpSet(systemName+"IVCurve.StartIVCurve.Send:_original.._value", 1);
		  delay(1);
		  //here is setting of reponse parameter
		  response = 0; //(0 means cmmand successfull)
		  if(response != 0) response = 0-response; //response code in DDC is coded negatif
    	  dpSet(systemName+"requestIVCurve.response:_original.._value", response,
                systemName+"requestIVCurve.trigger:_original.._value", !trigger);
 	  }//enf of(trigger)

}//end of requestIVCurve(..)

