Преглед на файлове

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 години
родител
ревизия
7d80bd83c6
променени са 2 файла, в които са добавени 54 реда и са изтрити 2 реда
  1. 25
    2
      pdbuddy/__init__.py
  2. 29
    0
      test_pdbuddy/__init__.py

+ 25
- 2
pdbuddy/__init__.py Целия файл

@@ -174,6 +174,22 @@ class Sink:
174 174
         if len(out):
175 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 193
     def identify(self):
178 194
         """Blinks the LED quickly"""
179 195
         self.send_command("identify")
@@ -225,8 +241,15 @@ class Sink:
225 241
         # Set voltage range
226 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 254
     @classmethod
232 255
     def get_devices(cls):

+ 29
- 0
test_pdbuddy/__init__.py Целия файл

@@ -25,6 +25,12 @@ class SinkTestCase(unittest.TestCase):
25 25
         self.obj_range = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
26 26
                 flags=pdbuddy.SinkFlags.HV_PREFERRED, v=13800, vmin=12000,
27 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 35
         self.obj_huge_v = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
30 36
                 flags=pdbuddy.SinkFlags.NONE, v=65536, vmin=None, vmax=None,
@@ -50,6 +56,13 @@ class SinkTestCase(unittest.TestCase):
50 56
                 flags=pdbuddy.SinkFlags.NONE, v=5000, vmin=None, vmax=None,
51 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 66
     def tearDown(self):
54 67
         # Close the connection to the PD Buddy Sink
55 68
         self.pdbs.close()
@@ -79,6 +92,14 @@ class SinkTestCase(unittest.TestCase):
79 92
         self.pdbs.set_tmpcfg(self.obj_range)
80 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 103
     def test_set_tmpcfg_huge_v(self):
83 104
         with self.assertRaises(ValueError):
84 105
             self.pdbs.set_tmpcfg(self.obj_huge_v)
@@ -107,6 +128,14 @@ class SinkTestCase(unittest.TestCase):
107 128
         with self.assertRaises(ValueError):
108 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 139
     def test_write(self):
111 140
         self.test_set_tmpcfg_valid()
112 141
         self.pdbs.write()

Loading…
Отказ
Запис