Project

General

Profile

Files » init.c

Frédéric Blanc, 2016-01-29 09:58

 
/**
* @brief init DCDC
* @date 17/10/2011
* @author F.BLANC LAAS-CNRS
*
*/


#include "asynctmr.h"
#include <utility.h>
#include "inst.h"
#include "var.h"
/**
* @brief fatal error
* @param string error
* @date 17/10/2011
*
*/
void fatal_error (char msg[])
{
MessagePopup ("Error", msg);
exit(-1);
}

/**
* @brief init main
* @param [in] name of file UIR
* @return 0
* @date 19/10/2012
*
*/
int init_main (char uir[])
{
int i;
char chn_nom_LOG[MAX_PATHNAME_LEN];
char chemin_nom[MAX_PATHNAME_LEN];
char message[255];
char message_LOG[255];
if ((T_panel[PANEL_TOP].panel = LoadPanel (0, uir, P_TOP)) < 0)
fatal_error("bad UIR");
if ((T_panel[PANEL_ABOUT].panel = LoadPanel (T_panel[PANEL_TOP].panel, uir, P_ABOUT)) < 0)
fatal_error("bad UIR");
if ((T_panel[PANEL_LOG].panel = LoadPanel (T_panel[PANEL_TOP].panel, uir, P_LOG )) < 0)
fatal_error("bad UIR");
if ((T_panel[PANEL_PORT].panel = LoadPanel (T_panel[PANEL_TOP].panel, uir, P_PORT )) < 0)
fatal_error("bad UIR");
if ((T_panel[PANEL_CONTROL].panel = LoadPanel (T_panel[PANEL_TOP].panel, uir, P_CONTROL )) < 0)
fatal_error("bad UIR");
if ((T_panel[PANEL_MEASURE].panel = LoadPanel (T_panel[PANEL_TOP].panel, uir, P_MEASURE )) < 0)
fatal_error("bad UIR");
if ((T_panel[PANEL_GRAPH].panel = LoadPanel (T_panel[PANEL_TOP].panel, uir, P_GRAPH2D )) < 0)
fatal_error("bad UIR");
if ((T_panel[PANEL_INFO].panel = LoadPanel (T_panel[PANEL_TOP].panel, uir, P_INFO )) < 0)
fatal_error("bad UIR");
if ((barre_de_menu = LoadMenuBar (T_panel[PANEL_TOP].panel, uir, MENU_DCDC)) < 0)
fatal_error("bad UIR");
// fichier log
GetDir (chn_nom_LOG);
sprintf (chn_nom_LOG, "%s\\%s", chn_nom_LOG,"banc_mesures.log");
file_LOG= fopen (chn_nom_LOG, "a");
if(file_LOG==NULL)
{
save_LOG("Save file init");
save_LOG(chn_nom_LOG);
save_LOG(" FAIL");
}
save_LOG("----------------------------------------------------------------------------------------------------------------");
save_LOG("RUN TESTER DC/DC");
sprintf (message_LOG," version CVI : %s",VERSION);
save_LOG(message_LOG);
GetCtrlVal (T_panel[PANEL_ABOUT].panel,P_ABOUT_VERSION_UIR,message);
sprintf (message_LOG," version UIR : %s",message);
save_LOG(message_LOG);

SetCtrlVal (T_panel[PANEL_ABOUT].panel,P_ABOUT_VERSION,VERSION);
DisplayPanel (T_panel[PANEL_TOP].panel);
//XML
save_LOG("initialization parameters from consigne file");
GetDir (chemin_nom);
sprintf (chemin_nom, "%s\\%s", chemin_nom,"consigne.xml");
if(load_consigne_xml(chemin_nom))
{
save_LOG("Load file consigne.xml");
save_LOG(chemin_nom);
save_LOG(" FAIL");
}else
{
save_LOG(" OK");
}
save_LOG("initialization parameters from XML file");
if(load_xml())
{
save_LOG(" FAIL");
init_usine ();
}else
{
save_LOG(" OK");
init_panel();
DisplayPanel (T_panel[PANEL_LOG].panel);
init_instrument ();
init_panel_Measure(1);
DisplayPanel(T_panel[PANEL_MEASURE].panel);
}
Set_panel_control();
Ctrl.Simul=0;
DisplayPanel (T_panel[PANEL_CONTROL].panel);
//TIMER
save_LOG("initialization CVI_TIMER OFF");
Ctrl.timer_id=NewAsyncTimer (1.0, -1, 0, CVI_timer, 0);
return 0;

}
/**
* @brief init panel DCDC
* @param dimmed
* @return 0
* @date 05/10/2011
*
*/
int init_panel_Measure(int dimmed)
{
if(instrument[INST_POWER].present==1)
{
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_POWER_V,ATTR_VISIBLE, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_POWER_I,ATTR_VISIBLE, 1);
SetCtrlVal(T_panel[PANEL_CONTROL].panel,P_CONTROL_V3,Ctrl.m_V3);
SetCtrlVal(T_panel[PANEL_CONTROL].panel,P_CONTROL_V4,Ctrl.m_V4);
SetCtrlVal(T_panel[PANEL_CONTROL].panel,P_CONTROL_I3,Ctrl.m_I3);
SetCtrlVal(T_panel[PANEL_CONTROL].panel,P_CONTROL_I4,Ctrl.m_I4);
SetCtrlVal(T_panel[PANEL_CONTROL].panel,P_CONTROL_P3,Ctrl.m_P3);
SetCtrlVal(T_panel[PANEL_CONTROL].panel,P_CONTROL_P4,Ctrl.m_P4);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_V3,ATTR_VISIBLE, Ctrl.m_V3);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_V4,ATTR_VISIBLE, Ctrl.m_V4);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_I3,ATTR_VISIBLE, Ctrl.m_I3);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_I4,ATTR_VISIBLE, Ctrl.m_I4);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_P3,ATTR_VISIBLE, Ctrl.m_P3);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_P4,ATTR_VISIBLE, Ctrl.m_P4);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_POWER_V,ATTR_DIMMED, dimmed);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_POWER_I,ATTR_DIMMED, dimmed);
}
if( instrument[INST_AFG].present==1)
{
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_FREQ,ATTR_VISIBLE, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PWM,ATTR_VISIBLE, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_INTER,ATTR_VISIBLE, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_FREQ,ATTR_DIMMED, dimmed);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PWM,ATTR_DIMMED, dimmed);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_INTER,ATTR_DIMMED, dimmed);
}
if( instrument[INST_LOAD].present==1)
{
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_LOAD_V,ATTR_VISIBLE, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_LOAD_I,ATTR_VISIBLE, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_LOAD_V,ATTR_DIMMED, dimmed);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_LOAD_I,ATTR_DIMMED, dimmed);
}

