Blame |
Last modification |
View Log
| RSS feed
#include <ansi_c.h>
/* Program qe2d.c za testiranje povrsinske obcutljivosti
Avtor: Samo Korpar
Verzija:
1.00 28.9.2009
-
*/
#include <utility.h>
#include <userint.h>
#include "K617.h"
#include <cvirte.h>
#include "qe2d_ui.h"
#define uSMC_USB
#ifdef uSMC_USB
# include "uSMC.h"
# define uSMC_SERIAL_X "0000000000004925"
# define uSMC_SERIAL_Y "0000000000006030"
# define uSMC_SERIAL_Z "0000000000002894"
const char serials
[3][16]= {uSMC_SERIAL_X
,uSMC_SERIAL_Y
,uSMC_SERIAL_Z
};
#endif /* uSMC_USB */
//#define MIKRO_COM 6
#ifdef MIKRO_COM
# include "MIKRO.h"
#endif /* MIKRO_COM */
#define SP2155_PORT 4
#ifdef SP2155_PORT
# include "SP2155.h"
#endif /* SP2155_PORT */
#define PROLOGIX_PORT 5
#define K617_ADDR 3
#define MAXXY 1000
#define MAXWL 1000
const int PosCtrl
[3]= {P1_X
,P1_Y
,P1_Z
};
const int ncurroff
=10;
const int ncurrmes
=3;
static int node
[3];
static int CurPos
[3]= {0,0,0};
static int p1h
,pID
,rID
,tfID
,plh
[MAXXY
],plqeh
[MAXXY
];
static int wl
[MAXXY
][MAXWL
];
static float tok
[MAXXY
][MAXWL
],qe
[MAXXY
][MAXWL
],tokoff
[MAXXY
];
//static float
float getavg
(int n
) {
int i
;
float tok
;
tok
=0;
for (i
=0; i
<n
; i
++)
tok
+=K617_get
(NULL
, NULL
);
return (tok
/(float)n
);
}
int CVICALLBACK cb_timer
(int panel
, int control
, int event
, void *callbackData
,
int eventData1
, int eventData2
) {
QueueUserEvent
(9000, p1h
, P1_TIMER
);
return (0);
}
int MDelay
(double t
) {
while (0.5<t
) {
ProcessSystemEvents
();
GetUserEvent
(0, &pID
, &rID
);
switch (rID
) {
case P1_STOP
:
return 1;
break;
}
Delay
(0.5);
t
-=0.5;
SetCtrlVal
(p1h
,P1_TOUT
,t
);
}
Delay
(t
);
SetCtrlVal
(p1h
,P1_TOUT
,0.0);
return 0;
}
int qescan
() {
int i
;
int npos
,nref
;
float wait
;
int icwl
;
double rcurr
;
SetCtrlAttribute
(p1h
, P1_TIMER
, ATTR_ENABLED
, 0);
GetCtrlVal
(p1h
, P1_POSITION
, &npos
);
#ifdef MIKRO_COM
SetCtrlVal
(p1h
,P1_STAGELED
,1);
for (i
=0; i
<2; i
++) {
GetTableCellVal
(p1h
,P1_POINTS
,MakePoint
(i
+1,npos
+1),&CurPos
[i
]);
MIKRO_MoveTo
(node
[i
],CurPos
[i
]);
MIKRO_GetPosition
(node
[i
],&CurPos
[i
]);
SetCtrlVal
(p1h
,PosCtrl
[i
],CurPos
[i
]);
}
SetCtrlVal
(p1h
,P1_STAGELED
,0);
#endif /* MIKRO_COM */
#ifdef uSMC_USB
SetCtrlVal
(p1h
,P1_STAGELED
,1);
for (i
=0; i
<2; i
++) {
GetTableCellVal
(p1h
,P1_POINTS
,MakePoint
(i
+1,npos
+1),&CurPos
[i
]);
uSMC_MoveTo
(node
[i
],CurPos
[i
]);
uSMC_GetPosition
(node
[i
],&CurPos
[i
]);
SetCtrlVal
(p1h
,PosCtrl
[i
],CurPos
[i
]);
}
SetCtrlVal
(p1h
,P1_STAGELED
,0);
#endif /* uSMC_USB */
K617_trigger_mode
(1);
#ifdef SP2155_PORT
SetCtrlVal
(p1h
, P1_GLED
, 1);
SP2155_SetWavelength
(1000);
SetCtrlVal
(p1h
, P1_GLED
, 0);
#endif /* SP2155_PORT */
GetCtrlVal
(p1h
, P1_WAIT0
, &wait
);
if (MDelay
(wait
*60.
)) return 1;
GetCtrlVal
(p1h
, P1_WAIT
, &wait
);
tokoff
[npos
]=getavg
(ncurroff
);
SetCtrlVal
(p1h
, P1_BGRCUR1
,tokoff
[npos
]);
GetCtrlVal
(p1h
, P1_NREF
, &nref
);
for (i
=0; i
<nref
; i
++) {
icwl
=wl
[0][i
];
#ifdef SP2155_PORT
SetCtrlVal
(p1h
, P1_GLED
, 1);
SP2155_SetWavelength
(icwl
);
SetCtrlVal
(p1h
, P1_GLED
, 0);
#endif /* SP2155_PORT */
SetCtrlVal
(p1h
, P1_CWL
, icwl
);
if (MDelay
(wait
)) return 1;
rcurr
=getavg
(ncurrmes
);
SetCtrlVal
(p1h
, P1_CURR
, rcurr
);
wl
[npos
][i
]=icwl
;
tok
[npos
][i
]=-(rcurr
-tokoff
[npos
]);
}
if (plh
[npos
]) DeleteGraphPlot
(p1h
, P1_GSAMPLE
, plh
[npos
], VAL_IMMEDIATE_DRAW
);
plh
[npos
] = PlotXY
(p1h
, P1_GSAMPLE
, wl
[npos
], tok
[npos
], nref
, VAL_INTEGER
, VAL_FLOAT
,
VAL_THIN_LINE
, VAL_EMPTY_SQUARE
, VAL_SOLID
, 1, VAL_RED
);
for (i
=0; i
<nref
; i
++)
if (tok
[0][i
]>1e-12)
qe
[npos
][i
]=qe
[0][i
]*tok
[npos
][i
]/tok
[0][i
];
else
qe
[npos
][i
]=0.
;
if (plqeh
[npos
]) DeleteGraphPlot
(p1h
, P1_GQE
, plqeh
[npos
], VAL_IMMEDIATE_DRAW
);
plqeh
[npos
] = PlotXY
(p1h
, P1_GQE
, wl
[npos
], qe
[npos
], nref
, VAL_INTEGER
,
VAL_FLOAT
, VAL_THIN_LINE
, VAL_EMPTY_SQUARE
,
VAL_SOLID
, 1, VAL_BLUE
);
K617_trigger_mode
(0);
SetCtrlAttribute
(p1h
, P1_TIMER
, ATTR_ENABLED
, 1);
#ifdef MIKRO_COM
SetCtrlVal
(p1h
, P1_STAGELED
, 1);
for (i
=0; i
<2; i
++) {
MIKRO_GetPosition
(node
[i
],&CurPos
[i
]);
SetCtrlVal
(p1h
,PosCtrl
[i
],CurPos
[i
]);
}
SetCtrlVal
(p1h
, P1_STAGELED
, 0);
#endif /* MIKRO_COM */
#ifdef uSMC_USB
SetCtrlVal
(p1h
,P1_STAGELED
,1);
for (i
=0; i
<2; i
++) {
uSMC_GetPosition
(node
[i
],&CurPos
[i
]);
SetCtrlVal
(p1h
,PosCtrl
[i
],CurPos
[i
]);
}
SetCtrlVal
(p1h
, P1_STAGELED
, 0);
#endif /* uSMC_USB */
return 0;
}
int mcp_positions
() {
FILE
*fp
=fopen("mcp_positions.txt","w");
int i
=0,j
=0;
int nx
=10;
int ny
=10;
int minx
=130000;
int maxx
=280000;
int miny
=115000;
int maxy
=265000;
fprintf(fp
,"30000 124000\n");
for (i
=0; i
<nx
+1; i
++) for (j
=0; j
<ny
+1; j
++)
fprintf(fp
,"%d %d\n",minx
+i
*(maxx
-minx
)/nx
, miny
+j
*(maxy
-miny
)/ny
);
fclose(fp
);
return 0;
}
int __stdcall WinMain
(HINSTANCE hInstance
, HINSTANCE hPrevInstance
,
LPSTR lpszCmdLine
, int nCmdShow
) {
int i
,j
,iret
,nb
;
int npos
,nref
,nrows
;
int igr
,iwl0
,idwl
,inwl
,ilwl
,icwl
;
int scan_on
;
int irange
,vsource
;
float vout
,wait
;
double rcurr
;
int hdr
[10];
float *fhdr
;
float sdata
[5];
// char cpref[100];
char pfile
[300];
FILE
*fp
;
scan_on
=0;
fhdr
=(float *)&hdr
[0];
if (InitCVIRTE
(hInstance
, 0, 0) == 0) return -1; /* out of memory */
mcp_positions
();
for (i
=0; i
<MAXXY
; i
++) {
tokoff
[i
]=0;
plh
[i
]=0;
plqeh
[i
]=0;
for (j
=0; j
<MAXWL
; j
++) {
tok
[i
][j
]=0.
;
wl
[i
][j
]=0;
qe
[i
][j
]=0.
;
}
}
#ifdef MIKRO_COM
MIKRO_Open
(MIKRO_COM
);
for (i
=0; i
<3; i
++) {
node
[i
]=i
+1;
MIKRO_Init
(node
[i
],0);
}
#endif /* MIKRO_COM */
#ifdef uSMC_USB
uSMC_Open
();
for (i
=0; i
<3; i
++) {
node
[i
]=uSMC_FindSerial
(serials
[i
])+1;
uSMC_Init
(node
[i
],1);
}
#endif /* uSMC_USB */
#ifdef SP2155_PORT
SP2155_Open
(SP2155_PORT
);
#endif /* SP2155_PORT */
if ((p1h
= LoadPanel
(0, "qe2d_ui.uir", P1
)) < 0) return -1;
DisplayPanel
(p1h
);
K617_open
(1,PROLOGIX_PORT
,K617_ADDR
,0,13);
K617_clear
();
GetCtrlVal
(p1h
,P1_RANGE_R
,&irange
);
K617_current_mode
(irange
);
K617_zero_correct
(1);
K617_data_format
(0);
K617_trigger_mode
(1);
#ifdef SP2155_PORT
igr
=SP2155_GetGrating
();
SetCtrlVal
(p1h
, P1_GRATING
, igr
);
icwl
= SP2155_GetWavelength
();
SetCtrlVal
(p1h
, P1_CWL
, icwl
);
#endif /* SP2155_PORT */
QueueUserEvent
(1000, p1h
, P1_VOUT
);
QueueUserEvent
(1000, p1h
, P1_VSOURCE
);
QueueUserEvent
(1000, p1h
, P1_TIMER
);
QueueUserEvent
(1000, p1h
, P1_WL0
);
QueueUserEvent
(1000, p1h
, P1_POSITION
);
fp
= fopen ("refqe.txt", "r");
nref
=0;
while(1) {
iret
=fscanf (fp
, " %d %f", &wl
[0][nref
], &qe
[0][nref
]);
if (iret
==2) nref
++;
else break;
}
fclose (fp
);
SetCtrlVal
(p1h
, P1_NREF
, nref
);
plqeh
[0] = PlotXY
(p1h
, P1_GQE
, wl
[0], qe
[0], nref
, VAL_INTEGER
,
VAL_FLOAT
, VAL_THIN_LINE
, VAL_EMPTY_SQUARE
,
VAL_SOLID
, 1, VAL_BLACK
);
#ifdef MIKRO_COM
SetCtrlVal
(p1h
, P1_STAGELED
,1);
for (i
=0; i
<3; i
++) {
MIKRO_GetPosition
(node
[i
],&CurPos
[i
]);
SetCtrlVal
(p1h
,PosCtrl
[i
],CurPos
[i
]);
}
SetCtrlVal
(p1h
,P1_STAGELED
,0);
#endif /* MIKRO_COM */
#ifdef uSMC_USB
SetCtrlVal
(p1h
, P1_STAGELED
,1);
for (i
=0; i
<3; i
++) {
uSMC_GetPosition
(node
[i
],&CurPos
[i
]);
SetCtrlVal
(p1h
,PosCtrl
[i
],CurPos
[i
]);
}
SetCtrlVal
(p1h
, P1_STAGELED
,0);
#endif /* uSMC_USB */
do {
GetUserEvent
(1, &pID
, &rID
);
switch (rID
) {
case P1_TIMER
:
rcurr
=K617_get
(NULL
, NULL
);
SetCtrlVal
(p1h
, P1_CURR
, rcurr
);
K617_status
();
SetCtrlVal
(p1h
, P1_VSOURCE
, K617Stat.
vsource_operate);
break;
case P1_GRATING
:
GetCtrlVal
(p1h
, P1_GRATING
, &igr
);
#ifdef SP2155_PORT
SetCtrlVal
(p1h
, P1_GLED
, 1);
SP2155_SetGrating
(igr
);
SetCtrlVal
(p1h
, P1_GLED
, 0);
#endif /* SP2155_PORT */
MessagePopup
("Reminder", "1.Switch the light source!\n2.Adjust the slit!\n3.Load the range file!");
break;
case P1_WL0
:
case P1_DWL
:
case P1_NWL
:
GetCtrlVal
(p1h
, P1_WL0
, &iwl0
);
GetCtrlVal
(p1h
, P1_DWL
, &idwl
);
GetCtrlVal
(p1h
, P1_NWL
, &inwl
);
ilwl
=iwl0
+(inwl
-1)*idwl
;
SetCtrlVal
(p1h
, P1_LWL
, ilwl
);
break;
case P1_CWL
:
GetCtrlVal
(p1h
, P1_CWL
, &icwl
);
#ifdef SP2155_PORT
SetCtrlVal
(p1h
, P1_GLED
, 1);
SP2155_SetWavelength
(icwl
);
SetCtrlVal
(p1h
, P1_GLED
, 0);
#endif /* SP2155_PORT */
break;
case P1_SCAN
:
SetCtrlAttribute
(p1h
, P1_TIMER
, ATTR_ENABLED
, 0);
GetCtrlVal
(p1h
, P1_WL0
, &iwl0
);
GetCtrlVal
(p1h
, P1_DWL
, &idwl
);
GetCtrlVal
(p1h
, P1_NWL
, &inwl
);
GetCtrlVal
(p1h
, P1_WAIT
, &wait
);
K617_trigger_mode
(1);
MDelay
(2);
for (i
=0; i
<inwl
; i
++) {
icwl
=iwl0
+i
*idwl
;
#ifdef SP2155_PORT
SetCtrlVal
(p1h
, P1_GLED
, 1);
SP2155_SetWavelength
(icwl
);
SetCtrlVal
(p1h
, P1_GLED
, 0);
#endif /* SP2155_PORT */
SetCtrlVal
(p1h
, P1_CWL
, icwl
);
MDelay
(wait
);
rcurr
=K617_get
(NULL
, NULL
);
SetCtrlVal
(p1h
, P1_CURR
, rcurr
);
wl
[1][i
]=icwl
;
tok
[1][i
]=-rcurr
;
}
if (plh
[1]) DeleteGraphPlot
(p1h
, P1_GSAMPLE
, plh
[1], VAL_IMMEDIATE_DRAW
);
plh
[1] = PlotXY
(p1h
, P1_GSAMPLE
, wl
[1], tok
[1], inwl
, VAL_INTEGER
, VAL_FLOAT
,
VAL_THIN_LINE
, VAL_EMPTY_SQUARE
, VAL_SOLID
, 1, VAL_RED
);
K617_trigger_mode
(0);
SetCtrlAttribute
(p1h
, P1_TIMER
, ATTR_ENABLED
, 1);
break;
case P1_READREFCURR
:
iret
= FileSelectPopup
("", "*.dat", ".dat",
"Izberi binarno datoteko za meritve",
VAL_SELECT_BUTTON
, 0, 0, 1, 1, pfile
);
if (iret
==1) {
fp
= fopen (pfile
, "rb");
nb
=fread(hdr
,sizeof(int),5,fp
);
//printf("[%d] %d %d %d %d %d\n",nb, hdr[0], hdr[1], hdr[2], hdr[3],hdr[4]);
switch (hdr
[0]) {
case 3: {
nb
=fread(&hdr
[5],sizeof(int),5,fp
);
//printf("x=%u y=%u | i0=%g i1=%g t=%u\t",hdr[5],hdr[6],fhdr[7],fhdr[8],hdr[9]);
}
case 2:
case 1:
nref
=hdr
[1]/sizeof(int)/5-1;
if (hdr
[0]==3) nref
--;
//printf("%d [%d] x=%d y=%d\n",hdr[2],nref, hdr[3],hdr[4]);
for (i
=0; i
<nref
; i
++) {
nb
=fread(sdata
,sizeof(float),5,fp
);
wl
[0][i
]=sdata
[0];
tok
[0][i
]=sdata
[1];
qe
[0][i
]=sdata
[3];
}
SetCtrlVal
(p1h
, P1_NREF
, nref
);
if (plqeh
[0]) DeleteGraphPlot
(p1h
, P1_GQE
, plqeh
[0], VAL_IMMEDIATE_DRAW
);
plqeh
[0] = PlotXY
(p1h
, P1_GQE
, wl
[0], qe
[0], nref
, VAL_INTEGER
,
VAL_FLOAT
, VAL_THIN_LINE
, VAL_EMPTY_SQUARE
,
VAL_SOLID
, 1, VAL_BLACK
);
if (plh
[0]) DeleteGraphPlot
(p1h
, P1_GREF
, plh
[0], VAL_IMMEDIATE_DRAW
);
plh
[0] = PlotXY
(p1h
, P1_GREF
, wl
[0], tok
[0], nref
, VAL_INTEGER
, VAL_FLOAT
,
VAL_THIN_LINE
, VAL_EMPTY_SQUARE
, VAL_SOLID
, 1, VAL_RED
);
break;
}
fclose(fp
);
}
break;
case P1_REFSCAN
:
MessagePopup
("Reminder", "Switch the cable to measure the reference PMT current!");
SetCtrlAttribute
(p1h
, P1_TIMER
, ATTR_ENABLED
, 0);
#ifdef MIKRO_COM
SetCtrlVal
(p1h
, P1_STAGELED
, 1);
for (i
=0; i
<2; i
++) {
GetTableCellVal
(p1h
,P1_POINTS
,MakePoint
(i
+1,1),&CurPos
[i
]);
MIKRO_MoveTo
(node
[i
],CurPos
[i
]);
MIKRO_GetPosition
(node
[i
],&CurPos
[i
]);
SetCtrlVal
(p1h
, PosCtrl
[i
],CurPos
[i
]);
}
SetCtrlVal
(p1h
, P1_STAGELED
, 0);
#endif /* MIKRO_COM */
#ifdef uSMC_USB
SetCtrlVal
(p1h
, P1_STAGELED
, 1);
for (i
=0; i
<2; i
++) {
GetTableCellVal
(p1h
,P1_POINTS
,MakePoint
(i
+1,1),&CurPos
[i
]);
uSMC_MoveTo
(node
[i
],CurPos
[i
]);
uSMC_GetPosition
(node
[i
],&CurPos
[i
]);
SetCtrlVal
(p1h
, PosCtrl
[i
],CurPos
[i
]);
}
SetCtrlVal
(p1h
, P1_STAGELED
, 0);
#endif /* uSMC_USB */
K617_trigger_mode
(1);
#ifdef SP2155_PORT
SetCtrlVal
(p1h
, P1_GLED
, 1);
SP2155_SetWavelength
(1000);
SetCtrlVal
(p1h
, P1_GLED
, 0);
#endif /* SP2155_PORT */
GetCtrlVal
(p1h
, P1_WAIT0
, &wait
);
if (MDelay
(wait
*60.
)) break;
GetCtrlVal
(p1h
, P1_WAIT
, &wait
);
tokoff
[0]=getavg
(ncurroff
);
SetCtrlVal
(p1h
, P1_BGRCUR0
,tokoff
[0]);
for (i
=0; i
<nref
; i
++) {
icwl
=wl
[0][i
];
#ifdef SP2155_PORT
SetCtrlVal
(p1h
, P1_GLED
, 1);
SP2155_SetWavelength
(icwl
);
SetCtrlVal
(p1h
, P1_GLED
, 0);
#endif /* SP2155_PORT */
SetCtrlVal
(p1h
, P1_CWL
, icwl
);
if (MDelay
(wait
)) break;
rcurr
=getavg
(ncurrmes
);
SetCtrlVal
(p1h
, P1_CURR
, rcurr
);
tok
[0][i
]=-(rcurr
-tokoff
[0]);
}
if (plh
[0]) DeleteGraphPlot
(p1h
, P1_GREF
, plh
[0], VAL_IMMEDIATE_DRAW
);
plh
[0] = PlotXY
(p1h
, P1_GREF
, wl
[0], tok
[0], nref
, VAL_INTEGER
, VAL_FLOAT
,
VAL_THIN_LINE
, VAL_EMPTY_SQUARE
, VAL_SOLID
, 1, VAL_RED
);
K617_trigger_mode
(0);
SetCtrlAttribute
(p1h
, P1_TIMER
, ATTR_ENABLED
, 1);
break;
case P1_QESCAN
:
MessagePopup
("Reminder", "Switch the cable to measure the sample detector current!");
// moved the delay into qescan()
//GetCtrlVal (p1h, P1_WAIT0, &wait);
//if (MDelay(wait*60)) break;
// reset plots for new scan
for (i
=1; i
<MAXXY
; i
++) {
if(plqeh
[i
]) SetPlotAttribute
(p1h
, P1_GQE
, plqeh
[i
], ATTR_TRACE_COLOR
, VAL_LT_GRAY
);
if(plh
[i
]) SetPlotAttribute
(p1h
, P1_GSAMPLE
, plh
[i
], ATTR_TRACE_COLOR
, VAL_LT_GRAY
);
plh
[i
]=0;
plqeh
[i
]=0;
}
if(plqeh
[0]) DeleteGraphPlot
(p1h
, P1_GQE
, plqeh
[0], VAL_IMMEDIATE_DRAW
);
plqeh
[0] = PlotXY
(p1h
, P1_GQE
, wl
[0], qe
[0], nref
, VAL_INTEGER
,
VAL_FLOAT
, VAL_THIN_LINE
, VAL_EMPTY_SQUARE
,
VAL_SOLID
, 1, VAL_BLACK
);
RefreshGraph
(p1h
, P1_GQE
);
RefreshGraph
(p1h
, P1_GSAMPLE
);
qescan
();
break;
case P1_QESCANALL
:
MessagePopup
("Reminder", "Switch the cable to measure the sample detector current!");
iret
=FileSelectPopup
("", "*.dat", ".dat",
"Izberi binarno datoteko za meritve",
VAL_SAVE_BUTTON
, 0, 0, 1, 1, pfile
);
if (iret
==1||(iret
==2)) {
// moved the delay into qescan()
//GetCtrlVal (p1h, P1_WAIT0, &wait);
//if (MDelay(wait*60)) break;
// reset plots for new scan
/*DeleteGraphPlot (p1h, P1_GQE, -1, VAL_IMMEDIATE_DRAW);
plqeh[0] = PlotXY (p1h, P1_GQE, wl[0], qe[0], nref, VAL_INTEGER,
VAL_FLOAT, VAL_THIN_LINE, VAL_EMPTY_SQUARE,
VAL_SOLID, 1, VAL_BLACK);
DeleteGraphPlot (p1h, P1_GSAMPLE, -1, VAL_IMMEDIATE_DRAW);
for (i=0; i<MAXXY; i++) {
plh[i]=0;
plqeh[i]=0;
}
*/
for (i
=1; i
<MAXXY
; i
++) {
if(plqeh
[i
]) SetPlotAttribute
(p1h
, P1_GQE
, plqeh
[i
], ATTR_TRACE_COLOR
, VAL_LT_GRAY
);
if(plh
[i
]) SetPlotAttribute
(p1h
, P1_GSAMPLE
, plh
[i
], ATTR_TRACE_COLOR
, VAL_LT_GRAY
);
plh
[i
]=0;
plqeh
[i
]=0;
}
if(plqeh
[0]) DeleteGraphPlot
(p1h
, P1_GQE
, plqeh
[0], VAL_IMMEDIATE_DRAW
);
plqeh
[0] = PlotXY
(p1h
, P1_GQE
, wl
[0], qe
[0], nref
, VAL_INTEGER
,
VAL_FLOAT
, VAL_THIN_LINE
, VAL_EMPTY_SQUARE
,
VAL_SOLID
, 1, VAL_BLACK
);
RefreshGraph
(p1h
, P1_GQE
);
RefreshGraph
(p1h
, P1_GSAMPLE
);
fp
= fopen (pfile
, "wb");
GetNumTableRows
(p1h
, P1_POINTS
, &nrows
);
for (j
=1; j
<nrows
; j
++) {
SetCtrlVal
(p1h
, P1_POSITION
, j
);
SetTableSelection
(p1h
, P1_POINTS
, MakeRect
(j
+1,1,1,2));
GetTableCellVal
(p1h
, P1_POINTS
, MakePoint
(1,j
+1), &CurPos
[0]);
GetTableCellVal
(p1h
, P1_POINTS
, MakePoint
(2,j
+1), &CurPos
[1]);
if (CurPos
[0] <= 0 && CurPos
[1]<= 0) {
j
=nrows
;
continue;
}
iret
=qescan
();
if (iret
) break;
GetCtrlVal
(p1h
, P1_X
, &CurPos
[0]);
GetCtrlVal
(p1h
, P1_Y
, &CurPos
[1]);
hdr
[0]=3;//recid 1,2= hdr len=5, 3=hdr len=10
hdr
[1]=(nref
*5+10)*sizeof(int);
hdr
[2]=j
;
hdr
[3]=CurPos
[0];
hdr
[4]=CurPos
[1];
GetTableCellVal
(p1h
, P1_POINTS
, MakePoint
(1,j
+1), &CurPos
[0]);
GetTableCellVal
(p1h
, P1_POINTS
, MakePoint
(2,j
+1), &CurPos
[1]);
hdr
[5]=CurPos
[0];
hdr
[6]=CurPos
[1];
fhdr
[7]=tokoff
[0];
fhdr
[8]=tokoff
[j
];
hdr
[9]=time(NULL
);
//printf("--> %d %d %d %d %d\n", hdr[0],hdr[1],hdr[2],hdr[3],hdr[4]);
fwrite (hdr
, sizeof(int), 10, fp
);
for (i
=0; i
<nref
; i
++) {
sdata
[0]=wl
[0][i
];
sdata
[1]=tok
[0][i
];
sdata
[2]=tok
[j
][i
];
sdata
[3]=qe
[0][i
];
sdata
[4]=qe
[j
][i
];
fwrite (sdata
, sizeof(float), 5, fp
);
}
}
fclose (fp
);
}
break;
case P1_HO
:
// if (!daq_on) {
SetWaitCursor
(1);
#ifdef MIKRO_COM
SetCtrlVal
(p1h
,P1_STAGELED
,1);
for (i
=0; i
<3; i
++) MIKRO_ReferenceMove
(node
[i
]);
SetCtrlVal
(p1h
,P1_STAGELED
,0);
#endif /* MIKRO_COM */
#ifdef uSMC_USB
SetCtrlVal
(p1h
,P1_STAGELED
,1);
for (i
=0; i
<3; i
++)uSMC_ReferenceMove
(node
[i
]);
SetCtrlVal
(p1h
,P1_STAGELED
,0);
#endif /* uSMC_USB */
SetWaitCursor
(0);
// }
break;
case P1_GOXY
:
GetCtrlVal
(p1h
,P1_POSITION
,&npos
);
#ifdef MIKRO_COM
SetCtrlVal
(p1h
,P1_STAGELED
,1);
for (i
=0; i
<2; i
++) {
GetTableCellVal
(p1h
,P1_POINTS
,MakePoint
(i
+1,npos
+1),&CurPos
[i
]);
MIKRO_MoveTo
(node
[i
],CurPos
[i
]);
MIKRO_GetPosition
(node
[i
],&CurPos
[i
]);
SetCtrlVal
(p1h
,PosCtrl
[i
],CurPos
[i
]);
}
SetCtrlVal
(p1h
,P1_STAGELED
,0);
#endif /* MIKRO_COM */
#ifdef uSMC_USB
SetCtrlVal
(p1h
,P1_STAGELED
,1);
for (i
=0; i
<2; i
++) {
GetTableCellVal
(p1h
,P1_POINTS
,MakePoint
(i
+1,npos
+1),&CurPos
[i
]);
uSMC_MoveTo
(node
[i
],CurPos
[i
]);
uSMC_GetPosition
(node
[i
],&CurPos
[i
]);
SetCtrlVal
(p1h
,PosCtrl
[i
],CurPos
[i
]);
}
SetCtrlVal
(p1h
,P1_STAGELED
,0);
#endif /* uSMC_USB */
break;
case P1_ZC
:
K617_zero_correct
(1);
break;
case P1_VOUT
:
GetCtrlVal
(p1h
, P1_VOUT
, &vout
);
K617_vsource_set
(vout
);
break;
case P1_VSOURCE
:
GetCtrlVal
(p1h
, P1_VSOURCE
, &vsource
);
K617_vsource_operate
(vsource
);
break;
case P1_RANGE_R
:
GetCtrlVal
(p1h
,P1_RANGE_R
,&irange
);
K617_current_mode
(irange
);
break;
case P1_LOADPOINTS
:
iret
= FileSelectPopup
("", "*.txt", ".txt",
"Izberi datoteko s pozicijami",
VAL_LOAD_BUTTON
, 0, 0, 1, 0, pfile
);
if (iret
==1) {
fp
= fopen (pfile
, "r");
i
=1;
while(1) {
iret
=fscanf (fp
, " %d %d", &CurPos
[0], &CurPos
[1]);
if (iret
==2) {
SetTableCellVal
(p1h
, P1_POINTS
, MakePoint
(1,i
), CurPos
[0]);
SetTableCellVal
(p1h
, P1_POINTS
, MakePoint
(2,i
), CurPos
[1]);
i
++;
} else
break;
}
fclose (fp
);
}
break;
case P1_SAVEPOINTS
:
iret
=FileSelectPopup
("", "*.txt", ".txt",
"Izberi datoteko s pozicijami",
VAL_SAVE_BUTTON
, 0, 0, 1, 1, pfile
);
if ((iret
==1)||(iret
==2)) {
fp
=fopen(pfile
,"w");
GetNumTableRows
(p1h
, P1_POINTS
, &i
);
for (j
=0; j
<i
;) {
j
++;
GetTableCellVal
(p1h
, P1_POINTS
, MakePoint
(1,j
), &CurPos
[0]);
GetTableCellVal
(p1h
, P1_POINTS
, MakePoint
(2,j
), &CurPos
[1]);
fprintf(fp
,"%d %d\n", CurPos
[0], CurPos
[1]);
}
fclose (fp
);
}
break;
case P1_SAVEQE
:
iret
=FileSelectPopup
("", "*.txt", ".txt",
"Izberi datoteko za meritve",
VAL_SAVE_BUTTON
, 0, 0, 1, 1, pfile
);
if (iret
==1||(iret
==2)) {
fp
= fopen (pfile
, "w");
GetCtrlVal
(p1h
, P1_POSITION
, &npos
);
for (i
=0; i
<nref
; i
++)
fprintf(fp
,"%d %g %g %g %g\n",
wl
[0][i
],tok
[0][i
],tok
[npos
][i
],qe
[0][i
],qe
[npos
][i
]);
fclose (fp
);
}
break;
case P1_POSITION
:
GetCtrlVal
(p1h
,P1_POSITION
,&npos
);
SetTableSelection
(p1h
, P1_POINTS
, MakeRect
(npos
+1,1,1,2));
break;
case P1_READQE
:
iret
= FileSelectPopup
("", "*.txt", ".txt",
"Izberi referencni QE",
VAL_LOAD_BUTTON
, 0, 0, 1, 0, pfile
);
if (iret
==1) {
fp
= fopen (pfile
, "r");
nref
=0;
while(1) {
iret
=fscanf (fp
, " %d %f", &wl
[0][nref
], &qe
[0][nref
]);
if (iret
==2) nref
++;
else break;
}
fclose (fp
);
SetCtrlVal
(p1h
, P1_NREF
, nref
);
if (plqeh
[0]) DeleteGraphPlot
(p1h
, P1_GQE
, plqeh
[0], VAL_IMMEDIATE_DRAW
);
plqeh
[0] = PlotXY
(p1h
, P1_GQE
, wl
[0], qe
[0], nref
, VAL_INTEGER
,
VAL_FLOAT
, VAL_THIN_LINE
, VAL_EMPTY_SQUARE
,
VAL_SOLID
, 1, VAL_BLACK
);
}
break;
case P1_GLED
:
break;
case P1_ZSET
:
GetCtrlVal
(p1h
,P1_ZSETTO
,&CurPos
[2]);
#ifdef MIKRO_COM
SetCtrlVal
(p1h
,P1_STAGELED
,1);
MIKRO_MoveTo
(node
[2],CurPos
[2]);
MIKRO_GetPosition
(node
[2],&CurPos
[2]);
SetCtrlVal
(p1h
,PosCtrl
[2],CurPos
[2]);
SetCtrlVal
(p1h
,P1_STAGELED
,0);
#endif /* MIKRO_COM */
#ifdef uSMC_USB
SetCtrlVal
(p1h
,P1_STAGELED
,1);
uSMC_MoveTo
(node
[2],CurPos
[2]);
uSMC_GetPosition
(node
[2],&CurPos
[2]);
SetCtrlVal
(p1h
,PosCtrl
[2],CurPos
[2]);
SetCtrlVal
(p1h
,P1_STAGELED
,0);
#endif /* uSMC_USB */
break;
}
} while ((rID
!= P1_EXIT
)||scan_on
);
DiscardPanel
(p1h
);
K617_trigger_mode
(0);
K617_close
();
#ifdef SP2155_PORT
SP2155_Close
();
#endif /* SP2155_PORT */
#ifdef MIKRO_COM
MIKRO_Close
();
#endif /* MIKRO_COM */
#ifdef uSMC_USB
for (i
=0; i
<3; i
++) uSMC_PowerOff
(node
[i
]);
uSMC_Close
();
#endif /* uSMC_USB */
return 0;
}