Subversion Repositories f9daq

Rev

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

Rev 185 Rev 256
Line 2... Line 2...
2
#include <utility.h>
2
#include <utility.h>
3
#include <gpib.h>
3
#include <gpib.h>
-
 
4
#include "prologix.h"
4
#include "K617.h"
5
#include "K617.h"
5
 
6
 
6
K617STATUS K617Stat;
7
K617STATUS K617Stat;
-
 
8
static int K617_Interface,K617_Port,K617_Gdev;
7
static int gdev,iret;
9
static int iret;
8
 
10
 
9
void GpibError(char *msg) {
11
void GpibError(char *msg) {
10
 
12
 
11
  printf ("%s\n", msg);
13
  printf ("%s\n", msg);
12
 
14
 
Line 46... Line 48...
46
 
48
 
47
  printf ("ibcntl = %ld\n", ibcntl);
49
  printf ("ibcntl = %ld\n", ibcntl);
48
  printf ("\n");
50
  printf ("\n");
49
 
51
 
50
  /* Call ibonl to take the device and interface offline */
52
  /* Call ibonl to take the device and interface offline */
51
  ibonl (gdev,0);
53
  ibonl (K617_Gdev,0);
52
 
54
 
53
  exit(1);
55
  exit(1);
54
}
56
}
55
 
57
 
56
void _VI_FUNC K617_open (int interface, int primary_addr, int secondary_addr,
58
void _VI_FUNC K617_open (int interface, int port, int primary_addr,
57
                         int timeout)
59
                         int secondary_addr, int timeout)
58
{
60
{
-
 
61
  char cmd[100];
59
/*
62
/*
60
  gdev = OpenDev ("GPIB0", "");
63
  K617_Gdev = OpenDev ("GPIB0", "");
61
  if (ibsta & ERR) GpibError("OpenDev Error");
-
 
62
  iret = ibpad (gdev, 0);
-
 
63
  if (ibsta & ERR) GpibError("OpenDev Error");
64
  if (ibsta & ERR) GpibError("OpenDev Error");
64
  iret = ibsad (gdev, NO_SAD);
-
 
65
  iret = ibtmo (gdev, T10s);
-
 
66
  iret = ibeot (gdev, 1);
-
 
67
  iret = ibeos (gdev, 0);
65
  iret = ibpad (K617_Gdev, 0);
68
*/
-
 
69
  gdev = ibdev(interface,primary_addr,secondary_addr,timeout,1,0);
-
 
70
  if (ibsta & ERR) GpibError("OpenDev Error");
66
  if (ibsta & ERR) GpibError("OpenDev Error");
-
 
67
  iret = ibsad (K617_Gdev, NO_SAD);
-
 
68
  iret = ibtmo (K617_Gdev, T10s);
-
 
69
  iret = ibeot (K617_Gdev, 1);
-
 
70
  iret = ibeos (K617_Gdev, 0);
-
 
71
*/
-
 
72
  K617_Interface=interface;
-
 
73
  K617_Port=port;
-
 
74
  switch (K617_Interface){
-
 
75
    case 1:
-
 
76
      PROLOGIX_Open (K617_Port);
-
 
77
      sprintf(cmd,"++addr %0d",primary_addr);
-
 
78
      PROLOGIX_Send (cmd);
-
 
79
      PROLOGIX_Send ("++auto 0");
-
 
80
      PROLOGIX_Send ("++eoi 1");
-
 
81
      PROLOGIX_Send ("++eot_enable 0");
-
 
82
      PROLOGIX_Send ("++read_tmo_ms 1000");
-
 
83
      break;
-
 
84
    default:
-
 
85
      K617_Gdev = ibdev(K617_Port,primary_addr,secondary_addr,timeout,1,0);
-
 
86
      if (ibsta & ERR) GpibError("OpenDev Error");
-
 
87
  }
71
  Delay(GDELAY);  
88
  Delay(GDELAY);  
72
  return;  
89
  return;  
73
}
90
}
74
 
91
 
75
void _VI_FUNC K617_clear (void)
92
void _VI_FUNC K617_clear (void)
76
{
93
{
-
 
94
  switch (K617_Interface){
-
 
95
    case 1:
-
 
96
      PROLOGIX_Send("++clr");
-
 
97
      break;
-
 
98
    default:
77
  iret = ibclr (gdev);                 /* Clear the device                        */
99
      iret = ibclr (K617_Gdev); // Clear the device
78
  if (ibsta & ERR) GpibError("OpenDev Error");
100
      if (ibsta & ERR) GpibError("OpenDev Error");
-
 
101
  }
79
  Delay(GDELAY);  
102
//  Delay(GDELAY);   
-
 
103
  Delay(2.);
80
  return;  
104
  return;  
81
   
-
 
82
}
105
}
83
 