if( instrument[INST_PM].present==1)
{
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCin_V,ATTR_VISIBLE, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCin_I,ATTR_VISIBLE, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCin_P,ATTR_VISIBLE, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCout_V,ATTR_VISIBLE, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCout_I,ATTR_VISIBLE, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCout_P,ATTR_VISIBLE, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_n_DCDC,ATTR_VISIBLE, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCin_V,ATTR_DIMMED, dimmed);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCin_I,ATTR_DIMMED, dimmed);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCin_P,ATTR_DIMMED, dimmed);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCout_V,ATTR_DIMMED, dimmed);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCout_I,ATTR_DIMMED, dimmed);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCout_P,ATTR_DIMMED, dimmed);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_n_DCDC,ATTR_DIMMED, dimmed);
}
if(instrument[INST_POWER].present==1 && instrument[INST_LOAD].present==1 && instrument[INST_AFG].present==1 && instrument[INST_PM].present==1)
{
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_START,ATTR_VISIBLE, 1);
SetMenuBarAttribute (barre_de_menu, MENU_DCDC_CONF_Simul, ATTR_DIMMED, 1);
}
return 0;
}
/**
* @brief init close main
* @param [in] name of file UIR
* @return 0
* @date 17/10/2011
*
*/
int init_close (void)
{
int i;
char message_LOG[1024];
char chemin_nom[MAX_PATHNAME_LEN];
// save_LOG("CVI_TIMER OFF");
// test_LOG(SetAsyncTimerAttribute (timer_id,ASYNC_ATTR_ENABLED,0 ));//desactivation timer
save_LOG("STOP GUI");
save_LOG("Save XML");
GetDir (chemin_nom);
sprintf (chemin_nom, "%s\\%s", chemin_nom,"consigne.xml");
Get_panel_control();
save_consigne_xml(chemin_nom);
for(i=0;i<MAX_PANEL;i++)
{
GetPanelAttribute (T_panel[i].panel, ATTR_TOP, &T_panel[i].top);
GetPanelAttribute (T_panel[i].panel, ATTR_LEFT,&T_panel[i].left);
GetPanelAttribute (T_panel[i].panel, ATTR_HEIGHT, &T_panel[i].height);
GetPanelAttribute (T_panel[i].panel, ATTR_WIDTH,&T_panel[i].width);
}
test_LOG(save_xml());
for(i=0;i<MAX_INSTRUMENT;i++)
{
if (instrument[i].present)
{
sprintf (message_LOG,"CLOSE IVI %s",instrument[i].port.instrDescr);
save_LOG(message_LOG);
test_LOG(inst_close (instrument[i].port.handle)); //fermeture setion visa
}
}
save_LOG("****************************************************************************************************************");
fclose (file_LOG);
return 0;
}

