#include <formatio.h>
#include <userint.h>
#include <ansi_c.h>
#include <utility.h>
#include <gpib.h>
#include "toolbox.h"
#include "prologix.h"
#include "K6517.h"
K6517STATUS K6517Stat
;
static int K6517_Interface
,K6517_Port
,K6517_Gdev
;
static int iret
;
static int stop
;
int _VI_FUNC K6517_status_print
(void);
void GpibError
(char *msg
) {
printf ("%s\n", msg
);
printf ("ibsta = &H%x <", ibsta
);
if (ibsta
& ERR
) printf (" ERR");
if (ibsta
& TIMO
) printf (" TIMO");
if (ibsta
& END
) printf (" END");
if (ibsta
& SRQI
) printf (" SRQI");
if (ibsta
& RQS
) printf (" RQS");
if (ibsta
& CMPL
) printf (" CMPL");
if (ibsta
& LOK
) printf (" LOK");
if (ibsta
& REM
) printf (" REM");
if (ibsta
& CIC
) printf (" CIC");
if (ibsta
& ATN
) printf (" ATN");
if (ibsta
& TACS
) printf (" TACS");
if (ibsta
& LACS
) printf (" LACS");
if (ibsta
& DTAS
) printf (" DTAS");
if (ibsta
& DCAS
) printf (" DCAS");
printf (" >\n");
printf ("iberr = %d", iberr
);
if (iberr
== EDVR
) printf (" EDVR <DOS Error>\n");
if (iberr
== ECIC
) printf (" ECIC <Not Controller-In-Charge>\n");
if (iberr
== ENOL
) printf (" ENOL <No Listener>\n");
if (iberr
== EADR
) printf (" EADR <Address error>\n");
if (iberr
== EARG
) printf (" EARG <Invalid argument>\n");
if (iberr
== ESAC
) printf (" ESAC <Not System Controller>\n");
if (iberr
== EABO
) printf (" EABO <Operation aborted>\n");
if (iberr
== ENEB
) printf (" ENEB <No GPIB board>\n");
if (iberr
== EOIP
) printf (" EOIP <Async I/O in progress>\n");
if (iberr
== ECAP
) printf (" ECAP <No capability>\n");
if (iberr
== EFSO
) printf (" EFSO <File system error>\n");
if (iberr
== EBUS
) printf (" EBUS <Command error>\n");
if (iberr
== ESTB
) printf (" ESTB <Status byte lost>\n");
if (iberr
== ESRQ
) printf (" ESRQ <SRQ stuck on>\n");
if (iberr
== ETAB
) printf (" ETAB <Table Overflow>\n");
printf ("ibcntl = %ld\n", ibcntl
);
printf ("\n");
/* Call ibonl to take the device and interface offline */
ibonl
(K6517_Gdev
,0);
exit(1);
}
void _VI_FUNC K6517_open
(int interface
, int port
, int primary_addr
,
int secondary_addr
, int timeout
)
{
char cmd
[100];
int status
;
/*
K6517_Gdev = OpenDev ("GPIB0", "");
if (ibsta & ERR) GpibError("OpenDev Error");
iret = ibpad (K6517_Gdev, 0);
if (ibsta & ERR) GpibError("OpenDev Error");
iret = ibsad (K6517_Gdev, NO_SAD);
iret = ibtmo (K6517_Gdev, T10s);
iret = ibeot (K6517_Gdev, 1);
iret = ibeos (K6517_Gdev, 0);
*/
K6517_Interface
=interface
;
K6517_Port
=port
;
switch (K6517_Interface
){
case 1:
status
= PROLOGIX_Open
(K6517_Port
);
printf("K6517_open %d\n", status
);
sprintf(cmd
,"++addr %0d",primary_addr
);
PROLOGIX_Send
(cmd
);
PROLOGIX_Send
("++auto 0");
PROLOGIX_Send
("++eoi 1");
PROLOGIX_Send
("++eot_enable 0");
PROLOGIX_Send
("++read_tmo_ms 1000");
break;
default:
K6517_Gdev
= ibdev
(K6517_Port
,primary_addr
,secondary_addr
,timeout
,1,0);
if (ibsta
& ERR
) GpibError
("OpenDev Error");
}
printf("Interface %d\n", interface
);
K6517_send
("*RST",0);
K6517_send
("*IDN?", 5);
char cres
[100];
cres
[0]= 0;
int len
= K6517_receive
(cres
, 50);
printf("[%d] %s\n", len
, cres
);
Delay
(GDELAY
);
return;
}
void _VI_FUNC K6517_clear
(void)
{
switch (K6517_Interface
){
case 1:
PROLOGIX_Send
("++clr");
break;
default:
iret
= ibclr
(K6517_Gdev
); // Clear the device
if (ibsta
& ERR
) GpibError
("OpenDev Error");
}
// Delay(GDELAY);
Delay
(2.
);
return;
}
void _VI_FUNC K6517_send
(char *cmd
, int len
)
{
printf("-> %s\n", cmd
);
if (!len
) len
= strlen(cmd
);
switch (K6517_Interface
){
case 1:
PROLOGIX_Send
(cmd
);
break;
default:
iret
= ibwrt
(K6517_Gdev
, cmd
, len
);
if (ibsta
& ERR
) GpibError
("OpenDev Error");
}
Delay
(GDELAY
);
return;
}
int _VI_FUNC K6517_receive
(char *response
, int maxbyt
)
{
int ierr
=0;
switch (K6517_Interface
){
case 1:
PROLOGIX_Send
("++read eoi");
ierr
= PROLOGIX_Receive
(response
,maxbyt
);
printf("<---Read [%d] %s\n", ierr
, response
);
return ierr
;
break;
default:
iret
= ibrd
(K6517_Gdev
, response
, maxbyt
);
if (ibsta
& ERR
) GpibError
("OpenDev Error");
response
[ibcntl
]=0;
return ibcntl
;
}
}
void _VI_FUNC K6517_status
(void)
{
int len
;
char cres
[100];
K6517_send
("U0X", 3);
len
= K6517_receive
(cres
, 90);
sscanf(cres
," 617%1d%2d%1d%1d%1d%1d%1d%1d%1d%1d%1d%2d%1d%2c",
&K6517Stat.
function,&K6517Stat.
range,&K6517Stat.
zero_check,
&K6517Stat.
zero_correct,&K6517Stat.
suppress,&K6517Stat.
trigger,
&K6517Stat.
vsource_operate,&K6517Stat.
read_mode,
&K6517Stat.
data_prefix,&K6517Stat.
display,
&K6517Stat.
data_store,&K6517Stat.
srq,&K6517Stat.
eoi,K6517Stat.
terminator);
printf("617FRRCZNTOBGDQMMKYY\n");
printf("%s\n",cres
);
// K6517_send ("X", 1);
return;
}
void _VI_FUNC K6517_data_format
(int mode
)
{
int len
;
char cmd
[100];
len
=sprintf(cmd
,"G%0dX",mode
);
K6517_send
(cmd
, len
);
return;
}
double _VI_FUNC K6517_get
(char *prefix
, int *loc
)
{
double value
;
char cres
[100];
K6517_send
("SENS:FUNC 'curr'",0);
// K6517_send (":SENS:CURR:RANG:UPP 21e-3",0);
// K6517_send ("SYST:ZCH 0",0);
K6517_send
("READ?",0);
cres
[0]= 0;
int len
= K6517_receive
(cres
, 50);
printf("current >%d, %s\n",len
,cres
);
return atof(cres
);
/*
K6517_send ("X", 1);
len = K6517_receive (cres, 50);
if (loc) {
*loc=-1;
sscanf(cres,"%4c%lg,%d",prefix, &value, loc);
prefix[4]=0;
} else {
sscanf(cres,"%*4c%lg,%*d",&value);
}
return value;
*/
}
void _VI_FUNC K6517_current_mode
(double range
)
{
int len
;
char cmd
[100];
if (range
> 0) {
len
=sprintf(cmd
,":SENS:CURR:RANG:AUTO OFF");
len
=sprintf(cmd
,":SENS:CURR:RANG:UPP %g",range
);
}
else len
=sprintf(cmd
,":SENS:CURR:RANG:AUTO ON");
// printf("%d, %s\n",len,cmd);
K6517_send
(cmd
, len
);
Delay
(1);
K6517_send
("SYST:ZCH 0",0);
return;
}
void _VI_FUNC K6517_zero_correct
(int zcorrect
)
{
K6517_send
("C0X", 3);
K6517_send
("Z0X", 3);
if (zcorrect
) {
K6517_send
("C1X", 3);
Delay
(2);
K6517_send
("Z1X", 3);
K6517_send
("C0X", 3);
}
return;
}
void _VI_FUNC K6517_trigger_mode
(int mode
)
{
int len
;
char cmd
[100];
//len=sprintf(cmd,"T%0dX",mode);
//K6517_send (cmd, len);
return;
}
void _VI_FUNC K6517_reading_mode
(int mode
)
{
int len
;
char cmd
[100];
//len=sprintf(cmd,"B%0dX",mode);
//K6517_send (cmd, len);
return;
}
void _VI_FUNC K6517_vsource_set
(float value
)
{
int len
;
char cmd
[100];
len
=sprintf(cmd
,":SOURCE:VOLTAGE %f",value
);
K6517_send
(cmd
, len
);
return;
}
double _VI_FUNC K6517_vsource_get
(void)
{
double value
;
/*
K6517_send ("SENS:FUNC 'volt'",0);
K6517_send ("SENS:VOLT:RANG:AUTO ON",0);
K6517_send ("SYST:ZCH 0",0);
K6517_send ("READ?",0);
*/
K6517_send
(":MEASure:VOLTage?",0);
char cres
[100];
cres
[0]= 0;
int len
= K6517_receive
(cres
, 50);
return atof(cres
);
}
void _VI_FUNC K6517_vsource_operate
(int operate
)
{
if (operate
){
// K6517_send (":SOURCE:VOLTAGE:MCONNECT 1", 0);
// K6517_send (":SENS:VOLTAGE:MANual:VSOurce:OPERate 1", 0);
//K6517_send (":MCONNECT 1", 0);
K6517_send
(":OUTP ON", 0);
// K6517_send (":SOURCE:VOLTAGE:RANGE 99", 0);
// K6517_send (":SOURCE:VOLTAGE 22", 0);
} else {
//K6517_send (":SOURCE:VOLTAGE 0", 0);
// K6517_send (":SENSe:VOLTAGE:MANual:VSOurce:OPERate 0", 0);
// K6517_send (":SOURCE:VOLTAGE:MCONNECT 0", 0);
K6517_send
(":OUTP OFF", 0);
//K6517_send (":MCONNECT 0", 0);
}
K6517_send
(":STATUS:OPER?",0);
char cres
[100];
cres
[0]= 0;
int len
= K6517_receive
(cres
, 50);
// return atoi(cres);
}
void _VI_FUNC K6517_close
(void)
{
// iret = CloseDev (K6517_Gdev);
switch (K6517_Interface
){
case 1:
PROLOGIX_Close
();
break;
default:
iret
= ibonl
(K6517_Gdev
, 0);// Take the device offline
if (ibsta
& ERR
) GpibError
("OpenDev Error");
}
return;
}
void _VI_FUNC K6517_test
(void)
{
int i
;
double value
;
char cres
[100];
K6517_clear
();
K6517_current_mode
(0);
K6517_zero_correct
(1);
K6517_data_format
(0);
K6517_trigger_mode
(1);
K6517_vsource_set
(-100.
);
K6517_vsource_operate
(1);
K6517_status
();
value
=K6517_get
(cres
,&i
);
printf("%s, %lg, %d\n",cres
,value
,i
);
value
=K6517_vsource_get
();
printf("%lg\n",value
);
value
=K6517_get
(cres
,&i
);
printf("%s, %lg, %d\n",cres
,value
,i
);
value
=K6517_get
(cres
,&i
);
printf("%s, %lg, %d\n",cres
,value
,i
);
value
=K6517_get
(cres
,&i
);
printf("%s, %lg, %d\n",cres
,value
,i
);
value
=K6517_get
(cres
,&i
);
printf("%s, %lg, %d\n",cres
,value
,i
);
Delay
(5);
K6517_vsource_operate
(0);
}
#ifdef K6517_MAIN
#include <cvirte.h>
#include <userint.h>
#include "K6517-ctrl.h"
int pnl
; int gLogToFile
;
int pn2
;
int gLogToFile
;
int vmon
[4]={P1_VMON_1
};
int imon
[4]={P1_IMON_1
};
int vset
[4]={P1_U_1
};
int iset
[4]={P1_I_1
};
int radiob
[4]={P1_BOX_1
};
int cvcc
[4]={P1_CVCC_1
};
const unsigned char Pre_1
= 1;
int gMask
=0xF;
int pnl
;
FILE
*gFp
;
int CVICALLBACK TimerOnOffCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
int state
;
switch (event
)
{
case EVENT_COMMIT
:
GetCtrlVal
(panel
, control
, &state
);
if (state
){
ResumeTimerCallbacks
();
} else {
SuspendTimerCallbacks
();
printf ("Disabling timer....\n");
}
break;
}
return 0;
}
// reads the run number from the first line in the file
int GetRunNumberFromFile
(char *fname
) {
char line
[MAX_PATHNAME_LEN
];
int ndim
= MAX_PATHNAME_LEN
;
int current_run
= -1;
FILE
*fp
= NULL
;
ssize_t size
;
if ( GetFileInfo
(fname
,&size
) ) fp
= fopen(fname
,"r");
if (fp
) {
if (fgets(line
,ndim
,fp
)!= NULL
) current_run
= atoi(line
);
fclose(fp
);
}
return current_run
;
}
int IncreaseRunNumberInFile
(char *fname
) {
int current_run
= GetRunNumberFromFile
(fname
);
FILE
*fp
= fopen(fname
,"w");
if (fp
) {
fprintf(fp
,"%d", current_run
+1 );
fclose(fp
);
}
return current_run
+1;
}
int __stdcall WinMain
(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
LPSTR lpszCmdLine
, int nCmdShow
)
{
char cres
[100];
double Voltage
, Current
, tinterval
;
if (InitCVIRTE
(hInstance
, 0, 0) == 0) return -1; /* out of memory */
SetStdioPort
(CVI_STDIO_WINDOW
);
if ((pnl
= LoadPanel
(0, "K6517-ctrl.uir", P1
)) < 0) return -1;
if ((pn2
= LoadPanel
(0, "K6517-ctrl.uir", P2
)) < 0) return -1;
K6517_open
(1,4,3,0,13);
SetCtrlVal
(pnl
, P1_ONOFF
, 0);
GetCtrlVal
(pnl
, P1_TINTERVAL
, &tinterval
);
SetCtrlAttribute
(pnl
, P1_TIMER
, ATTR_INTERVAL
, tinterval
);
TimerOnOffCB
(pnl
, P1_TIMERON
, EVENT_COMMIT
,NULL
,0,0);
for (unsigned char ch
=0;ch
<1;ch
++){
int ison
,i
;
Voltage
=K6517_vsource_get
();
Current
=K6517_get
(cres
,&i
);
SetCtrlVal
(pnl
, vset
[ch
], Voltage
);
SetCtrlVal
(pnl
, iset
[ch
], Current
);
GetCtrlVal
(pnl
, radiob
[ch
], &ison
);
gMask
= ison
;
}
DisplayPanel
(pnl
);
DisplayPanel
(pn2
);
RunUserInterface
();
DiscardPanel
(pn2
);
DiscardPanel
(pnl
);
K6517_close
();
if (gFp
) fclose(gFp
);
return 0;
}
int CVICALLBACK SwitchOnOffCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
unsigned char state
;
switch (event
)
{
case EVENT_COMMIT
:
GetCtrlVal
(panel
, control
, &state
);
K6517_vsource_operate
(state
);
break;
}
return 0;
}
int CVICALLBACK SetCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
char cres
[100];
int i
;
switch (event
)
{
case EVENT_COMMIT
:
for (unsigned char ch
= 0; ch
<1;ch
++){
//printf("ch %d %x\n", ch, gMask);
if (gMask
){
double Voltage
;
double Current
;
GetCtrlVal
(panel
, vset
[ch
], &Voltage
);
GetCtrlVal
(panel
, iset
[ch
], &Current
);
printf("->ch %d VSet %g Iset %g\n", ch
, Voltage
, Current
);
K6517_vsource_set
(Voltage
);
Voltage
=K6517_vsource_get
();
// TMI_Current(TMI_DeviceId, ch+1, Pre_1, Current);
Current
=K6517_get
(cres
,&i
);
printf("<-ch %d VSet %g Iset %g\n", ch
, Voltage
, Current
);
}
}
break;
}
return 0;
}
int CVICALLBACK ReadCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
int iRet
;
char ch
=0;
double Voltage
;
double Current
;
char cv_cc
;
char cres
[100];
switch (event
)
{
case EVENT_COMMIT
:
for (ch
= 0; ch
<1;ch
++){
if (gMask
){
int ison
,i
;
Voltage
=K6517_vsource_get
();
Current
=K6517_get
(cres
,&i
);
cv_cc
= 1;
printf("ch %d VSet %g Iset %g\n", ch
, Voltage
, Current
);
SetCtrlVal
(panel
, vmon
[ch
], Voltage
);
SetCtrlVal
(panel
, imon
[ch
], Current
);
SetCtrlVal
(panel
, cvcc
[ch
], cv_cc
);
}
}
break;
}
return 0;
}
int CVICALLBACK SetIntervalCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
double tinterval
;
switch (event
) {
case EVENT_COMMIT
:
GetCtrlVal
(panel
, control
, &tinterval
);
SetCtrlAttribute
(panel
, P1_TIMER
, ATTR_INTERVAL
, tinterval
);
break;
}
return 0;
}
int CVICALLBACK ExitCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
switch (event
)
{
case EVENT_COMMIT
:
K6517_send
(":OUTP OFF", 0);
QuitUserInterface
(0);
break;
}
return 0;
}
int CVICALLBACK SetMaskCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{ int ison
;
switch (event
)
{
case EVENT_COMMIT
:
GetCtrlVal
(panel
, control
, &ison
);
for (int i
=0;i
<1;i
++) if (control
== radiob
[i
]) break;
gMask
= ison
;
break;
}
return 0;
}
int CVICALLBACK LogToFileCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
switch (event
)
{
case EVENT_COMMIT
:
GetCtrlVal
(panel
, control
, &gLogToFile
);
break;
}
return 0;
}
int CVICALLBACK TimerCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
switch (event
)
{
unsigned char ch
;
double current
[4];
double voltage
;
char cv_cc
= 0;
char cres
[100];
int i
=0;
case EVENT_TIMER_TICK
:
for (ch
= 0; ch
<1;ch
++){
if (gMask
){
voltage
=K6517_vsource_get
();
current
[ch
] =K6517_get
(cres
,&i
);
if (gLogToFile
){
if (!gFp
) {
gFp
= fopen("K6517.log","w");
fprintf(gFp
,"#time\tch\tU\tI\tCV_CC\n");
}
fprintf(gFp
,"%ul\t%d\t%g\t%g\t%d\n", time(NULL
), ch
+1, voltage
, current
[ch
], cv_cc
);
}
}
}
PlotStripChart
(panel
, P1_GRAPH
, current
, 1, 0, 0, VAL_DOUBLE
);
PlotStripChart
(panel
, P1_GRAPH_1
, &voltage
, 1, 0, 0, VAL_DOUBLE
);
break;
}
return 0;
}
int CVICALLBACK TestCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
switch (event
) {
case EVENT_COMMIT
:
K6517_test
();
break;
}
return 0;
}
int CVICALLBACK IVSCANCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
int nsteps
;
double umin
, umax
, u
;
double *xpoints
;
double *ypoints
;
static int plivhandle
=0;
double current
;
double voltage
;
char cv_cc
= 0;
char cres
[100];
char fileName
[100];
char fname
[100];
char path
[100];
double range
;
int k
=0;
int state
;
int overflow
;
char ovf
[10];
FILE
*fp
;
time_t mtime
;
ssize_t size
;
switch (event
) {
case EVENT_COMMIT
:
K6517_send
(":OUTP ON", 0);
// GetCtrlVal(panel, P2_UMIN, &umin);
// GetCtrlVal(panel, P2_UMAX, &umax);
// GetCtrlVal(panel, P2_NSTEPS, &nsteps);
SetCtrlVal
(pnl
, P1_TIMERON
, 0);
GetCtrlVal
(panel
, P2_FILENAME
, fileName
);
GetCtrlVal
(panel
, P2_PATH
, path
);
// GetCtrlVal(panel, P2_RANGE, &range);
TimerOnOffCB
(pnl
, P1_TIMERON
, EVENT_COMMIT
, NULL
, 0, 0);
sprintf(fname
, "%s/%s.dat", path
, fileName
);
if ( !GetFileInfo
(fname
,&size
) )
fp
= fopen(fname
,"w");
else {
sprintf(cres
, "File %s exist\n Remove it first",fname
);
MessagePopup
("Info", cres
);
return 0;
}
time(&mtime
);
printf("#%s %s\n",DateStr
(), TimeStr
());
if (fp
) fprintf(fp
, "#%s %s\n",DateStr
(), TimeStr
());
// K6517_current_mode (range);
stop
= 0;
LogScaleCB
(panel
, P2_LOGSCALE
, EVENT_COMMIT
,NULL
, 0, 0);
int voltageMax
[4]={P2_UMAX_1
,P2_UMAX_2
,P2_UMAX_3
,P2_UMAX_4
};
int voltageMin
[4]={P2_UMIN_1
,P2_UMIN_2
,P2_UMIN_3
,P2_UMIN_4
};
int numberOfSteps
[4]={P2_NSTEPS_1
,P2_NSTEPS_2
,P2_NSTEPS_3
,P2_NSTEPS_4
};
int selectRange
[4]={P2_RANGE_1
,P2_RANGE_2
,P2_RANGE_3
,P2_RANGE_4
};
int intervals
[4]={P2_SLCT_1
,P2_SLCT_2
,P2_SLCT_3
,P2_SLCT_4
};
int nrOfInt
;
int nrOfSteps
;
int N
=0;
int K
=0;
for (int j
=0;j
<4;j
++){
GetCtrlVal
(panel
, intervals
[j
], &nrOfInt
);
N
= N
+ nrOfInt
;
GetCtrlVal
(panel
, numberOfSteps
[j
], &nrOfSteps
);
K
= K
+ nrOfSteps
;
}
xpoints
= (double *) malloc ((K
-N
+2)*sizeof(double));
ypoints
= (double *) malloc ((K
-N
+2)*sizeof(double));
int tockaK
=0;
for (int i
=0;i
<N
;i
++){
GetCtrlVal
(panel
, voltageMin
[i
], &umin
);
GetCtrlVal
(panel
, voltageMax
[i
], &umax
);
GetCtrlVal
(panel
, numberOfSteps
[i
], &nsteps
);
GetCtrlVal
(panel
, selectRange
[i
], &range
);
K6517_current_mode
(range
);
for (int n
=0;n
<nsteps
+1;n
++){
if (i
>0) {
if(n
==0) n
++;
};
u
= umin
+ n
*(umax
-umin
)/nsteps
;
K6517_vsource_set
(u
);
// voltage =K6517_vsource_get();
current
=K6517_get
(cres
,&k
);
if (current
> range
) printf("Overflow +\n");
if (current
< -range
) printf("Overflow -\n");
voltage
= u
;
xpoints
[tockaK
]= voltage
;
ypoints
[tockaK
]= current
;
SetCtrlVal
(panel
, P2_VMON
, voltage
);
if (fp
) fprintf(fp
, "%d %g %g %g\n",tockaK
, u
, voltage
,current
);
printf("n=%d u=%g voltage=%g current=%g\n",tockaK
, u
, voltage
,current
);
if (plivhandle
) DeleteGraphPlot
(panel
, P2_GRAPHIV
, plivhandle
, VAL_IMMEDIATE_DRAW
);
plivhandle
= PlotXY
(panel
, P2_GRAPHIV
, xpoints
, ypoints
, tockaK
+1, VAL_DOUBLE
, VAL_DOUBLE
, VAL_CONNECTED_POINTS
, VAL_BOLD_X
, VAL_SOLID
, 1, VAL_RED
);
ProcessSystemEvents
();
tockaK
++;
if (stop
) break;
}
}
fclose(fp
);
free(xpoints
);
free(ypoints
);
break;
}
return 0;
}
int CVICALLBACK SETVOLTCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
double voltage
;
switch (event
) {
case EVENT_COMMIT
:
GetCtrlVal
(panel
, P2_VOLT
, &voltage
);
K6517_vsource_set
(voltage
);
break;
}
return 0;
}
int CVICALLBACK StopCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
switch (event
) {
case EVENT_COMMIT
:
stop
= 1;
break;
}
return 0;
}
int CVICALLBACK LogScaleCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
int selected
;
switch (event
) {
case EVENT_COMMIT
:
GetCtrlVal
(panel
, control
, &selected
);
if(selected
) SetCtrlAttribute
(panel
, P2_GRAPHIV
,ATTR_YMAP_MODE
, VAL_LOG
);
else SetCtrlAttribute
(panel
, P2_GRAPHIV
,ATTR_YMAP_MODE
, VAL_LINEAR
);
break;
}
return 0;
}
//****************************
int EscapeString
(const char *i
, char *o
) {
int iptr
=0, optr
= 0;
// walk though the input string
for (iptr
= 0; iptr
< strlen(i
); iptr
++, optr
++) {
// search for
if ( (i
[iptr
]=='\\') ) {
printf("Escape String %d %d \n",i
[iptr
] , i
[iptr
]==92 ) ;
//sa02Printf("Escape String %d %d \n",i[iptr] , ( (i[iptr] == 92) || (i[iptr] == 42) )) ;
o
[optr
] = i
[iptr
];
optr
++;
}
o
[optr
] = i
[iptr
];
}
o
[optr
] = '\0';
return 0;
}
int CVICALLBACK DrawCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
switch (event
) {
case EVENT_COMMIT
:{
char fileName
[100];
char fname
[100];
char path
[100];
GetCtrlVal
(panel
, P2_FILENAME
, fileName
);
GetCtrlVal
(panel
, P2_PATH
, path
);
sprintf(fname
, "%s/%s.dat", path
, fileName
);
int status
;
char name
[MAX_PATHNAME_LEN
];
// char dfile[MAX_PATHNAME_LEN];
// char efile[MAX_PATHNAME_LEN];
// status = FileSelectPopup ("dat", "*.dat", ".dat",
// "Izberi datoteko s podatki",
// VAL_LOAD_BUTTON, 0, 0, 1, 0, efile);
// EscapeString(efile,dfile);
sprintf(name
,"C:/root/bin/root.exe IUdraw.cxx(\\\"%s\\\")", fname
);
// sprintf(name ,"C:/root/bin/root.exe IUdraw.cxx");
printf("%s\n",name
);
LaunchExecutable
(name
);
break;
}
}
return 0;
}
int CVICALLBACK Print
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
char dfile
[MAX_PATHNAME_LEN
];
char name
[MAX_PATHNAME_LEN
];
int h2
=0;
switch (event
) {
case EVENT_COMMIT
: {
int hours
, minutes
, seconds
;
int month
, day
, year
;
int id
=-1;
//int bitmap = 0;
GetSystemDate
(&month
,&day
,&year
);
GetSystemTime
(&hours
, &minutes
, &seconds
);
sprintf(name
,"IV");
sprintf(dfile
,"%d_%d_%d_%d_%d_%s.bmp",year
,month
,day
,hours
,minutes
, name
);
SaveCtrlDisplayToFile
(panel
,P2_GRAPHIV
, 0, -1, -1, dfile
);
printf("bmp image saved as %s\n", dfile
);
//PrintCtrl (p1h, P1_GRAPH2D, "sa02_CVI", 1, 1);
}
break;
}
return 0;
}
int CVICALLBACK DebugCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
int selected
;
int debugCode
;
switch (event
) {
case EVENT_COMMIT
:
GetCtrlVal
(panel
, control
, &selected
);
if(selected
) debugCode
= 1;
else debugCode
= 0;
break;
}
return 0;
}
int CVICALLBACK Exit2CB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
) {
switch (event
) {
case EVENT_COMMIT
:
K6517_send
(":OUTP OFF", 0);
QuitUserInterface
(0);
break;
}
return 0;
}
#endif