106
 
84
void _VI_FUNC K617_send (char *cmd, int len)
107
void _VI_FUNC K617_send (char *cmd, int len)
85
{
108
{
-
 
109
  switch (K617_Interface){
-
 
110
    case 1:
-
 
111
      PROLOGIX_Send(cmd);
-
 
112
      break;
-
 
113
    default:
86
  iret = ibwrt (gdev, cmd, len);
114
      iret = ibwrt (K617_Gdev, cmd, len);
87
  if (ibsta & ERR) GpibError("OpenDev Error");
115
      if (ibsta & ERR) GpibError("OpenDev Error");
-
 
116
  }
88
  Delay(GDELAY);  
117
  Delay(GDELAY);  
89
  return;  
118
  return;  
90
}
119
}
91
 
120
 
92
int _VI_FUNC K617_receive (char *response, int maxbyt)
121
int _VI_FUNC K617_receive (char *response, int maxbyt)
93
{
122
{
-
 
123
  switch (K617_Interface){
-
 
124
    case 1:
-
 
125
      PROLOGIX_Send("++read eoi");
-
 
126
      return PROLOGIX_Receive (response,maxbyt);
-
 
127
      break;
-
 
128
    default:
94
  iret = ibrd (gdev, response, maxbyt);
129
      iret = ibrd (K617_Gdev, response, maxbyt);
95
  if (ibsta & ERR) GpibError("OpenDev Error");
130
      if (ibsta & ERR) GpibError("OpenDev Error");
96
  response[ibcntl]=0;
131
      response[ibcntl]=0;
97
  return ibcntl;    
132
      return ibcntl;    
-
 
133
  }
98
}
134
}
99
 
135
 
100
void _VI_FUNC K617_status (void)
136
void _VI_FUNC K617_status (void)
101
{
137
{
102
  int len;
138
  int len;
Line 108... Line 144...
108
         &K617Stat.function,&K617Stat.range,&K617Stat.zero_check,
144
         &K617Stat.function,&K617Stat.range,&K617Stat.zero_check,
109
         &K617Stat.zero_correct,&K617Stat.suppress,&K617Stat.trigger,
145
         &K617Stat.zero_correct,&K617Stat.suppress,&K617Stat.trigger,
110
         &K617Stat.vsource_operate,&K617Stat.read_mode,
146
         &K617Stat.vsource_operate,&K617Stat.read_mode,
111
         &K617Stat.data_prefix,&K617Stat.display,
147
         &K617Stat.data_prefix,&K617Stat.display,
112
         &K617Stat.data_store,&K617Stat.srq,&K617Stat.eoi,K617Stat.terminator);
148
         &K617Stat.data_store,&K617Stat.srq,&K617Stat.eoi,K617Stat.terminator);
-
 
149
//  printf("617FRRCZNTOBGDQMMKYY\n");
-
 
150
//  printf("%s\n",cres);
113
  K617_send ("X", 1);
151
//  K617_send ("X", 1);
114
  return;
152
  return;
115
}
153
}
116
 
154
 
117
void _VI_FUNC K617_data_format (int mode)
155
void _VI_FUNC K617_data_format (int mode)
118
{
156
{
119
  int len;
157
  int len;
120
  char cmd[100];
158
  char cmd[100];
121
 
159
 
122
  len=sprintf(cmd,"G%0dX",mode);
160
  len=sprintf(cmd,"G%0dX",mode);
123
  K617_send (cmd, len);
161
  K617_send (cmd, len);
Line 136... Line 174...
136
    *loc=-1;
174
    *loc=-1;
137
    sscanf(cres,"%4c%lg,%d",prefix, &value, loc);
175
    sscanf(cres,"%4c%lg,%d",prefix, &value, loc);
138
    prefix[4]=0;
176
    prefix[4]=0;
139
  } else {
177
  } else {
140
    sscanf(cres,"%*4c%lg,%*d",&value);
178
    sscanf(cres,"%*4c%lg,%*d",&value);
141
  }
179
  }
142
  return value;
180
  return value;
143
}
181
}
144
 
182
 