/**
* @brief init_GBF
* @param [in] num_gbf numero gbf
* @return 0
* @date 23/09/2011
*
*/
int init_AFG(int inst_afg)
{
int i,phase;
char message [1024];
char message2 [1024];
char message_LOG [1024];
switch(inst_afg)
{
case INST_AFG :
sprintf(message,"AFG");
break;
case INST_AFG_2 :
sprintf(message,"AFG 2");
break;
}
instrument[inst_afg].present=0;
instrument[inst_afg].actif =0;
if(instrument[inst_afg].port.typeCOM>-1 )
if(initcom (&instrument[inst_afg].port))
{
SetCtrlVal(T_panel[PANEL_CONTROL].panel,P_CONTROL_RINGPHAS,0);
sprintf (message_LOG,"INSTRUMENT %s ",message);
save_LOG(message_LOG);
save_LOG(" FAIL");
} else
{
instrument[inst_afg].present=1;
instrument[inst_afg].actif =1;
cmd_display_text(inst_afg,message);
sprintf (message_LOG,"INSTRUMENT %s ",message);
save_LOG(message_LOG);
init_type_inst(inst_afg);
if(strcmp (instrument[inst_afg].constructeur,"TEKTRONIX")==0)
{
instrument[inst_afg].type=AFG3022;
save_LOG("---");
// parametre default
sprintf(message,"SOURce:ROSCillator:SOURce EXTernal"); //ref 10MHz ext
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
sprintf(message,"SOURce1:FREQuency:CONCurrent ON"); //freq ch2=ch1
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
if(inst_afg==INST_AFG)
sprintf(message,"TRIGger:SEQuence:SOURce TIMer"); //GBF1 TRIG int
else
sprintf(message,"TRIGger:SEQuence:SOURce EXTernal"); //GBF2 TRIG ext
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
sprintf(message,"TRIGger:SEQuence:SLOPe POSitive"); //front montant
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
for(phase=1;phase<=2;++phase)
{
sprintf(message,"SOURce%d:BURSt:MODE TRIGgered",phase);
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
sprintf(message,"SOURce%d:BURSt:NCYCles INFinity",phase);
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
sprintf(message,"SOURce%d:BURSt:DELay 0.0ns",phase);
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
sprintf(message,"SOURce%d:BURSt:STATe ON",phase);
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
sprintf(message,"SOURce%d:FUNCtion:SHAPe PULSe",phase);
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
sprintf(message,"OUTPut%d:IMPedance INFinity",phase);
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
sprintf(message,"SOURce%d:VOLTage:LEVel:IMMediate:HIGH 5V",phase);
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
sprintf(message,"SOURce%d:VOLTage:LEVel:IMMediate:LOW 0V",phase);
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
sprintf(message,"SOURce%d:PULSe:DCYCle 5.0",phase);
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
cmd_AFG_freq(inst_afg,phase);
cmd_AFG_delay(inst_afg,phase);
}
}
}
return 0;
}
/**
* @brief init instrunemt
* @param [in] num_intrument
* @return 0
* @date 23/09/2011
*
*/
int init_type_inst(int inst)
{
char message [255];
char message_LOG [255];
char *ptr,*str;
int ic;
if(instrument[inst].port.language==SCPI)
{
sprintf(message,"*RST");
inst_WriteInstrData (instrument[inst].port.handle,message );
ic=0;
str= strchr (instrument[inst].port.instrDescr,',' );
for(ptr=instrument[inst].port.instrDescr;ptr<str;ptr++)
instrument[inst].constructeur[ic++]=*ptr;
str=strchr (++ptr,',' );
ic=0;
for(;ptr<str;ptr++)
instrument[inst].model[ic++]=*ptr;
str=strchr (++ptr,',' );
ic=0;
for(;ptr<str;ptr++)
instrument[inst].num_serie[ic++]=*ptr;
str=strchr (++ptr,'/' );
ic=0;
for(;ptr<str;ptr++)
instrument[inst].date_CAL[ic++]=*ptr;
save_LOG("+++");
sprintf (message_LOG," %s ",instrument[inst].constructeur);
save_LOG(message_LOG);
sprintf (message_LOG," %s ",instrument[inst].model);
save_LOG(message_LOG);
sprintf (message_LOG," %s ",instrument[inst].num_serie);
save_LOG(message_LOG);
sprintf (message_LOG," %s ",instrument[inst].date_CAL);
save_LOG(message_LOG);
}
return 0;
}

