Browse Source

Added set_p and set_r methods

Along with full support for them in set_tmpcfg, and a bunch of test
cases.
Clara Hobbs 6 years ago
parent
commit
7d80bd83c6
2 changed files with 54 additions and 2 deletions
  1. 25
    2
      pdbuddy/__init__.py
  2. 29
    0
      test_pdbuddy/__init__.py

+ 25
- 2
pdbuddy/__init__.py View File

174
         if len(out):
174
         if len(out):
175
             raise ValueError(out[0])
175
             raise ValueError(out[0])
176
 
176
 
177
+    def set_p(self, mw):
178
+        """Sets the power of the configuration buffer, in milliwatts"""
179
+        out = self.send_command("set_p {}".format(mw))
180
+        # If that command gave any output, that indicates an error.  Raise an
181
+        # exception to make that clear.
182
+        if len(out):
183
+            raise ValueError(out[0])
184
+
185
+    def set_r(self, mr):
186
+        """Sets the resistance of the configuration buffer, in milliohms"""
187
+        out = self.send_command("set_r {}".format(mr))
188
+        # If that command gave any output, that indicates an error.  Raise an
189
+        # exception to make that clear.
190
+        if len(out):
191
+            raise ValueError(out[0])
192
+
177
     def identify(self):
193
     def identify(self):
178
         """Blinks the LED quickly"""
194
         """Blinks the LED quickly"""
179
         self.send_command("identify")
195
         self.send_command("identify")
225
         # Set voltage range
241
         # Set voltage range
226
         self.set_vrange(sc.vmin, sc.vmax)
242
         self.set_vrange(sc.vmin, sc.vmax)
227
         
243
         
228
-        # Set current
229
-        self.set_i(sc.i)
244
+        if sc.idim is SinkDimension.CURRENT:
245
+            # Set current
246
+            self.set_i(sc.i)
247
+        elif sc.idim is SinkDimension.POWER:
248
+            # Set power
249
+            self.set_p(sc.i)
250
+        elif sc.idim is SinkDimension.RESISTANCE:
251
+            # Set resistance
252
+            self.set_r(sc.i)
230
 
253
 
231
     @classmethod
254
     @classmethod
232
     def get_devices(cls):
255
     def get_devices(cls):

+ 29
- 0
test_pdbuddy/__init__.py View File

25
         self.obj_range = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
25
         self.obj_range = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
26
                 flags=pdbuddy.SinkFlags.HV_PREFERRED, v=13800, vmin=12000,
26
                 flags=pdbuddy.SinkFlags.HV_PREFERRED, v=13800, vmin=12000,
27
                 vmax=16000, i=2000, idim=pdbuddy.SinkDimension.CURRENT)
27
                 vmax=16000, i=2000, idim=pdbuddy.SinkDimension.CURRENT)
28
+        self.obj_valid_p = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
29
+                flags=pdbuddy.SinkFlags.NONE, v=15000, vmin=None, vmax=None,
30
+                i=35000, idim=pdbuddy.SinkDimension.POWER)
31
+        self.obj_valid_r = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
32
+                flags=pdbuddy.SinkFlags.NONE, v=15000, vmin=None, vmax=None,
33
+                i=10000, idim=pdbuddy.SinkDimension.RESISTANCE)
28
 
34
 
29
         self.obj_huge_v = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
35
         self.obj_huge_v = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
30
                 flags=pdbuddy.SinkFlags.NONE, v=65536, vmin=None, vmax=None,
36
                 flags=pdbuddy.SinkFlags.NONE, v=65536, vmin=None, vmax=None,
50
                 flags=pdbuddy.SinkFlags.NONE, v=5000, vmin=None, vmax=None,
56
                 flags=pdbuddy.SinkFlags.NONE, v=5000, vmin=None, vmax=None,
51
                 i=-1, idim=pdbuddy.SinkDimension.CURRENT)
57
                 i=-1, idim=pdbuddy.SinkDimension.CURRENT)
52
 
58
 
59
+        self.obj_neg_p = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
60
+                flags=pdbuddy.SinkFlags.NONE, v=15000, vmin=None, vmax=None,
61
+                i=-1, idim=pdbuddy.SinkDimension.POWER)
62
+        self.obj_neg_r = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
63
+                flags=pdbuddy.SinkFlags.NONE, v=15000, vmin=None, vmax=None,
64
+                i=-1, idim=pdbuddy.SinkDimension.RESISTANCE)
65
+
53
     def tearDown(self):
66
     def tearDown(self):
54
         # Close the connection to the PD Buddy Sink
67
         # Close the connection to the PD Buddy Sink
55
         self.pdbs.close()
68
         self.pdbs.close()
79
         self.pdbs.set_tmpcfg(self.obj_range)
92
         self.pdbs.set_tmpcfg(self.obj_range)
80
         self.assertEqual(self.pdbs.get_tmpcfg(), self.obj_range)
93
         self.assertEqual(self.pdbs.get_tmpcfg(), self.obj_range)
81
 
94
 
95
+    def test_set_tmpcfg_valid_p(self):
96
+        self.pdbs.set_tmpcfg(self.obj_valid_p)
97
+        self.assertEqual(self.pdbs.get_tmpcfg(), self.obj_valid_p)
98
+
99
+    def test_set_tmpcfg_valid_r(self):
100
+        self.pdbs.set_tmpcfg(self.obj_valid_r)
101
+        self.assertEqual(self.pdbs.get_tmpcfg(), self.obj_valid_r)
102
+
82
     def test_set_tmpcfg_huge_v(self):
103
     def test_set_tmpcfg_huge_v(self):
83
         with self.assertRaises(ValueError):
104
         with self.assertRaises(ValueError):
84
             self.pdbs.set_tmpcfg(self.obj_huge_v)
105
             self.pdbs.set_tmpcfg(self.obj_huge_v)
107
         with self.assertRaises(ValueError):
128
         with self.assertRaises(ValueError):
108
             self.pdbs.set_tmpcfg(self.obj_neg_i)
129
             self.pdbs.set_tmpcfg(self.obj_neg_i)
109
 
130
 
131
+    def test_set_tmpcfg_neg_p(self):
132
+        with self.assertRaises(ValueError):
133
+            self.pdbs.set_tmpcfg(self.obj_neg_p)
134
+
135
+    def test_set_tmpcfg_neg_r(self):
136
+        with self.assertRaises(ValueError):
137
+            self.pdbs.set_tmpcfg(self.obj_neg_r)
138
+
110
     def test_write(self):
139
     def test_write(self):
111
         self.test_set_tmpcfg_valid()
140
         self.test_set_tmpcfg_valid()
112
         self.pdbs.write()
141
         self.pdbs.write()

Loading…
Cancel
Save