📄 powermc.c
字号:
mark=0;
break;
}
return 0;
}
//NUMBER 3:
int CVICALLBACK ENTRY_3 (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char string[10];
switch (event)
{
case EVENT_COMMIT:
if (sign==1)
{
GetCtrlVal (panelHandle, PANEL_STRING_VOLTAGE, string);
if (strlen(string)==6&&mark!=1) break;
if (string[0]=='0'&&string[1]!='.'||mark==1)
SetCtrlVal (panelHandle, PANEL_STRING_VOLTAGE, "3");
else
{
strcat(string,"3");
SetCtrlVal (panelHandle, PANEL_STRING_VOLTAGE, string);
}
}
else
{
GetCtrlVal (panelHandle, PANEL_STRING_CURRENT, string);
if (strlen(string)==6&&mark!=1) break;
if (string[0]=='0'&&string[1]!='.'||mark==1)
SetCtrlVal (panelHandle, PANEL_STRING_CURRENT, "3");
else
{
strcat(string,"3");
SetCtrlVal (panelHandle, PANEL_STRING_CURRENT, string);
}
}
mark=0;
break;
}
return 0;
}
//NUMBER 2:
int CVICALLBACK ENTRY_2 (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char string[10];
switch (event)
{
case EVENT_COMMIT:
if (sign==1)
{
GetCtrlVal (panelHandle, PANEL_STRING_VOLTAGE, string);
if (strlen(string)==6&&mark!=1) break;
if (string[0]=='0'&&string[1]!='.'||mark==1)
SetCtrlVal (panelHandle, PANEL_STRING_VOLTAGE, "2");
else
{
strcat(string,"2");
SetCtrlVal (panelHandle, PANEL_STRING_VOLTAGE, string);
}
}
else
{
GetCtrlVal (panelHandle, PANEL_STRING_CURRENT, string);
if (strlen(string)==6&&mark!=1) break;
if (string[0]=='0'&&string[1]!='.'||mark==1)
SetCtrlVal (panelHandle, PANEL_STRING_CURRENT, "2");
else
{
strcat(string,"2");
SetCtrlVal (panelHandle, PANEL_STRING_CURRENT, string);
}
}
mark=0;
break;
}
return 0;
}
//NUMBER 1:
int CVICALLBACK ENTRY_1 (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char string[10];
switch (event)
{
case EVENT_COMMIT:
if (sign==1)
{
GetCtrlVal (panelHandle, PANEL_STRING_VOLTAGE, string);
if (strlen(string)==6&&mark!=1) break;
if (string[0]=='0'&&string[1]!='.'||mark==1)
SetCtrlVal (panelHandle, PANEL_STRING_VOLTAGE, "1");
else
{
strcat(string,"1");
SetCtrlVal (panelHandle, PANEL_STRING_VOLTAGE, string);
}
}
else
{
GetCtrlVal (panelHandle, PANEL_STRING_CURRENT, string);
if (strlen(string)==6&&mark!=1) break;
if (string[0]=='0'&&string[1]!='.'||mark==1)
SetCtrlVal (panelHandle, PANEL_STRING_CURRENT, "1");
else
{
strcat(string,"1");
SetCtrlVal (panelHandle, PANEL_STRING_CURRENT, string);
}
}
mark=0;
break;
}
return 0;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* FUNCTION AREA */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
//READBACK FROM THE POWER SUPPLY:
int CVICALLBACK FUNCTION_READ (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
unsigned int i=0,j=0,length=0;
double temp_VOLT=0,temp_CURR=0;
double E1=10,E2=10;
switch (event)
{
case EVENT_COMMIT:
autoread=0; SetCtrlVal (panelHandle, PANEL_LED_AUTO, 0); //CAUTION!
ibwrt (device, "MEAS:VOLT?", 10);
ibrd (device, DataBuffer_VOLT, 20);
for (;DataBuffer_VOLT[i]!='E'&&i<20;i++);
temp_VOLT=( (DataBuffer_VOLT[0]-48) + (DataBuffer_VOLT[2]-48)*0.1 + (DataBuffer_VOLT[3]-48)*0.01 + (DataBuffer_VOLT[4]-48)*0.001 + (DataBuffer_VOLT[5]-48)*0.0001 ) * pow (E1,-((int)DataBuffer_VOLT[i+1]-44)*(DataBuffer_VOLT[i+2]-48));
SetCtrlVal (panelHandle, PANEL_NUMERIC_VOLTAGE, temp_VOLT);
SetCtrlVal (panelHandle, PANEL_NUMERICGAUGE_VOLTAGE, temp_VOLT);
ibwrt (device, "MEAS:CURR?", 10);
ibrd (device, DataBuffer_CURR, 20);
for (;DataBuffer_CURR[j]!='E'&&j<20;j++);
temp_CURR=( (DataBuffer_CURR[0]-48) + (DataBuffer_CURR[2]-48)*0.1 + (DataBuffer_CURR[3]-48)*0.01 + (DataBuffer_CURR[4]-48)*0.001 + (DataBuffer_CURR[5]-48)*0.0001 ) * pow (E2,-((int)DataBuffer_CURR[j+1]-44)*(DataBuffer_CURR[j+2]-48));
if (temp_CURR>=0)
{
SetCtrlVal (panelHandle, PANEL_NUMERIC_CURRENT, temp_CURR);
SetCtrlVal (panelHandle, PANEL_NUMERICGAUGE_CURRENT, temp_CURR);
}
Delay (0.2);
status (1);
break;
}
return 0;
}
//AUTO MONITOR:
int CVICALLBACK FUNCTION_AUTO (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
autoread=1;
SetCtrlVal (panelHandle, PANEL_LED_AUTO, 1);
CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, AutoReadThreadFunction, NULL, &threadFunctionID);
break;
}
return 0;
}
//STOP AUTO MONITOR:
int CVICALLBACK FUNCTION_STOP (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
autoread=0;
SetCtrlVal (panelHandle, PANEL_LED_AUTO, 0);
break;
}
return 0;
}
//THE POWER SUPPLY IS IN CV MODE:
int CVICALLBACK FUNCTION_CV (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char string1[]="STAT:OPER:ENAB 1280;PTR 1280";
char string2[]="*SRE 128";
switch (event)
{
case EVENT_COMMIT:
ibwrt (device,string1,strlen(string1));
ibwrt (device,string2,strlen(string2));
break;
}
return 0;
}
//THE POWER SUPPLY IS IN CC MODE:
int CVICALLBACK FUNCTION_CC (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char string1[]="STAT:OPER:ENAB 1280;PTR 1280";
char string2[]="*SRE 128";
switch (event)
{
case EVENT_COMMIT:
ibwrt (device,string1,strlen(string1));
ibwrt (device,string2,strlen(string2));
break;
}
return 0;
}
//THE OCP FUNCTION IS ENABLED:
int CVICALLBACK FUNCTION_OCP (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char string1[]="STAT:OPER:ENAB 1280;PTR 1280";
char string2[]="*SRE 128";
switch (event)
{
case EVENT_COMMIT:
ibwrt (device,string1,strlen(string1));
ibwrt (device,string2,strlen(string2));
break;
}
return 0;
}
//THE OVP FUNCTION IS ENABLED:
int CVICALLBACK FUNCTION_OVP (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char string1[]="STAT:OPER:ENAB 1280;PTR 1280";
char string2[]="*SRE 128";
switch (event)
{
case EVENT_COMMIT:
ibwrt (device,string1,strlen(string1));
ibwrt (device,string2,strlen(string2));
break;
}
return 0;
}
//RESET THE POWER:
int CVICALLBACK FUNCTION_RST (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
ibwrt (device, "VOLT 0", 6);
ibwrt (device, "OUTP OFF", 8);
ibwrt(device,"*RST",4);
Delay (0.5);
FUNCTION_READ (1, 45, 1, 0, 0, 0);
break;
}
return 0;
}
//CLEAR STATUS:
int CVICALLBACK FUNCTION_CLS (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
ibwrt (device, "VOLT 0", 6);
ibwrt (device, "OUTP OFF", 8);
ibwrt(device,"*CLS",4);
Delay (0.5);
FUNCTION_READ (1, 45, 1, 0, 0, 0);
break;
}
return 0;
}
//RECALL THE POWER'S STATUS TO NONVOLATILE MEMORY FROM 0 TO 4:
int CVICALLBACK FUNCTION_RCL (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char string_RCL[20]="*RCL ";
char string[10]={'0','0','0','0','0','0'};
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (panelHandle, PANEL_STRING_PARAMETERS, string);
if (strlen(string)==1 && '0'<=string[0]<='4')
{
strcat (string_RCL,string);
ibwrt (device,string_RCL,strlen(string_RCL));
}
else
{
SetCtrlVal (panelHandle, PANEL_STRING_PARAMETERS, "Error");
}
Delay (0.5);
FUNCTION_READ (1, 45, 1, 0, 0, 0);
break;
}
return 0;
}
//SAVE THE POWER'S STATUS TO NONVOLATILE MEMORY FROM 0 TO 4:
int CVICALLBACK FUNCTION_SAV (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
char string_SAV[20]="*SAV ";
char string[10]={'0','0','0','0','0','0'};
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (panelHandle, PANEL_STRING_PARAMETERS, string);
if (strlen(string)==1 && '0'<=string[0]<='4')
{
strcat (string_SAV,string);
ibwrt (device,string_SAV,strlen(string_SAV));
}
else
{
SetCtrlVal (panelHandle, PANEL_STRING_PARAMETERS, "Error");
}
break;
}
return 0;
}
//POWER'S OUTPUT IS ON OR OFF:
int CVICALLBACK FUNCTION_OUTPUT (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int led_dis=0;
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (panelHandle, PANEL_LED_DIS, &led_dis);
if (led_dis==0)
{
ibwrt (device, "OUTP OFF", 8);
SetCtrlVal (panelHandle, PANEL_LED_DIS, 1);
}
else
{
ibwrt (device, "OUTP ON", 8);
SetCtrlVal (panelHandle, PANEL_LED_DIS, 0);
}
break;
}
return 0;
}
//POWER ON AND INITIATE:
int CVICALLBACK FUNCTION_ON (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
device = ibdev (0, 5, NO_SAD, T10s, 1, 0); //打开设备并设置参数
ibwrt(device,"*RST",4);
break;
}
return 0;
}
//CLOSE THE POWER:
int CVICALLBACK FUNCTION_OFF (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
ibwrt (device,"VOLT 0",6);
ibonl (device,0);
break;
}
return 0;
}
//CLOSE POWER AND QIUT THIS PROGRAM:
int CVICALLBACK FUNCTION_QUIT (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
autoread=0;
SetCtrlVal (panelHandle, PANEL_LED_AUTO, 0);
ibwrt (device,"VOLT 0",6);
ibonl (device,0);
QuitUserInterface (0);
break;
}
return 0;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* CUSTOMIZE */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int CVICALLBACK AutoReadThreadFunction(void *functionData)
{
unsigned int threadi=0,threadj=0,threadlength=0;
double threadtemp_VOLT=0,threadtemp_CURR=0;
double threadE1=10,threadE2=10;
int threadtimes=1;
char threadDataBuffer_VOLT[20]={'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
char threadDataBuffer_CURR[20]={'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
while (threadtimes<=1000)
{
ibwrt (device, "MEAS:VOLT?", 10);
ibrd (device, threadDataBuffer_VOLT, 20);
for (threadi=0;threadDataBuffer_VOLT[threadi]!='E'&&threadi<20;threadi++);
threadtemp_VOLT=( (threadDataBuffer_VOLT[0]-48) + (threadDataBuffer_VOLT[2]-48)*0.1 + (threadDataBuffer_VOLT[3]-48)*0.01 + (threadDataBuffer_VOLT[4]-48)*0.001 + (threadDataBuffer_VOLT[5]-48)*0.0001 ) * pow (threadE1,-((int)threadDataBuffer_VOLT[threadi+1]-44)*(threadDataBuffer_VOLT[threadi+2]-48));
SetCtrlVal (panelHandle, PANEL_NUMERIC_VOLTAGE, threadtemp_VOLT);
SetCtrlVal (panelHandle, PANEL_NUMERICGAUGE_VOLTAGE, threadtemp_VOLT);
ibwrt (device, "MEAS:CURR?", 10);
ibrd (device, threadDataBuffer_CURR, 20);
for (threadj=0;threadDataBuffer_CURR[threadj]!='E'&&threadj<20;threadj++);
threadtemp_CURR=( (threadDataBuffer_CURR[0]-48) + (threadDataBuffer_CURR[2]-48)*0.1 + (threadDataBuffer_CURR[3]-48)*0.01 + (threadDataBuffer_CURR[4]-48)*0.001 + (threadDataBuffer_CURR[5]-48)*0.0001 ) * pow (threadE2,-((int)threadDataBuffer_CURR[threadj+1]-44)*(threadDataBuffer_CURR[threadj+2]-48));
if (threadtemp_CURR>=0)
{
SetCtrlVal (panelHandle, PANEL_NUMERIC_CURRENT, threadtemp_CURR);
SetCtrlVal (panelHandle, PANEL_NUMERICGAUGE_CURRENT, threadtemp_CURR);
}
Delay (0.1);
status (1);
threadtimes++;
Delay (0.2);
if(autoread==0)
{
SetCtrlVal (panelHandle, PANEL_LED_AUTO, 0);
CmtExitThreadPoolThread (threadFunctionID);
}
}
return 0;
}
void status (int event)
{
switch (event)
{
case EVENT_COMMIT:
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -