Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include <userint.h>
#include "pw18-1.8aq-ctrl.h"
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <pw18-1.8aq.h>
int TMI_DeviceId
=0;
int TMI_Initialize
()
{
TMI_HandleOpen
= NULL
;
TMI_HandleClose
= NULL
;
TMI_TimeOut
= NULL
;
TMI_Refresh
= NULL
;
TMI_ModelNameQ
= NULL
;
TMI_Voltage
= NULL
;
TMI_VoltageQ
= NULL
;
TMI_Current
= NULL
;
TMI_CurrentQ
= NULL
;
TMI_MainOutput
= NULL
;
TMI_MainOutputQ
= NULL
;
TMI_Delay
= NULL
;
TMI_DelayQ
= NULL
;
TMI_OutputSel
= NULL
;
TMI_OutputSelQ
= NULL
;
TMI_TrackingOnOff
= NULL
;
TMI_TrackingOnOffQ
= NULL
;
TMI_TrackingMode
= NULL
;
TMI_TrackingModeQ
= NULL
;
TMI_TrackingGroup
= NULL
;
TMI_TrackingGroupQ
= NULL
;
TMI_TrackingData
= NULL
;
TMI_TrackingDataQ
= NULL
;
TMI_DelayTime
= NULL
;
TMI_DelayTimeQ
= NULL
;
TMI_Display
= NULL
;
TMI_DisplayQ
= NULL
;
TMI_Preset
= NULL
;
TMI_PresetQ
= NULL
;
TMI_MoniDataQ
= NULL
;
TMI_AdrQ
= NULL
;
TMI_RemoteLocal
= NULL
;
TMI_LocalLockOut
= NULL
;
TMI_DataBackUp
= NULL
;
TMI_SRQEnable
= NULL
;
TMI_AllPresetQ
= NULL
;
TMI_AllPresetQS
= NULL
;
TMI_Out
= NULL
;
TMI_In
= NULL
;
return 0;
}
int TMI_Test
()
{
char str
[0xFF];
if (TMI_HandleOpen
== NULL
) return FALSE
;
if (TMI_HandleClose
== NULL
) return FALSE
;
if (TMI_TimeOut
== NULL
) return FALSE
;
if (TMI_Refresh
== NULL
) return FALSE
;
if (TMI_ModelNameQ
== NULL
) return FALSE
;
if (TMI_Voltage
== NULL
) return FALSE
;
if (TMI_VoltageQ
== NULL
) return FALSE
;
if (TMI_Current
== NULL
) return FALSE
;
if (TMI_CurrentQ
== NULL
) return FALSE
;
if (TMI_MainOutput
== NULL
) return FALSE
;
if (TMI_MainOutputQ
== NULL
) return FALSE
;
if (TMI_Delay
== NULL
) return FALSE
;
if (TMI_DelayQ
== NULL
) return FALSE
;
if (TMI_OutputSel
== NULL
) return FALSE
;
if (TMI_OutputSelQ
== NULL
) return FALSE
;
if (TMI_TrackingOnOff
== NULL
) return FALSE
;
if (TMI_TrackingOnOffQ
== NULL
) return FALSE
;
if (TMI_TrackingMode
== NULL
) return FALSE
;
if (TMI_TrackingModeQ
== NULL
) return FALSE
;
if (TMI_TrackingGroup
== NULL
) return FALSE
;
if (TMI_TrackingGroupQ
== NULL
) return FALSE
;
if (TMI_TrackingData
== NULL
) return FALSE
;
if (TMI_TrackingDataQ
== NULL
) return FALSE
;
if (TMI_DelayTime
== NULL
) return FALSE
;
if (TMI_DelayTimeQ
== NULL
) return FALSE
;
if (TMI_Display
== NULL
) return FALSE
;
if (TMI_DisplayQ
== NULL
) return FALSE
;
if (TMI_Preset
== NULL
) return FALSE
;
if (TMI_PresetQ
== NULL
) return FALSE
;
if (TMI_MoniDataQ
== NULL
) return FALSE
;
if (TMI_AdrQ
== NULL
) return FALSE
;
if (TMI_RemoteLocal
== NULL
) return FALSE
;
if (TMI_LocalLockOut
== NULL
) return FALSE
;
if (TMI_DataBackUp
== NULL
) return FALSE
;
if (TMI_SRQEnable
== NULL
) return FALSE
;
if (TMI_AllPresetQ
== NULL
) return FALSE
;
if (TMI_AllPresetQS
== NULL
) return FALSE
;
if (TMI_Out
== NULL
) return FALSE
;
if (TMI_In
== NULL
) return FALSE
;
TMI_ModelNameQ
(TMI_DeviceId
, str
);
printf("TMI_ModelNameQ %s\n",str
);
return TRUE
;
}
int TMI_Close
()
{
if(TMI_APIDll
!= NULL
) {
if (TMI_DeviceId
){
TMI_RemoteLocal
(TMI_DeviceId
);
TMI_HandleClose
(TMI_DeviceId
);
TMI_DeviceId
= 0;
}
FreeLibrary
(TMI_APIDll
);
}
return 0;
}
int TMI_Open
()
{
TMI_Initialize
();
printf("FALSE =%d TRUE=%d\n", FALSE
, TRUE
);
TMI_APIDll
=LoadLibrary
((LPCSTR
)"TMI_API.dll");
if( TMI_APIDll
== NULL
)
return FALSE
;
TMI_HandleOpen
= (int ( __stdcall
* )( char * , char * )) GetProcAddress
(TMI_APIDll
, "TMI_HandleOpen");
if( TMI_HandleOpen
== NULL
)
return FALSE
;
TMI_TimeOut
= (int ( __stdcall
* )( int , int )) GetProcAddress
(TMI_APIDll
, "TMI_TimeOut");
if( TMI_TimeOut
== NULL
)
return FALSE
;
TMI_Refresh
= (int ( __stdcall
* )( int )) GetProcAddress
(TMI_APIDll
, "TMI_Refresh");
if( TMI_Refresh
== NULL
)
return FALSE
;
TMI_ModelNameQ
= (int ( __stdcall
* )( int , char * )) GetProcAddress
(TMI_APIDll
, "TMI_ModelNameQ");
if( TMI_ModelNameQ
== NULL
)
return FALSE
;
TMI_Voltage
= (int ( __stdcall
* )( int , unsigned char , unsigned char , double )) GetProcAddress
(TMI_APIDll
, "TMI_Voltage");
if( TMI_Voltage
== NULL
)
return FALSE
;
TMI_VoltageQ
= (int ( __stdcall
* )( int , unsigned char , unsigned char , double * )) GetProcAddress
(TMI_APIDll
, "TMI_VoltageQ");
if( TMI_VoltageQ
== NULL
)
return FALSE
;
TMI_Current
= (int ( __stdcall
* )(int , unsigned char , unsigned char , double )) GetProcAddress
(TMI_APIDll
, "TMI_Current");
if( TMI_Current
== NULL
)
return FALSE
;
TMI_CurrentQ
= (int ( __stdcall
* )(int , unsigned char , unsigned char , double * )) GetProcAddress
(TMI_APIDll
, "TMI_CurrentQ");
if( TMI_CurrentQ
== NULL
)
return FALSE
;
TMI_MainOutput
= (int ( __stdcall
* )(int , unsigned char )) GetProcAddress
(TMI_APIDll
, "TMI_MainOutput");
if( TMI_MainOutput
== NULL
)
return FALSE
;
TMI_MainOutputQ
= (int ( __stdcall
* )(int , unsigned char * )) GetProcAddress
(TMI_APIDll
, "TMI_MainOutputQ");
if( TMI_MainOutputQ
== NULL
)
return FALSE
;
TMI_Delay
= (int ( __stdcall
* )(int , unsigned char )) GetProcAddress
(TMI_APIDll
, "TMI_Delay");
if( TMI_Delay
== NULL
)
return FALSE
;
TMI_DelayQ
= (int ( __stdcall
* )(int , unsigned char * )) GetProcAddress
(TMI_APIDll
, "TMI_DelayQ");
if( TMI_DelayQ
== NULL
)
return FALSE
;
TMI_OutputSel
= (int ( __stdcall
* )(int , unsigned char , unsigned char )) GetProcAddress
(TMI_APIDll
, "TMI_OutputSel");
if( TMI_OutputSel
== NULL
)
return FALSE
;
TMI_OutputSelQ
= (int ( __stdcall
* )(int , unsigned char , unsigned char * )) GetProcAddress
(TMI_APIDll
, "TMI_OutputSelQ");
if( TMI_OutputSelQ
== NULL
)
return FALSE
;
TMI_TrackingOnOff
= (int ( __stdcall
* )(int , unsigned char )) GetProcAddress
(TMI_APIDll
, "TMI_TrackingOnOff");
if( TMI_TrackingOnOff
== NULL
)
return FALSE
;
TMI_TrackingOnOffQ
= (int ( __stdcall
* )(int , unsigned char * )) GetProcAddress
(TMI_APIDll
, "TMI_TrackingOnOffQ");
if( TMI_TrackingOnOffQ
== NULL
)
return FALSE
;
TMI_TrackingMode
= (int ( __stdcall
* )(int , unsigned char )) GetProcAddress
(TMI_APIDll
, "TMI_TrackingMode");
if( TMI_TrackingMode
== NULL
)
return FALSE
;
TMI_TrackingModeQ
= (int ( __stdcall
* )(int , unsigned char * )) GetProcAddress
(TMI_APIDll
, "TMI_TrackingModeQ");
if( TMI_TrackingModeQ
== NULL
)
return FALSE
;
TMI_TrackingGroup
= (int ( __stdcall
* )(int , unsigned char , unsigned char )) GetProcAddress
(TMI_APIDll
, "TMI_TrackingGroup");
if( TMI_TrackingGroup
== NULL
)
return FALSE
;
TMI_TrackingGroupQ
= (int ( __stdcall
* )(int , unsigned char , unsigned char * )) GetProcAddress
(TMI_APIDll
, "TMI_TrackingGroupQ");
if( TMI_TrackingGroupQ
== NULL
)
return FALSE
;
TMI_TrackingData
= (int ( __stdcall
* )(int , unsigned char , unsigned char , double )) GetProcAddress
(TMI_APIDll
, "TMI_TrackingData");
if( TMI_TrackingData
== NULL
)
return FALSE
;
TMI_TrackingDataQ
= (int ( __stdcall
* )(int , unsigned char , unsigned char , double * )) GetProcAddress
(TMI_APIDll
, "TMI_TrackingDataQ");
if( TMI_TrackingDataQ
== NULL
)
return FALSE
;
TMI_DelayTime
= (int ( __stdcall
* )(int , unsigned char , double )) GetProcAddress
(TMI_APIDll
, "TMI_DelayTime");
if( TMI_DelayTime
== NULL
)
return FALSE
;
TMI_DelayTimeQ
= (int ( __stdcall
* )(int , unsigned char , double * )) GetProcAddress
(TMI_APIDll
, "TMI_DelayTimeQ");
if( TMI_DelayTimeQ
== NULL
)
return FALSE
;
TMI_Display
= (int ( __stdcall
* )(int , unsigned char )) GetProcAddress
(TMI_APIDll
, "TMI_Display");
if( TMI_Display
== NULL
)
return FALSE
;
TMI_DisplayQ
= (int ( __stdcall
* )(int , unsigned char * )) GetProcAddress
(TMI_APIDll
, "TMI_DisplayQ");
if( TMI_DisplayQ
== NULL
)
return FALSE
;
TMI_Preset
= (int ( __stdcall
* )(int , unsigned char )) GetProcAddress
(TMI_APIDll
, "TMI_Preset");
if( TMI_Preset
== NULL
)
return FALSE
;
TMI_PresetQ
= (int ( __stdcall
* )(int , unsigned char * )) GetProcAddress
(TMI_APIDll
, "TMI_PresetQ");
if( TMI_PresetQ
== NULL
)
return FALSE
;
TMI_MoniDataQ
= (int ( __stdcall
* )(int , char , double * , double * , char * )) GetProcAddress
(TMI_APIDll
, "TMI_MoniDataQ");
if( TMI_MoniDataQ
== NULL
)
return FALSE
;
TMI_AdrQ
= (int ( __stdcall
* )(int , unsigned char * )) GetProcAddress
(TMI_APIDll
, "TMI_AdrQ");
if( TMI_AdrQ
== NULL
)
return FALSE
;
TMI_RemoteLocal
= (int ( __stdcall
* )(int )) GetProcAddress
(TMI_APIDll
, "TMI_RemoteLocal");
if( TMI_RemoteLocal
== NULL
)
return FALSE
;
TMI_LocalLockOut
= (int ( __stdcall
* )(int )) GetProcAddress
(TMI_APIDll
, "TMI_LocalLockOut");
if( TMI_LocalLockOut
== NULL
)
return FALSE
;
TMI_DataBackUp
= (int ( __stdcall
* )(int )) GetProcAddress
(TMI_APIDll
, "TMI_DataBackUp");
if( TMI_DataBackUp
== NULL
)
return FALSE
;
TMI_SRQEnable
= (int ( __stdcall
* )(int , unsigned char )) GetProcAddress
(TMI_APIDll
, "TMI_SRQEnable");
if( TMI_SRQEnable
== NULL
)
return FALSE
;
TMI_AllPresetQ
= (int ( __stdcall
* )(int , double * )) GetProcAddress
(TMI_APIDll
, "TMI_AllPresetQ");
if( TMI_AllPresetQ
== NULL
)
return FALSE
;
TMI_AllPresetQS
= (int ( __stdcall
* )(int , char * )) GetProcAddress
(TMI_APIDll
, "TMI_AllPresetQS");
if( TMI_AllPresetQS
== NULL
)
return FALSE
;
TMI_Out
= (int ( __stdcall
* )(int , char * )) GetProcAddress
(TMI_APIDll
, "TMI_Out");
if( TMI_Out
== NULL
)
return FALSE
;
TMI_In
= (int ( __stdcall
* )(int , char * )) GetProcAddress
(TMI_APIDll
, "TMI_In");
if( TMI_In
== NULL
)
return FALSE
;
TMI_HandleClose
= (int ( __stdcall
* )( int )) GetProcAddress
(TMI_APIDll
, "TMI_HandleClose");
if( TMI_HandleClose
== NULL
)
return FALSE
;
printf("TMI_In loaded.\n");
return TRUE
;
}
int TMI_OpenHandle
(char * dev
, char * usb
){
TMI_DeviceId
= TMI_HandleOpen
(dev
, usb
);
return TMI_DeviceId
;
}
/****************TOKOVI (potek, kako se spreminjajo tokovi s casom)****************/
void TMI_ReadCurrent
(double * I
, double * V
, unsigned char * mode
, unsigned char *onoff
){
int iRet
;
char ch
=0;
double Voltage
;
double Current
;
char cv_cc
;
iRet
= TMI_TimeOut
(TMI_DeviceId
, 1);
iRet
= TMI_Refresh
(TMI_DeviceId
);
//iRet = TMI_MainOutput(TMI_DeviceId, Output);
//iRet = TMI_MainOutputQ(TMI_DeviceId, &Output);
for (ch
=0;ch
<4;ch
++){
iRet
= TMI_MoniDataQ
(TMI_DeviceId
, ch
+1, &Voltage
, &Current
, &cv_cc
);
//if (debug) printf("[%d] %g V %g A CVCC %d\t",ch, Voltage, Current, cv_cc );
I
[ch
]= Current
; //s tem definiras kaj sta I in V.
V
[ch
]= Voltage
;
}
//if (debug) printf("\n");
return;
}
#ifdef MAIN
#include <ansi_c.h>
#include <utility.h>
#include "pw18-1.8aq-ctrl.h"
#define RSTREG(a,x) (a&=(~(x)))
#define SETREG(a,x) (a|=x)
int gLogToFile
;
int vmon
[4]={P1_VMON_1
,P1_VMON_2
,P1_VMON_3
,P1_VMON_4
};
int imon
[4]={P1_IMON_1
,P1_IMON_2
,P1_IMON_3
,P1_IMON_4
};
int vset
[4]={P1_U_1
,P1_U_2
,P1_U_3
,P1_U_4
};
int iset
[4]={P1_I_1
,P1_I_2
,P1_I_3
,P1_I_4
};
int radiob
[4]={P1_BOX_1
,P1_BOX_2
,P1_BOX_3
,P1_BOX_4
};
int cvcc
[4]={P1_CVCC_1
,P1_CVCC_2
,P1_CVCC_3
,P1_CVCC_4
};
const unsigned char Pre_1
= 1;
int gMask
=0xF;
int pnl
;
FILE
*gFp
;
int main
(int argc
, char *argv
[])
{
int DeviceId
=0;
unsigned char MainOutput
;
double Voltage
, Current
, tinterval
;
char str
[0xFF];
if (InitCVIRTE
(0, argv
, 0) == 0)
return -1; /* out of memory */
SetStdioPort
(CVI_STDIO_WINDOW
);
if ((pnl
= LoadPanel
(0, "pw18-1.8aq-ctrl.uir", P1
)) < 0) return -1;
if (TMI_Open
()== 0) MessagePopup
("Error","Cannot open USB device");
DeviceId
= TMI_OpenHandle
("PW-A","USB:1:1");
if (TMI_Test
() == 0 )MessagePopup
("DLL error","Dll Error");
if (DeviceId
< 0) MessagePopup
("Error","Not Connected");
printf("TMI device ID %d\n",TMI_DeviceId
);
TMI_MainOutputQ
(TMI_DeviceId
, &MainOutput
);
SetCtrlVal
(pnl
, P1_ONOFF
, MainOutput
);
GetCtrlVal
(pnl
, P1_TINTERVAL
, &tinterval
);
SetCtrlAttribute
(pnl
, P1_TIMER
, ATTR_INTERVAL
, tinterval
);
for (unsigned char ch
=0;ch
<4;ch
++){
int ison
;
TMI_VoltageQ
(TMI_DeviceId
, ch
+1, Pre_1
, &Voltage
);
TMI_CurrentQ
(TMI_DeviceId
, ch
+1, Pre_1
, &Current
);
SetCtrlVal
(pnl
, vset
[ch
], Voltage
);
SetCtrlVal
(pnl
, iset
[ch
], Current
);
GetCtrlVal
(pnl
, radiob
[ch
], &ison
);
if (ison
) SETREG
(gMask
,(1<<ch
)); else RSTREG
(gMask
,(1<<ch
));
}
DisplayPanel
(pnl
);
RunUserInterface
();
DiscardPanel
(pnl
);
TMI_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
);
TMI_MainOutput
(TMI_DeviceId
, state
);
break;
}
return 0;
}
int CVICALLBACK SetCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
switch (event
)
{
case EVENT_COMMIT
:
for (unsigned char ch
= 0; ch
<4;ch
++){
//printf("ch %d %x\n", ch, gMask);
if (gMask
& (1<<ch
)){
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
);
TMI_Voltage
(TMI_DeviceId
, ch
+1, Pre_1
, Voltage
);
TMI_VoltageQ
(TMI_DeviceId
, ch
+1, Pre_1
, &Voltage
);
TMI_Current
(TMI_DeviceId
, ch
+1, Pre_1
, Current
);
TMI_CurrentQ
(TMI_DeviceId
, ch
+1, Pre_1
, &Current
);
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
;
switch (event
)
{
case EVENT_COMMIT
:
for (ch
= 0; ch
<4;ch
++){
if (gMask
& (1<<ch
)){
iRet
= TMI_TimeOut
(TMI_DeviceId
, 1);
iRet
= TMI_Refresh
(TMI_DeviceId
);
iRet
= TMI_MoniDataQ
(TMI_DeviceId
, ch
+1, &Voltage
, &Current
, &cv_cc
);
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 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;
}
int CVICALLBACK ExitCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
switch (event
)
{
case EVENT_COMMIT
:
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
<4;i
++) if (control
== radiob
[i
]) break;
if (ison
) SETREG
(gMask
,(1<<i
)); else RSTREG
(gMask
,(1<<i
));
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
;
case EVENT_TIMER_TICK
:
for (ch
= 0; ch
<4;ch
++){
if (gMask
& (1<<ch
)){
TMI_TimeOut
(TMI_DeviceId
, 1);
TMI_Refresh
(TMI_DeviceId
);
TMI_MoniDataQ
(TMI_DeviceId
, ch
+1, &voltage
, ¤t
[ch
], &cv_cc
);
SetCtrlVal
(panel
, vmon
[ch
], voltage
);
SetCtrlVal
(panel
, imon
[ch
], current
[ch
]);
SetCtrlVal
(panel
, cvcc
[ch
], cv_cc
);
if (gLogToFile
){
if (!gFp
) {
gFp
= fopen("pw18-1.8aq.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
, 4, 0, 0, VAL_DOUBLE
);
break;
}
return 0;
}
#endif MAIN