/**
* @brief init LOAD
* @param [in] num_LOAD numeroLOAD
* @return 0
* @date 23/09/2011
*
*/
int init_LOAD(int inst_load)
{
char message [1024];
char message_LOG [1024];
instrument[inst_load].present=0;
instrument[inst_load].actif =0;
sprintf(message,"LOAD");
if(instrument[inst_load].port.typeCOM>-1 )
if(initcom (&instrument[inst_load].port))
{
sprintf (message_LOG,"INSTRUMENT %s ",message);
save_LOG(message_LOG);
save_LOG(" FAIL");
} else
{
instrument[inst_load].present=1;
instrument[inst_load].actif =1;
sprintf (message_LOG,"INSTRUMENT %s ",message);
save_LOG(message_LOG);
init_type_inst(inst_load);
if(strcmp (instrument[inst_load].constructeur,"HOECHERL&HACKL")==0)
{
instrument[inst_load].type=HHZS;
instrument[inst_load].port.language=SCPI;
save_LOG("---");
}
else if(strcmp (instrument[inst_load].constructeur,"HEWLETT-PACKARD")==0)
{
if(strcmp (instrument[inst_load].model,"6060B")==0)
{
instrument[inst_load].type=LOAD6060B;
instrument[inst_load].port.language=SCPI;
save_LOG("---");
}
else
save_LOG("ATTENTION POWER ?");
}
else if(instrument[inst_load].port.instrDescr[0]='?')
{
instrument[inst_load].port.language=ARPS;
sprintf(instrument[inst_load].model,"PLZ1003W");
sprintf (message_LOG,"%s ",instrument[inst_load].model);
save_LOG(message_LOG);
instrument[inst_load].type=PLZ;
sprintf(message,"PSET 900W");
inst_WriteInstrData (instrument[inst_load].port.handle,message);
sprintf(message,"CCRANGE 0");//Curr LOW gamme
inst_WriteInstrData (instrument[inst_load].port.handle,message);
save_LOG(" Curr LOW gamme 20A");
sprintf(message,"CV 0");//CV OFF
save_LOG(" CV OFF");
inst_WriteInstrData (instrument[inst_load].port.handle,message);
sprintf(message,"CCR 1");//CC ON
inst_WriteInstrData (instrument[inst_load].port.handle,message);
save_LOG(" CC ON");
save_LOG("---");
}
}
return 0;
}
/**
* @brief init POWER
* @param [in] num_power numero power
* @return 0
* @date 23/09/2011
*
*/
int init_POWER(int inst_power)
{
char message [1024];
char message_LOG [1024];
instrument[inst_power].present=0;
instrument[inst_power].actif =0;
sprintf(message,"POWER");
if(instrument[inst_power].port.typeCOM>-1 )
if(initcom (&instrument[inst_power].port))
{
sprintf (message_LOG,"INSTRUMENT %s ",message);
save_LOG(message_LOG);
save_LOG(" FAIL");
} else
{
instrument[inst_power].present=1;
instrument[inst_power].actif =1;
sprintf (message_LOG,"INSTRUMENT %s ",message);
save_LOG(message_LOG);
init_type_inst(inst_power);
if(strcmp (instrument[inst_power].constructeur,"HEWLETT-PACKARD")==0)
{
if(strcmp (instrument[inst_power].model,"6032A")==0)
{
instrument[inst_power].type=SPS6032A;
save_LOG("---");
}
}
if(instrument[inst_power].port.language==ARPS)
{
if(instrument[inst_power].port.instrDescr[0]='?')
{
//sprintf(instrument[inst_power].model,"PLZ1003W");
//instrument[inst_power].type=PLZ;
save_LOG("---");
}
}
}
return 0;
}

