Subversion Repositories f9daq

Rev

Rev 151 | Rev 155 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
151 f9daq 1
#include <windows.h>
2
#include <cvirte.h>
3
#include <utility.h>
4
#include <stdio.h>
5
#include <stdarg.h>
154 f9daq 6
#include "MPOD.h"
151 f9daq 7
 
154 f9daq 8
static mpodInit=1;
9
HSNMP crateHsnmp[MAX_CRATES];
10
 
11
int _VI_FUNC MPOD_Start (void)
12
{
13
  int i;
14
  if (mpodInit) {
15
    for (i=0;i<MAX_CRATES;i++) crateHsnmp[i]=NULL;
16
    if(!snmpInit()) return -1;                     // basic init
17
    mpodInit=0;
18
  }
19
  return 0;
20
}
21
 
22
int _VI_FUNC MPOD_Open (int mpodn, char *address)
23
{
24
  if (crateHsnmp[mpodn]) {
25
    printf("Crate number %i already in use!\n",mpodn);
26
    return -2;
27
  }
28
  crateHsnmp[mpodn] = snmpOpen(address);   // open TCP/IP socket
29
  if(!crateHsnmp[mpodn]) return -1;
30
  return 0;
31
}
32
 
33
int _VI_FUNC MPOD_GetInt (int mpodn, char *oidstr)
34
{
35
  SnmpObject tmpObject;
36
 
37
  getNode(oidstr, &tmpObject);
38
  return snmpGetInt(crateHsnmp[mpodn], &tmpObject);
39
}
40
 
41
double _VI_FUNC MPOD_GetDouble (int mpodn, char *oidstr)
42
{
43
  SnmpObject tmpObject;
44
 
45
  getNode(oidstr, &tmpObject);
46
  return snmpGetDouble(crateHsnmp[mpodn], &tmpObject);
47
}
48
 
49
int _VI_FUNC MPOD_Close (int mpodn)
50
{
51
  snmpClose(crateHsnmp[mpodn]);
52
  crateHsnmp[mpodn]=NULL;
53
  return 0;
54
}
55
 
56
int _VI_FUNC MPOD_End (void)
57
{
58
  if (!mpodInit) {
59
    snmpCleanup();  // finish
60
    mpodInit=1;
61
  }
62
  return 0;
63
}
64
 
65
#ifdef MPOD_MAIN
151 f9daq 66
int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
67
                       LPSTR lpszCmdLine, int nCmdShow) {
68
 
69
  double ret;
70
//  double voltage;
71
  double vSet=0;
72
  int ch=0;
73
  int iret;
74
//  int i, j;
75
 
76
  HSNMP crate1;
77
 
78
  if (InitCVIRTE (hInstance, 0, 0) == 0)
79
    return -1;    /* out of memory */
154 f9daq 80
 
81
  MPOD_Start();
82
  MPOD_Open(0,"arich-mpod1.kek.jp");
83
  crate1 = crateHsnmp[0];
151 f9daq 84
 
85
  printf("-----------------------------------------------------------------\n");
86
 
87
  iret=getMainSwitch(crate1);
88
  printf("Main Switch = %i\n", iret);
89
 
154 f9daq 90
  iret=MPOD_GetInt(0,"moduleNumber.0");
91
  printf("Module Number = %i\n", iret);
151 f9daq 92
 
154 f9daq 93
  ret=MPOD_GetDouble(0,"outputVoltage.1");
94
  printf("Output Voltage = %f.\n", ret);
95
 
151 f9daq 96
  vSet = getOutputVoltage(crate1, ch);
97
  printf("Output Voltage %i = %f.\n", ch, vSet);
98
 
99
//Test Channel Status
100
  iret=getChannelSwitch(crate1, ch);
101
  printf("Channel Status %i = %i\n", ch, iret);
102
 
103
//Test Reading the Sense Measurement
104
  ret = getOutputSenseMeasurement(crate1, ch);
105
  printf("Sense Voltage =  %f\n", ret);
106
 
107
//Test Reading the Current
108
  ret = getCurrentMeasurement(crate1, ch);
109
  printf("Current Measurement =  %f\n", ret);
110
 
111
  printf("Turning channel %i ON\n", ch);
112
  setChannelSwitch(crate1, ch, 1);
113
  Delay(1);
114
 
115
//Test Channel Status
116
  iret=getChannelSwitch(crate1, ch);
117
  printf("Channel Status %i = %i\n", ch, iret);
118
 
119
//Test Reading the Sense Measurement
120
  ret = getOutputSenseMeasurement(crate1, ch);
121
  printf("Sense Voltage =  %f\n", ret);
122
 
123
//Test Reading the Current
124
  ret = getCurrentMeasurement(crate1, ch);
125
  printf("Current Measurement =  %f\n", ret);
126
 
127
  getchar();
128
 
129
  printf("Turning channel %i OFF\n", ch);
130
  setChannelSwitch(crate1, ch, 0);
131
 
132
  printf("-----------------------------------------------------------------\n");
133
 
154 f9daq 134
  Delay(1);
135
 
136
  MPOD_Close(0);
137
  MPOD_End();
151 f9daq 138
 
139
  return 0;
140
}
154 f9daq 141
 
142
#endif /* MPOD_MAIN */