Subversion Repositories f9daq

Rev

Rev 310 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 310 Rev 312
Line 10... Line 10...
10
static ViSession DeviceHandle,RMHandle;
10
static ViSession DeviceHandle,RMHandle;
11
 
11
 
12
 
12
 
13
char response[0xFF]= {0};
13
char response[0xFF]= {0};
14
 
14
 
15
 
-
 
-
 
15
int K2231A_SetDebug(int x){ debug = x;return 0;};
16
 
16
 
17
int K2231A_Write(const char *format, ...  )
17
int K2231A_Write(const char *format, ...  )
18
{
18
{
19
        char cmd[0xFF];
19
        char cmd[0xFF];
20
    va_list aptr;
20
    va_list aptr;
21
    va_start(aptr, format);
21
    va_start(aptr, format);
22
    vsprintf(cmd, format, aptr);
22
    vsprintf(cmd, format, aptr);
23
    va_end(aptr);
23
    va_end(aptr);
24
 
24
 
25
        char str[0xFF];
25
        char str[0xFF];
26
        sprintf(str, "%s\r\n",cmd);
26
        sprintf(str, "%s\r\n",cmd);
27
        int istat = viPrintf (DeviceHandle, str);
27
        int istat = viPrintf (DeviceHandle, str);
28
        if (debug) printf("K2231A_Write %s\n", cmd);
28
        if (debug) printf("K2231A_Write %s\n", cmd);
29
        return istat;
29
        return istat;
30
}
30
}
31
 
31
 
32
const char * K2231A_Read(const char *format, ...  )
32
const char * K2231A_Read(const char *format, ...  )
33
{
33
{
34
       
34
       
35
        char cmd[0xFF];
35
        char cmd[0xFF];
36
    va_list aptr;
36
    va_list aptr;
Line 41... Line 41...
41
        char str[0xFF];
41
        char str[0xFF];
42
        int istat=0;
42
        int istat=0;
43
 
43
 
44
        sprintf(str, "%s\n",cmd);
44
        sprintf(str, "%s\n",cmd);
45
        istat = viPrintf (DeviceHandle, str);
45
        istat = viPrintf (DeviceHandle, str);
46
 
46
 
47
        int nb=0;
47
        int nb=0;
48
        istat = viRead (DeviceHandle, response, 0xFF, &nb);
48
        istat = viRead (DeviceHandle, response, 0xFF, &nb);
49
 
49
 
50
        if (nb>0) response[nb-1]=0;
50
        if (nb>0) response[nb-1]=0;
51
        if (debug) printf("K2231A_Read %s : %s\n", cmd, response);
51
        if (debug) printf("K2231A_Read %s : %s\n", cmd, response);
Line 54... Line 54...
54
        return response;
54
        return response;
55
}
55
}
56
 
56
 
57
int K2231A_QueryInt(const char *format, ... )
57
int K2231A_QueryInt(const char *format, ... )
58
{
58
{
59
  char cmd[0xFF];
59
  char cmd[0xFF];
60
  va_list aptr;
60
  va_list aptr;
61
  va_start(aptr, format);
61
  va_start(aptr, format);
62
  vsprintf(cmd, format, aptr);
62
  vsprintf(cmd, format, aptr);
63
  va_end(aptr);
63
  va_end(aptr);
64
  return atoi(K2231A_Read(cmd ));
64
  return atoi(K2231A_Read(cmd ));
65
}
65
}
66
 
66
 
Line 72... Line 72...
72
  va_start(aptr, format);
72
  va_start(aptr, format);
73
  vsprintf(cmd, format, aptr);
73
  vsprintf(cmd, format, aptr);
74
  va_end(aptr);
74
  va_end(aptr);
75
  return atof(K2231A_Read(cmd ));    
75
  return atof(K2231A_Read(cmd ));    
76
}
76
}
-
 
77
 
-
 
78
static int K2231A_Port=5;
-
 
79
int K2231A_SetPort(int x){K2231A_Port=x; return x;};
77
 
80
 
78
int K2231A_Initialize()
81
int K2231A_Initialize()
79
{
82
{
80
 
83
 
81
        istat = viOpenDefaultRM (&RMHandle);
84
        istat = viOpenDefaultRM (&RMHandle);
-
 
85
        char cport[0xFF];
-
 
86
        sprintf(cport,"ASRL%d::INSTR", K2231A_Port );
82
        if (RMHandle) istat = viOpen (RMHandle, "ASRL5::INSTR", VI_NULL, VI_NULL, &DeviceHandle);
87
        if (RMHandle) istat = viOpen (RMHandle, cport , VI_NULL, VI_NULL, &DeviceHandle);
83
        if (DeviceHandle)
88
        if (DeviceHandle)
84
        {
89
        {
85
 
90
 
86
                istat = viSetAttribute (DeviceHandle, VI_ATTR_TERMCHAR, '\n');
91
                istat = viSetAttribute (DeviceHandle, VI_ATTR_TERMCHAR, '\n');
87
                istat = viSetAttribute (DeviceHandle, VI_ATTR_TERMCHAR_EN, VI_TRUE);
92
                istat = viSetAttribute (DeviceHandle, VI_ATTR_TERMCHAR_EN, VI_TRUE);
Line 144... Line 149...
144
double K2231A_GetSetVoltage(){
149
double K2231A_GetSetVoltage(){
145
  return K2231A_QueryDouble("VOLT?");    
150
  return K2231A_QueryDouble("VOLT?");    
146
}
151
}
147
 
152
 
148
double K2231A_SetCurrent(double x){
153
double K2231A_SetCurrent(double x){
149
  return K2231A_QueryDouble("CURR %f", x);    
154
  return K2231A_Write("CURR %f", x);    
150
}
155
}
151
 
156
 
152
double K2231A_SetVoltage(double x){
157
double K2231A_SetVoltage(double x){
153
  return K2231A_QueryDouble("VOLT %f", x);    
158
  return K2231A_Write("VOLT %f", x);    
154
}
159
}
155
 
160
 
156
double K2231A_GetCurrentMonitor(){
161
double K2231A_GetCurrentMonitor(){
157
  return K2231A_QueryDouble("MEAS:CURR?");    
162
  return K2231A_QueryDouble("MEAS:CURR?");    
158
}
163
}