/**
* @brief init Power Meter
* @return 0
* @date 19/10/2012
*
*/
int init_PM_measure(void)
{
char message [1024];
if(instrument[INST_PM].present==1)
{
sprintf(message,":NUM:ITEM1 UDC,2;:NUM:ITEM2 IDC,1;:NUM:ITEM3 P,1");
if(strcmp (instrument[INST_PM].model,"760304-04-SV")==0) //WT3000
sprintf(message,":NUM:ITEM1 U,2;:NUM:ITEM2 I,1;:NUM:ITEM3 P,1");
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
sprintf(message,":NUM:ITEM4 UDC,1;:NUM:ITEM5 IDC,2;:NUM:ITEM6 P,2");
if(strcmp (instrument[INST_PM].model,"760304-04-SV")==0) //WT3000
sprintf(message,":NUM:ITEM4 U,1;:NUM:ITEM5 I,2;:NUM:ITEM6 P,2");
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
sprintf(message,":NUM:ITEM7 UDC,3;:NUM:ITEM10 UDC,4;");
if(strcmp (instrument[INST_PM].model,"760304-04-SV")==0) //WT3000
sprintf(message,":NUM:ITEM7 U,3;:NUM:ITEM10 U,4;");
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
if(strcmp (instrument[INST_PM].model,"760304-04-SV")==0) //WT3000
{
sprintf(message,":CURRent:MODE:ALL DC");
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
sprintf(message,":VOLTage:MODE:ALL DC");
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
}
}
return 0;
}
/**
* @brief init Power Meter
* @return 0
* @date 23/09/2011
*
*/
int init_PM_CAL(void)
{
char message [1024];
double valeur,setting;
if(instrument[INST_PM].present==1)
{
if(measure[0].CalVin_Auto==0)
{
//15, 30, 60, 100, 150, 300, 600, 1000
setting=max(consigne[0].Vin_START,consigne[0].Vin_STOP);
if(setting<=15)
valeur=15;
else
if(setting<=30)
valeur=30;
else
if(setting<=60)
valeur=60;
else
if(setting<=100)
valeur=100;
else
if(setting<=150)
valeur=150;
else
if(setting<=300)
valeur=300;
else
if(setting<=600)
valeur=600;
else
valeur=1000;
sprintf(message,":INPUT:VOLTAGE:RANGE:ELEMENT1 %1.4E",valeur);
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
sprintf(message,"CAL VOLTAGE IN %1.1f V",valeur);
save_LOG(message);
}else
{
sprintf(message,":INPUT:VOLTAGE:AUTO:ELEMENT1 ON");
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
sprintf(message,"CAL VOLTAGE IN AUTO");
save_LOG(message);
}
if(measure[0].CalVout_Auto==0)
{
if(consigne[0].Vout_MAX<=15)
valeur=15;
else
if(consigne[0].Vout_MAX<=30)
valeur=30;
else
if(consigne[0].Vout_MAX<=60)
valeur=60;
else
if(consigne[0].Vout_MAX<=100)
valeur=100;
else
if(consigne[0].Vout_MAX<=150)
valeur=150;
else
if(consigne[0].Vout_MAX<=300)
valeur=300;
else
if(consigne[0].Vout_MAX<=600)
valeur=600;
else
valeur=1000;
sprintf(message,":INPUT:VOLTAGE:RANGE:ELEMENT2 %1.4E",valeur);
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
sprintf(message,"CAL VOLTAGE OUT %1.1f V",valeur);
save_LOG(message);
}else
{
sprintf(message,":INPUT:VOLTAGE:AUTO:ELEMENT2 ON");
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
sprintf(message,"CAL VOLTAGE OUT AUTO");
save_LOG(message);
}
//currnet500 (mA), 1, 2, 5, 10, 20, 30
if(measure[0].CalIin_Auto==0)
{
if(consigne[0].Iin_MAX<=0.5)
valeur=0.5;
else
if(consigne[0].Iin_MAX<=1)
valeur=1;
else
if(consigne[0].Iin_MAX<=2)
valeur=2;
else
if(consigne[0].Iin_MAX<=5)
valeur=5;
else
if(consigne[0].Iin_MAX<=10)
valeur=10;
else
if(consigne[0].Iin_MAX<=20)
valeur=20;
else
valeur=30;
sprintf(message,":INPUT:CURRENT:RANGE:ELEMENT1 %1.4E",valeur);
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
sprintf(message,"CAL CURRENT IN %1.1f A",valeur);
save_LOG(message);
}else
{
sprintf(message,":INPUT:CURRENT:AUTO:ELEMENT1 ON");
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
sprintf(message,"CAL CURRENT IN AUTO");
save_LOG(message);
}
if(measure[0].CalIout_Auto==0)
{
setting=max(consigne[0].Pout_START/min(consigne[0].Vout_START,consigne[0].Vout_STOP),consigne[0].Pout_STOP/min(consigne[0].Vout_START,consigne[0].Vout_STOP));
if(setting<=0.5)
valeur=0.5;
else
if(setting<=1)
valeur=1;
else
if(setting<=2)
valeur=2;
else
if(setting<=5)
valeur=5;
else
if(setting<=10)
valeur=10;
else
if(setting<=20)
valeur=20;
else
valeur=30;
sprintf(message,":INPUT:CURRENT:RANGE:ELEMENT2 %1.4E",valeur);
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
sprintf(message,"CAL CURRENT OUT %1.1f A",valeur);
save_LOG(message);
}else
{
sprintf(message,":INPUT:CURRENT:AUTO:ELEMENT2 ON");
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
sprintf(message,"CAL CURRENT OUT AUTO");
save_LOG(message);
}
sprintf(message,":INPUT:VOLTAGE:AUTO:ELEMENT3 ON");
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
sprintf(message,"CAL VOLTAGE 3 AUTO");
save_LOG(message);
sprintf(message,":INPUT:VOLTAGE:AUTO:ELEMENT4 ON");
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
sprintf(message,"CAL VOLTAGE 4 AUTO");
save_LOG(message);
}
return 0;
}
/**
* @brief init Power Meter
* @param [in] num_PM numero PM
* @return 0
* @date 23/09/2011
*
*/

