My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
CbassPowerSupply.h
1 #ifndef GCP_UTIL_CBASSPOWERSUPPLY_H
2 #define GCP_UTIL_CBASSPOWERSUPPLY_H
3 
4 /*
5  * CbassPowerDupply.h
6  * cbass_interface
7  *
8  * Created by Stephen Muchovej on 10.12.2010
9  *
10  */
11 
12 #include <iostream>
13 #include <math.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <termios.h>
17 
18 #include <vector>
19 
20 #include "gcp/util/common/Directives.h"
21 #include "gcp/util/common/FdSet.h"
22 
23 #if DIR_HAVE_USB
24 #include "usb.h"
25 #endif
26 
27 #define PS_MAX_READ_BUF 128
28 #define BRATE B9600
29 #define PS_TIMEOUT_USEC 200000
30 #define PS_READ_ATTEMPTS_TIMEOUT 5
31 #define PS_SETVOLT_TIMEOUT 10
32 #define PS_BUF_LIMIT 'x'
33 #define PS_VOLT_STEPSIZE 0.02
34 #define PS_VOLT_GATE_ALLOW 0.03
35 #define PS_VOLT_CURRENT_ALLOW 0.03
36 #define PS_VOLT_WAIT 250 // ms
37 
38 
39 
40 // DU to voltage conversions
41 // Measured empirically, Sept 30, 2010.
42 #define PS_VOLT_M_GATE -0.002941 // volts/DU
43 #define PS_VOLT_B_GATE 0.6169 // volts
44 #define PS_VOLT_M_DRAIN 0.00982 // volts/DU
45 #define PS_VOLT_B_DRAIN 0.01089 // volts
46 #define PS_GAIN_M_CURRENT 0.0491 // mA/DU
47 #define PS_GAIN_B_CURRENT 0.1275 // mA
48 
49 const float drain_stepsize[6] = {3.914,5.180,7.789,3.924,5.185,7.777}; // DU/Step
50 const float current_stepsize[6] = {4.33,4.37,7.36,4.35,4.38,7.43}; // DU/Step
51 const float max_drainvolt[6] = {3.730,4.930,7.399,3.730,4.930,7.409}; // Volts
52 const float mindraincurrent_slope[6] = {0,0,0,0,0,0}; // mA/V
53 const float mindraincurrent_intercept[6] = {0,0,0,0,0,0}; // mA
54 const float maxdraincurrent_slope[6] = {4.74,4.67,4.61,4.66,4.58,4.64}; // mA/V
55 const float maxdraincurrent_intercept[6] = {0.046,0.14,0.14,0.076,0.084,0.19}; // mA
56 const int nonlin_current = 5; // DU
57 const int nonlin_gate = 145; // DU
58 
59 
60 namespace gcp {
61  namespace util {
62 
63  // Class to Communicate with the Power Supply
64 
66  public:
67 
72 
76  virtual ~CbassPowerSupply();
77 
78 
83 
84 
85 
89  bool connected_;
90 
94  bool queryBias_;
95 
99  int fd_;
100 
104  float retVal_;
105  char returnString_[PS_MAX_READ_BUF];
106  float volts_[3];
107  float allVolts_[36];
108 
112  void psConnect();
113 
117  void psDisconnect();
118 
122  int waitForResponse();
123 
124 
128  int psWrite(char* command);
129  int psWrite(char* command, int len);
130  // int psRead();
131  // int psRead2();
132  int readArduino();
133 
137  void psSetModule(char* modStage);
138  void psChangeVoltage(char* voltRequest);
139  void psGetVoltage();
140  void psGetVoltageOld();
141 
145  int psSetVoltage(int modsel, int stagesel, float gatevolt, float currvolt);
146  int psGetAllVoltages();
147 
151  enum Command {
152  INVALID ,
153  };
154 
158  int issueCommand(Command type);
159  int issueCommand(Command type, unsigned char address);
160  int issueCommand(Command type, unsigned char* period);
161  int issueCommand(Command type, unsigned char address, unsigned char* period);
162 
163  private:
164  void printBits(unsigned char feature);
165 
166  }; // End class CbassPowerSupply
167  }; // End namespace util
168 }; // End namespace gcp
169 #endif
CbassPowerSupply()
Definition: CbassPowerSupply.cc:32
Definition: Command.h:34
void psDisconnect()
Definition: CbassPowerSupply.cc:126
float retVal_
Definition: CbassPowerSupply.h:104
bool connected_
Definition: CbassPowerSupply.h:89
gcp::util::FdSet fdSet_
Definition: CbassPowerSupply.h:82
void psConnect()
Definition: CbassPowerSupply.cc:54
Definition: script.h:529
int psWrite(char *command)
Definition: CbassPowerSupply.cc:157
Definition: FdSet.h:16
int fd_
Definition: CbassPowerSupply.h:99
int psSetVoltage(int modsel, int stagesel, float gatevolt, float currvolt)
Definition: CbassPowerSupply.cc:661
bool queryBias_
Definition: CbassPowerSupply.h:94
int issueCommand(Command type)
void psSetModule(char *modStage)
Definition: CbassPowerSupply.cc:411
void psGetVoltage()
Definition: CbassPowerSupply.cc:601
int waitForResponse()
Definition: CbassPowerSupply.cc:1024
virtual ~CbassPowerSupply()
Definition: CbassPowerSupply.cc:43
Definition: CbassPowerSupply.h:65
int psGetAllVoltages()
Definition: CbassPowerSupply.cc:940
void psChangeVoltage(char *voltRequest)
Definition: CbassPowerSupply.cc:478