145
void _VI_FUNC K617_current_mode (int range)
183
void _VI_FUNC K617_current_mode (int range)
146
{
184
{
Line 181... Line 219...
181
{
219
{
182
  int len;
220
  int len;
183
  char cmd[100];
221
  char cmd[100];
184
 
222
 
185
  len=sprintf(cmd,"B%0dX",mode);
223
  len=sprintf(cmd,"B%0dX",mode);
186
  K617_send (cmd, len);
224
  K617_send (cmd, len);
187
  return;
225
  return;
188
}
226
}
189
 
227
 
190
void _VI_FUNC K617_vsource_set (float value)
228
void _VI_FUNC K617_vsource_set (float value)
191
{
229
{
192
  int len;
230
  int len;
Line 205... Line 243...
205
 
243
 
206
  K617_reading_mode (4);
244
  K617_reading_mode (4);
207
  value = K617_get (NULL, NULL);
245
  value = K617_get (NULL, NULL);
208
  K617_reading_mode (0);
246
  K617_reading_mode (0);
209
  return value;    
247
  return value;    
210
}
248
}
211
 
249
 
212
void _VI_FUNC K617_vsource_operate (int operate)
250
void _VI_FUNC K617_vsource_operate (int operate)
213
{
251
{
214
 
252
 
215
  if (operate)
253
  if (operate)
216
    K617_send ("O1X", 3);
254
    K617_send ("O1X", 3);
217
   else
255
   else
218
    K617_send ("O0X", 3);
256
    K617_send ("O0X", 3);
219
   
257
   
220
  return;  
258
  return;  
221
}
259
}
222
 
260
 
223
void _VI_FUNC K617_close (void)
261
void _VI_FUNC K617_close (void)
224
{
262
{
225
//  iret = CloseDev (gdev);
263
//  iret = CloseDev (K617_Gdev);
-
 
264
  switch (K617_Interface){
-
 
265
    case 1:
-
 
266
      PROLOGIX_Close();
-
 
267
      break;
-
 
268
    default:
226
  iret = ibonl(gdev, 0);              /* Take the device offline                 */
269
     iret = ibonl(K617_Gdev, 0);// Take the device offline
227
  if (ibsta & ERR) GpibError("OpenDev Error");
270
     if (ibsta & ERR) GpibError("OpenDev Error");
-
 
271
  }
228
  return;
272
  return;
229
}
273
}
230
 
274
 
231
#ifdef K617_MAIN
275
#ifdef K617_MAIN
232
 
276
 
Line 239... Line 283...
239
  double value;
283
  double value;
240
  char cres[100];
284
  char cres[100];
241
 
285
 
242
  if (InitCVIRTE (hInstance, 0, 0) == 0) return -1;    /* out of memory */
286
  if (InitCVIRTE (hInstance, 0, 0) == 0) return -1;    /* out of memory */
243
       
287
       
244
  K617_open (0, 3, 0, 13);
288
  K617_open (1,5,3,0,13);
245
/*
-
 
246
  K617_clear ();
289
  K617_clear ();
247
  K617_current_mode (4);
290
  K617_current_mode (4);
248
  K617_zero_correct (1);
291
  K617_zero_correct (1);
249
  K617_data_format (0);
292
  K617_data_format (0);
250
  K617_trigger_mode (0);
293
  K617_trigger_mode (1);
251
  K617_vsource_set (-100.);
294
  K617_vsource_set (-100.);
252
  K617_vsource_operate (1);
295
  K617_vsource_operate (1);
253
*/
-
 
254
  K617_status ();
-
 
255
 
296
 
-
 
297
  K617_status();
-
 
298
 
256
  value=K617_get(cres, &i);
299
  value=K617_get(cres,&i);
-
 
300
  printf("%s, %lg, %d\n",cres,value,i);
-
 
301
  value=K617_vsource_get();
-
 
302
  printf("%lg\n",value);
-
 
303
  value=K617_get(cres,&i);
257
  printf("%s, %lg, %d\n",cres,value,i);
304
  printf("%s, %lg, %d\n",cres,value,i);
258
 
-
 
259
  value=K617_vsource_get();
305
  value=K617_get(cres,&i);
260
  printf("%s, %lg, %d\n",cres,value,i);
306
  printf("%s, %lg, %d\n",cres,value,i);
261
 
307
  value=K617_get(cres,&i);
-
 
308
  printf("%s, %lg, %d\n",cres,value,i);
262
  value=K617_get(cres, &i);
309
  value=K617_get(cres,&i);
263
  printf("%s, %lg, %d\n",cres,value,i);
310
  printf("%s, %lg, %d\n",cres,value,i);
264
 
-
 
265
  Delay(5);
311
  Delay(5);
266
//  K617_vsource_operate (0);
312
  K617_vsource_operate (0);
267
 
313
 
268
  K617_close ();
314
  K617_close();
269
 
315
 
270
  return 0;
316
  return 0;
271
}
317
}
272
 
318
 
273
#endif
319
#endif