int init_PM(int inst_PM)
{
char message [1024];
char message_LOG [1024];
instrument[inst_PM].present=0;
instrument[inst_PM].actif =0;
sprintf(message,"PM");
if(instrument[inst_PM].port.typeCOM>-1 )
if(initcom (&instrument[inst_PM].port))
{
sprintf (message_LOG,"INSTRUMENT %s ",message);
save_LOG(message_LOG);
save_LOG(" FAIL");
} else
{
instrument[inst_PM].present=1;
instrument[inst_PM].actif =1;
sprintf (message_LOG,"INSTRUMENT %s ",message);
save_LOG(message_LOG);
init_type_inst(inst_PM);
if(strcmp (instrument[inst_PM].constructeur,"YOKOGAWA")==0)
{
instrument[inst_PM].type=WT;
save_LOG(" VOLTAGE GAMME AUTO");
sprintf(message,":INPUT:VOLTAGE:AUTO:ALL ON");
if(strcmp (instrument[inst_PM].model,"760304-04-SV")==0) //WT3000
Delay(1); //pb de demmarage avec WT3000
inst_WriteInstrData (instrument[inst_PM].port.handle,message );
fnct_attente (5,"ATTENTE FIN CALIBRAGE TENSION WATTMETRE");
save_LOG(" CURRENT GAMME AUTO");
sprintf(message,":INPUT:CURRENT:AUTO:ALL ON");
inst_WriteInstrData (instrument[inst_PM].port.handle,message );
fnct_attente (5,"ATTENTE FIN CALIBRAGE COURANT WATTMETRE");
sprintf(message,":NUM:ITEM1 URMS,1;:NUM:ITEM2 IRMS,1;:NUM:ITEM3 P,1");
if(strcmp (instrument[inst_PM].model,"760304-04-SV")==0) //WT3000
sprintf(message,":NUM:ITEM1 U,1;:NUM:ITEM2 I,1;:NUM:ITEM3 P,1");
inst_WriteInstrData (instrument[inst_PM].port.handle,message );
sprintf(message,":NUM:ITEM4 URMS,2;:NUM:ITEM5 IRMS,2;:NUM:ITEM6 P,2");
if(strcmp (instrument[inst_PM].model,"760304-04-SV")==0) //WT3000
sprintf(message,":NUM:ITEM4 U,2;:NUM:ITEM5 I,2;:NUM:ITEM6 P,2");
inst_WriteInstrData (instrument[inst_PM].port.handle,message );
sprintf(message,":NUM:ITEM7 URMS,3;:NUM:ITEM8 IRMS,3;:NUM:ITEM9 P,3");
if(strcmp (instrument[inst_PM].model,"760304-04-SV")==0) //WT3000
sprintf(message,":NUM:ITEM7 U,3;:NUM:ITEM8 I,3;:NUM:ITEM9 P,3");
inst_WriteInstrData (instrument[inst_PM].port.handle,message );
sprintf(message,":NUM:ITEM10 URMS,4;:NUM:ITEM11 IRMS,4;:NUM:ITEM12 P,4");
if(strcmp (instrument[inst_PM].model,"760304-04-SV")==0) //WT3000
sprintf(message,":NUM:ITEM10 U,4;:NUM:ITEM11 I,4;:NUM:ITEM12 P,4");
inst_WriteInstrData (instrument[inst_PM].port.handle,message );
//ALL DC
if(strcmp (instrument[INST_PM].model,"760304-04-SV")==0) //WT3000
{
sprintf(message,":CURRent:MODE:ALL DC");
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
sprintf(message,":VOLTage:MODE:ALL DC");
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
}
//display
sprintf(message,":MEASURE:EFFICIENCY:ETA1 P2,P1");
inst_WriteInstrData (instrument[inst_PM].port.handle,message );
sprintf(message,":DISPLAY:MODE NUMERIC");
inst_WriteInstrData (instrument[inst_PM].port.handle,message );
sprintf(message,":DISPLAY:NUMERIC:NORMAL:FORMAT VAL8");
inst_WriteInstrData (instrument[inst_PM].port.handle,message );
sprintf(message,":DISPLAY:NUMERIC:NORMAL:VAL8:ITEM4 U,2,TOTAL");
inst_WriteInstrData (instrument[inst_PM].port.handle,message );
sprintf(message,":DISPLAY:NUMERIC:NORMAL:VAL8:ITEM5 I,2,TOTAL");
inst_WriteInstrData (instrument[inst_PM].port.handle,message );
sprintf(message,":DISPLAY:NUMERIC:NORMAL:VAL8:ITEM6 P,2,TOTAL");
inst_WriteInstrData (instrument[inst_PM].port.handle,message );
sprintf(message,":DISPLAY:NUMERIC:NORMAL:VAL8:ITEM7 ETA1"); //?
inst_WriteInstrData (instrument[inst_PM].port.handle,message );
sprintf(message,":DISPLAY:NUMERIC:NORMAL:VAL8:ITEM8 NONE");
inst_WriteInstrData (instrument[inst_PM].port.handle,message );
save_LOG("---");
}
}

return 0;
}
/**
* @brief init instrument
* @param
* @return 0
* @date 14/12/2010
*
*/
int init_instrument (void)
{
char *ptr,*str;
char message [1024];
char message2 [1024];
char message_LOG [1024];
int i,ic;
for(i=0;i<MAX_INSTRUMENT;i++)
{
switch (i)
{
case INST_POWER :
init_POWER(INST_POWER);
break;
case INST_LOAD :
init_LOAD(INST_LOAD);
break;
case INST_AFG :
init_AFG(INST_AFG);
break;
case INST_AFG_2 :
init_AFG(INST_AFG_2);
break;
case INST_PM :
init_PM(INST_PM);
break;

}

}
return 0;
}
/**
* @brief init usine
* @param
* @return 0
* @date 16/10/2012
*
*/
int init_usine (void)
{
int i;
GetDir (Ctrl.racine);
init_reset_panel();
Ctrl.m_V3=0;
Ctrl.m_V4=0;
Ctrl.m_I3=0;
Ctrl.m_I4=0;
Ctrl.m_P3=0;
Ctrl.m_P4=0;
Ctrl.Iout=0;
consigne[0].nb_cycle=1;
for(i=0;i<MAX_INSTRUMENT;i++)
{
init_port(&instrument[i].port);
}
return 0;
}
/**
* @brief init panel
* @param
* @return 0
* @date 14/12/2010
*
*/
int init_reset_panel (void)
{
T_panel[PANEL_TOP].top=30;
T_panel[PANEL_TOP].left=15;
T_panel[PANEL_TOP].height=858;
T_panel[PANEL_TOP].width=936;
T_panel[PANEL_ABOUT].top=271;
T_panel[PANEL_ABOUT].left=413;
T_panel[PANEL_ABOUT].height=275;
T_panel[PANEL_ABOUT].width=375;
T_panel[PANEL_LOG].top=754;
T_panel[PANEL_LOG].left=3;
T_panel[PANEL_LOG].height=100;
T_panel[PANEL_LOG].width=930;
T_panel[PANEL_PORT].top=45;
T_panel[PANEL_PORT].left=93;
T_panel[PANEL_PORT].height=356;
T_panel[PANEL_PORT].width=755;
T_panel[PANEL_MEASURE].top=325;
T_panel[PANEL_MEASURE].left=3;
T_panel[PANEL_MEASURE].height=402;
T_panel[PANEL_MEASURE].width=930;
T_panel[PANEL_CONTROL].top=46;
T_panel[PANEL_CONTROL].left=3;
T_panel[PANEL_CONTROL].height=253;
T_panel[PANEL_CONTROL].width=611;
T_panel[PANEL_GRAPH].top=46;
T_panel[PANEL_GRAPH].left=621;
T_panel[PANEL_GRAPH].height=253;
T_panel[PANEL_GRAPH].width=311;
T_panel[PANEL_INFO].top=300;
T_panel[PANEL_INFO].left=3;
T_panel[PANEL_INFO].height=100;
T_panel[PANEL_INFO].width=930;
init_panel ();
return 0;
}
/**
* @brief init panel
* @param
* @return 0
* @date 14/12/2010
*
*/
int init_panel (void)
{
int i;
for(i=0;i<MAX_PANEL;i++)
{
SetPanelAttribute (T_panel[i].panel, ATTR_TOP, T_panel[i].top);
SetPanelAttribute (T_panel[i].panel, ATTR_LEFT,T_panel[i].left);
SetPanelAttribute (T_panel[i].panel, ATTR_HEIGHT, T_panel[i].height);
SetPanelAttribute (T_panel[i].panel, ATTR_WIDTH,T_panel[i].width);
}
return 0;
}

