|
#include "inst.h"
|
|
#include <utility.h>
|
|
#include "var.h"
|
|
/**
|
|
* @brief cmd_load
|
|
* @param [in] volt consigne de tension en volt
|
|
* @param [in] curr consigne de courant en ampere
|
|
* @param [in] etat 1 ON
|
|
* @return 0
|
|
* @date 05/10/2011
|
|
*
|
|
*/
|
|
int cmd_load (float volt,float curr,int etat)
|
|
{
|
|
int language;
|
|
int handle;
|
|
char message [255];
|
|
char message_LOG [255];
|
|
if(instrument[INST_LOAD].present==1)
|
|
{
|
|
handle=instrument[INST_LOAD].port.handle;
|
|
language=instrument[INST_LOAD].port.language;
|
|
|
|
sprintf(message,"VOLT %2.4E",volt);
|
|
if (language==ARPS)
|
|
{
|
|
sprintf(message,"VSET %2.3fV",volt);
|
|
}
|
|
inst_WriteInstrData (handle,message);
|
|
|
|
sprintf(message,"CURR %2.4E",curr);
|
|
if (language==ARPS)
|
|
{
|
|
sprintf(message,"ISET %2.3fA",curr);
|
|
}
|
|
inst_WriteInstrData (handle,message);
|
|
sprintf(message,"INP %d",etat);
|
|
if (language==ARPS)
|
|
{
|
|
sprintf(message,"LOAD %d",etat); //a v?rifier
|
|
}
|
|
inst_WriteInstrData (handle,message);
|
|
if(Ctrl.verbose)
|
|
{
|
|
sprintf (message_LOG," LOAD volt=%f curr=%f etat=%d", volt, curr,etat);
|
|
save_LOG(message_LOG);
|
|
}
|
|
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_LOAD_V,volt);
|
|
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_LOAD_I,curr);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
/**
|
|
* @brief gestion de l'alimentation
|
|
* @param[in] tension en Volt de l'alimentation
|
|
* @param[in] courant en ampere
|
|
* @param[in] etat 1 ON
|
|
* @return 0
|
|
* @date 05/10/2011
|
|
*
|
|
*/
|
|
int cmd_power(float volt,float curr,int etat)
|
|
{
|
|
int language;
|
|
int handle;
|
|
char message[1024];
|
|
char message_LOG[1024];
|
|
if(instrument[INST_POWER].present==1)
|
|
{
|
|
handle=instrument[INST_POWER].port.handle;
|
|
language=instrument[INST_POWER].port.language;
|
|
sprintf(message,"CURR %2.2E",curr);
|
|
inst_WriteInstrData (handle,message );
|
|
sprintf(message,"VOLT %2.2E",volt);
|
|
inst_WriteInstrData (handle,message );
|
|
sprintf(message,"OUTP %d",etat);
|
|
inst_WriteInstrData (handle,message );
|
|
if(Ctrl.verbose)
|
|
{
|
|
sprintf (message_LOG," POWER volt=%f curr=%f etat=%d", volt, curr,etat);
|
|
save_LOG(message_LOG);
|
|
}
|
|
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_POWER_V,volt);
|
|
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_POWER_I,curr);
|
|
}
|
|
return 0;
|
|
}
|
|
/**
|
|
* @brief cmd_display_text
|
|
* @param [IN] instrum
|
|
* @param [IN] string
|
|
* @return 0
|
|
* @date 12/01/2011
|
|
*
|
|
*/
|
|
int cmd_display_text(int instrum,char* txt)
|
|
{
|
|
char message[255];
|
|
if(instrument[instrum].present==1)
|
|
{
|
|
sprintf(message,":DISP:TEXT:DATA \"%s\"",txt);
|
|
inst_WriteInstrData (instrument[instrum].port.handle,message );
|
|
}
|
|
return 0;
|
|
}
|
|
/**
|
|
* @brief read YOKOGAWA volt out
|
|
* @return 0
|
|
* @date 10/12/2010
|
|
*
|
|
*/
|
|
|
|
int read_PM_volt(double *volt)
|
|
{
|
|
char buffer [1024];
|
|
char message [1024];
|
|
char message_LOG [1024];
|
|
int nboctet;
|
|
int handle;
|
|
int i;
|
|
if(instrument[INST_PM].present==1)
|
|
{
|
|
handle=instrument[INST_PM].port.handle;
|
|
sprintf(message,":NUMERIC:NORMAL:VALUE?");
|
|
inst_WriteInstrData (handle,message);
|
|
inst_ReadInstrData (handle, 1024,buffer, &nboctet);
|
|
if(buffer[0]=='I')
|
|
{
|
|
Delay(0.5);
|
|
inst_WriteInstrData (handle,message);
|
|
inst_ReadInstrData (handle, 1024,buffer, &nboctet);
|
|
if(buffer[0]=='I')
|
|
{
|
|
cmd_PM_CAL_V(2,consigne[0].Vout*1.5) ;
|
|
Delay(0.5);
|
|
inst_WriteInstrData (handle,message);
|
|
inst_ReadInstrData (handle, 1024,buffer, &nboctet);
|
|
}
|
|
|
|
}
|
|
if(buffer[0]=='N')
|
|
{
|
|
i=0;
|
|
do
|
|
{ if(Ctrl.stop==1)
|
|
return 1;
|
|
++i;
|
|
Delay(0.5);
|
|
inst_WriteInstrData (handle,message);
|
|
inst_ReadInstrData (handle, 1024,buffer, &nboctet);
|
|
if (i>20)
|
|
{
|
|
Ctrl.stop=1;
|
|
sprintf (message_LOG,"STOP ERROR READ PM volt=%f buffer: %s", *volt,buffer);
|
|
save_LOG(message_LOG);
|
|
return -1;
|
|
}
|
|
}while(buffer[0]=='N');
|
|
|
|
}
|
|
*volt=atof(buffer);
|
|
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_DCDCout_V,*volt);
|
|
if(Ctrl.verbose || *volt==0.0)
|
|
{
|
|
sprintf (message_LOG," READ PM volt=%f buffer: %s", *volt,buffer);
|
|
save_LOG(message_LOG);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
/**
|
|
* @brief read_PM_YOKOGAWA
|
|
* @return 0
|
|
* @date 10/10/2013
|
|
*
|
|
*/
|
|
int read_PM_YOKOGAWA(double *Vin,double *Iin,double *Pin,
|
|
double *Vout,double *Iout,double *Pout,double *V3,double *V4,double *I3,double *I4,double *P3,double *P4)
|
|
{
|
|
|
|
char buffer [1024];
|
|
char message [1024];
|
|
int nboctet;
|
|
int handle;
|
|
|
|
|
|
if(instrument[INST_PM].present==1)
|
|
{
|
|
|
|
handle=instrument[INST_PM].port.handle;
|
|
sprintf(message,":NUMERIC:NORMAL:VALUE?");
|
|
inst_WriteInstrData (handle,message);
|
|
inst_ReadInstrData (handle, 1024,buffer, &nboctet);
|
|
sscanf(buffer,"%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf"
|
|
,Vin,Iin,Pin
|
|
,Vout,Iout,Pout
|
|
,V3,I3,P3
|
|
,V4,I4,P4);
|
|
if(Ctrl.verbose)
|
|
{
|
|
sprintf (message," READ PM %f,%f,%f,%f,%f,%f",*Vin,*Iin,*Pin
|
|
,*Vout,*Iout,*Pout);
|
|
save_LOG(message);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
}
|
|
/**
|
|
* @brief read_PM_YOKOGAWA
|
|
* @return 0
|
|
* @date 10/12/2010
|
|
*
|
|
*/
|
|
int read_Cal_PM_YOKOGAWA(double *CalVin,double *CalIin,
|
|
double *CalVout,double *CalIout)
|
|
{
|
|
|
|
char buffer [1024];
|
|
char message [1024];
|
|
int nboctet;
|
|
int handle;
|
|
|
|
if(instrument[INST_PM].present==1)
|
|
{
|
|
|
|
handle=instrument[INST_PM].port.handle;
|
|
sprintf(message,":INPUT:CURRENT:RANGE?");
|
|
inst_WriteInstrData (handle,message);
|
|
inst_ReadInstrData (handle, 1024,buffer, &nboctet);
|
|
sscanf(buffer,":CURR:RANG:ELEM %lf;ELEM2 %lf"
|
|
,CalIin,CalIout);
|
|
sprintf(message,":INPUT:VOLTAGE:RANGE?");
|
|
inst_WriteInstrData (handle,message);
|
|
inst_ReadInstrData (handle, 1024,buffer, &nboctet);
|
|
sscanf(buffer,":VOLT:RANG:ELEM %lf;ELEM2 %lf"
|
|
,CalVin,CalVout);
|
|
if(Ctrl.verbose)
|
|
{
|
|
sprintf (message," READ CAL PM %f,%f,%f,%f",*CalVin,*CalIin,*CalVout,*CalIout);
|
|
save_LOG(message);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* @brief Calibre Power Meter volt
|
|
* @return 0
|
|
* @date 23/09/2011
|
|
*
|
|
*/
|
|
int cmd_PM_CAL_V(int element,double setting)
|
|
{
|
|
char message [1024];
|
|
double valeur;
|
|
if(instrument[INST_PM].present==1)
|
|
{
|
|
|
|
//15, 30, 60, 100, 150, 300, 600, 1000
|
|
|
|
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:ELEMENT%d %1.4E",element,valeur);
|
|
inst_WriteInstrData (instrument[INST_PM].port.handle,message );
|
|
|
|
}
|
|
return 0;
|
|
}
|
|
/**
|
|
* @brief trig
|
|
* @param [in] inst_afg instrument afg
|
|
|
|
* @return 0
|
|
* @date 10/12/2010
|
|
*
|
|
*/
|
|
int cmd_AFG_trig(int inst_afg)
|
|
{
|
|
char message [1024];
|
|
if(instrument[inst_afg].present==1)
|
|
{
|
|
|
|
sprintf(message,"TRIGger:SEQuence:IMMediate");
|
|
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
|
|
}
|
|
return 0;
|
|
}
|
|
/**
|
|
* @brief output on
|
|
* @param [in] inst_afg instrument afg
|
|
* @param [in] phase
|
|
* @param [in] etat ON|OFF
|
|
* @return 0
|
|
* @date 10/12/2010
|
|
*
|
|
*/
|
|
int cmd_AFG_out(int inst_afg,int phase,int etat)
|
|
{
|
|
char message [1024];
|
|
if(instrument[inst_afg].present==1)
|
|
{
|
|
if(etat==1)
|
|
sprintf(message,"OUTPut%d:STATe ON",phase);
|
|
else
|
|
sprintf(message,"OUTPut%d:STATe OFF",phase);
|
|
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
|
|
}
|
|
return 0;
|
|
}
|
|
/**
|
|
* @brief freq
|
|
* @param [in] inst_afg instrument afg
|
|
* @param [in] phase
|
|
* @return 0
|
|
* @date 10/12/2010
|
|
*
|
|
*/
|
|
int cmd_AFG_freq(int inst_afg,int phase)
|
|
{
|
|
char message [1024];
|
|
if(instrument[inst_afg].present==1)
|
|
{
|
|
sprintf(message,"SOURce%d:PULSe:PERiod %1.4E",phase,1/consigne[0].freq);
|
|
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
|
|
}
|
|
return 0;
|
|
}
|
|
/**
|
|
* @brief retard de phase
|
|
* @param [in] num_afg numero afg
|
|
* @param [in] phase
|
|
* @return 0
|
|
* @date 10/12/2010
|
|
*
|
|
*/
|
|
int cmd_AFG_delay(int inst_afg,int phase)
|
|
{
|
|
char message [1024];
|
|
float retard=0;
|
|
if(instrument[inst_afg].present==1)
|
|
{
|
|
if(consigne[0].interleaving==0)
|
|
retard=0;
|
|
else
|
|
{
|
|
switch (consigne[0].phase)
|
|
{
|
|
case 0:
|
|
case 1:
|
|
retard=0;
|
|
break;
|
|
case 2:
|
|
switch (phase)
|
|
{
|
|
case 1:
|
|
if(inst_afg==INST_AFG)
|
|
retard=0; //GBF1 PH1
|
|
else
|
|
retard=0; //GBF2 PH1
|
|
break;
|
|
case 2:
|
|
if(inst_afg==INST_AFG)
|
|
retard=(1/consigne[0].freq)/2; //GBF1 PH2
|
|
else
|
|
retard=0; //GBF2 PH2
|
|
break;
|
|
}
|
|
break;
|
|
case 3:
|
|
switch (phase)
|
|
{
|
|
case 1:
|
|
if(inst_afg==INST_AFG)
|
|
retard=0; //GBF1 PH1
|
|
else
|
|
retard=(2/consigne[0].freq)/3; //GBF2 PH1
|
|
break;
|
|
case 2:
|
|
if(inst_afg==INST_AFG)
|
|
retard=(1/consigne[0].freq)/3; //GBF1 PH2
|
|
else
|
|
retard=0; //GBF2 PH2
|
|
break;
|
|
}
|
|
break;
|
|
case 4:
|
|
switch (phase)
|
|
{
|
|
case 1:
|
|
if(inst_afg==INST_AFG)
|
|
retard=0; //GBF1 PH1
|
|
else
|
|
retard=(2/consigne[0].freq)/4; //GBF2 PH1
|
|
break;
|
|
case 2:
|
|
if(inst_afg==INST_AFG)
|
|
retard=(1/consigne[0].freq)/4;//GBF1 PH2
|
|
else
|
|
retard=(3/consigne[0].freq)/4;//GBF2 PH2
|
|
break;
|
|
|
|
}
|
|
break;
|
|
default:
|
|
retard=0;
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
sprintf(message,"SOURce%d:BURSt:TDELay %1.3Es",phase,retard);
|
|
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
|
|
}
|
|
return 0;
|
|
}
|
|
/**
|
|
* @brief PWM
|
|
* @param [in] inst_afg instrument afg
|
|
* @param [in] phase
|
|
* @return 0
|
|
* @date 10/12/2010
|
|
*
|
|
*/
|
|
int cmd_AFG_pwm(int inst_afg,int phase,double pwm)
|
|
{
|
|
char message [1024];
|
|
if(instrument[inst_afg].present==1)
|
|
{
|
|
sprintf(message,"SOURce%d:PULSe:DCYCle %1.4E",phase,pwm);
|
|
inst_WriteInstrData (instrument[inst_afg].port.handle,message );
|
|
if(Ctrl.verbose)
|
|
{
|
|
sprintf (message," AGF inst=%d phase=%d duty=%f", inst_afg,phase,pwm);
|
|
save_LOG(message);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* @brief PWM
|
|
* @param [in] inst_afg instrument afg
|
|
* @param [in] phase
|
|
* @return 0
|
|
* @date 10/12/2010
|
|
*
|
|
*/
|
|
int cmd_AFG_pwm_ALL(double pwm)
|
|
{
|
|
char message [1024];
|
|
if(instrument[INST_AFG].present==1 || instrument[INST_AFG_2].present==1)
|
|
{
|
|
|
|
sprintf(message,"SOURce1:PULSe:DCYCle %1.4E;:SOURce2:PULSe:DCYCle %1.4E",pwm,pwm);
|
|
if(instrument[INST_AFG].present==1)
|
|
{
|
|
inst_WriteInstrData (instrument[INST_AFG].port.handle,message );
|
|
if(Ctrl.verbose)
|
|
{
|
|
sprintf (message," AFG duty=%f",pwm);
|
|
save_LOG(message);
|
|
}
|
|
}
|
|
if(instrument[INST_AFG_2].present==1)
|
|
{
|
|
inst_WriteInstrData (instrument[INST_AFG_2].port.handle,message );
|
|
if(Ctrl.verbose)
|
|
{
|
|
sprintf (message," AFG 2 duty=%f",pwm);
|
|
save_LOG(message);
|
|
}
|
|
}
|
|
SetCtrlVal (T_panel[PANEL_MEASURE].panel,P_MEASURE_PWM,pwm);
|
|
}
|
|
return 0;
|
|
}
|