/**
* @brief init phase
* @return 0
* @date 23/09/2011
*
*/
int init_phase(void)
{
int test;
int ctrlarray;
switch(consigne[0].phase)
{
case 4:
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_MEASURE].panel, CTRL_AFG);
SetCtrlArrayAttribute (ctrlarray,ATTR_VISIBLE, 1);
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_CONTROL].panel, CTRL_PH0);
SetCtrlArrayAttribute (ctrlarray,ATTR_DIMMED, 0);
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_RINGPHAS_2,ATTR_DIMMED, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_1,ATTR_DIMMED, 0);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_2,ATTR_DIMMED, 0);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_3,ATTR_DIMMED, 0);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_4,ATTR_DIMMED, 0);
Ctrl.phase1=1;
Ctrl.phase2=1;
Ctrl.phase3=1;
Ctrl.phase4=1;
Ctrl.pid=1;
break;
case 3:
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_MEASURE].panel, CTRL_AFG);
SetCtrlArrayAttribute (ctrlarray,ATTR_VISIBLE, 1);
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_CONTROL].panel, CTRL_PH0);
SetCtrlArrayAttribute (ctrlarray,ATTR_DIMMED, 0);
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_RINGPHAS_2,ATTR_DIMMED, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_1,ATTR_DIMMED, 0);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_2,ATTR_DIMMED, 0);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_3,ATTR_DIMMED, 0);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_4,ATTR_DIMMED, 1);
Ctrl.phase1=1;
Ctrl.phase2=1;
Ctrl.phase3=1;
Ctrl.phase4=0;
Ctrl.pid=1;
break;
case 2:
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_MEASURE].panel, CTRL_AFG);
SetCtrlArrayAttribute (ctrlarray,ATTR_VISIBLE, 1);
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_CONTROL].panel, CTRL_PH0);
SetCtrlArrayAttribute (ctrlarray,ATTR_DIMMED, 0);
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_RINGPHAS_2,ATTR_DIMMED, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_1,ATTR_DIMMED, 0);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_2,ATTR_DIMMED, 0);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_3,ATTR_DIMMED, 1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_4,ATTR_DIMMED, 1);
Ctrl.phase1=1;
Ctrl.phase2=1;
Ctrl.phase3=0;
Ctrl.phase4=0;
Ctrl.pid=1;
break;
case 1:
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_MEASURE].panel, CTRL_AFG);
SetCtrlArrayAttribute (ctrlarray,ATTR_VISIBLE, 1);
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_CONTROL].panel, CTRL_PH0);
SetCtrlArrayAttribute (ctrlarray,ATTR_DIMMED, 0);
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_RINGPHAS_2,ATTR_DIMMED, 0);
GetCtrlVal (T_panel[PANEL_CONTROL].panel,P_CONTROL_RINGPHAS_2,&test);
switch(test)
{
case 1:
Ctrl.phase1=1;
Ctrl.phase2=0;
Ctrl.phase3=0;
Ctrl.phase4=0;
break;
case 2:
Ctrl.phase1=0;
Ctrl.phase2=1;
Ctrl.phase3=0;
Ctrl.phase4=0;
break;
case 3:
Ctrl.phase1=0;
Ctrl.phase2=0;
Ctrl.phase3=1;
Ctrl.phase4=0;
break;
case 4:
Ctrl.phase1=0;
Ctrl.phase2=0;
Ctrl.phase3=0;
Ctrl.phase4=1;
break;
}
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_1,ATTR_DIMMED, !Ctrl.phase1);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_2,ATTR_DIMMED, !Ctrl.phase2);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_3,ATTR_DIMMED, !Ctrl.phase3);
SetCtrlAttribute (T_panel[PANEL_MEASURE].panel,P_MEASURE_PH_4,ATTR_DIMMED, !Ctrl.phase4);
Ctrl.pid=1;
break;
case 0:
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_MEASURE].panel, CTRL_AFG);
SetCtrlArrayAttribute (ctrlarray,ATTR_VISIBLE, 0);
ctrlarray = GetCtrlArrayFromResourceID (T_panel[PANEL_CONTROL].panel, CTRL_PH0);
SetCtrlArrayAttribute (ctrlarray,ATTR_DIMMED, 1);
SetCtrlAttribute (T_panel[PANEL_CONTROL].panel,P_CONTROL_RINGPHAS_2,ATTR_DIMMED, 1);
Ctrl.phase1=0;
Ctrl.phase2=0;
Ctrl.phase3=0;
Ctrl.phase4=0;
Ctrl.pid=0;
break;
}
return 0;
}
(13-13/25)