pvblocks 0.0.1__py3-none-any.whl → 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pvblocks might be problematic. Click here for more details.

pvblocks/__init__.py CHANGED
@@ -1,2 +1,2 @@
1
- VERSION = '0.0.1'
1
+ VERSION = '0.0.2'
2
2
  __version__ = VERSION
pvblocks/constants.py CHANGED
@@ -30,3 +30,13 @@ class Rr1700Command(IntEnum):
30
30
  BroadcastThresholdExceeded = 111,
31
31
  CurveRunning = 250
32
32
 
33
+ class Rr1700Function(IntEnum):
34
+ IvMppReadIVPoint = 20,
35
+ IvMppApplyState = 21,
36
+ PvIrrReadIrradiances = 30
37
+
38
+ class IvMppState(IntEnum):
39
+ Voc = 0,
40
+ Isc = 1,
41
+ Mpp = 2,
42
+ VoltageBias = 3
pvblocks/exceptions.py CHANGED
@@ -18,5 +18,19 @@ class NoReadDataImplementedException(Exception):
18
18
  class CannotOpenBlockException(Exception):
19
19
  '''Cannot open PVBlock.'''
20
20
 
21
+ def __str__(self):
22
+ return self.__doc__
23
+
24
+
25
+ class MethodNotSupportedException(Exception):
26
+ '''Method not supported for PVBlock.'''
27
+
28
+ def __str__(self):
29
+ return self.__doc__
30
+
31
+
32
+ class PvBlocksIsNoneException(Exception):
33
+ '''PVBlock is None'''
34
+
21
35
  def __str__(self):
22
36
  return self.__doc__
@@ -3,7 +3,10 @@ from . import exceptions
3
3
  from . import constants
4
4
  import serial
5
5
  import uuid
6
+ import struct
6
7
  from time import sleep
8
+ from enum import IntEnum
9
+
7
10
 
8
11
 
9
12
  def show_version():
@@ -21,7 +24,8 @@ class PvBlocks(object):
21
24
  TYPES = {
22
25
  20: 'IV/MPP IV-Curve control and measure PvBlock',
23
26
  30: 'PV-IRR 4x analog voltage readout block',
24
- 40: 'PV-TEMP 4x Pt100 readout block'
27
+ 40: 'PV-TEMP 4x Pt100 readout block',
28
+ 50: 'PV-MOD digital modbus module'
25
29
  }
26
30
 
27
31
  def __init__(self, serialport):
@@ -32,6 +36,9 @@ class PvBlocks(object):
32
36
  parity=serial.PARITY_NONE,
33
37
  stopbits=serial.STOPBITS_ONE,
34
38
  timeout=1)
39
+ self.Blocks = []
40
+ self.IvMppBlocks = []
41
+ self.PvIrrBlocks = []
35
42
 
36
43
  def init_system(self):
37
44
  self.uart.write(serial.to_bytes([1, constants.Rr1700Command.Alive]))
@@ -41,7 +48,12 @@ class PvBlocks(object):
41
48
  raise exceptions.NoResponseException()
42
49
  return bts[0] == 3 and bts[1] == constants.Rr1700Command.Alive
43
50
 
44
- def scanblocks(self):
51
+
52
+ def close_system(self):
53
+ self.uart.close()
54
+
55
+
56
+ def scan_blocks(self):
45
57
  self.uart.write(serial.to_bytes([1, constants.Rr1700Command.ListModules]))
46
58
  sleep(2)
47
59
  bts = ReadSerial(self.uart)
@@ -51,57 +63,30 @@ class PvBlocks(object):
51
63
 
52
64
  module_count = bts[3]
53
65
  self.Blocks = []
66
+ self.IvMppBlocks = []
67
+ self.PvIrrBlocks = []
54
68
  for index in range(module_count):
55
- blck = PvBlock(bts[(index * 9) + 4: (index * 9) + 13])
56
- self.Blocks.append(blck)
57
-
58
- return module_count > 0
69
+ match bts[(index * 9) + 4 + 8]:
70
+ case 20:
71
+ blck = IvMpp(bts[(index * 9) + 4: (index * 9) + 13], self.uart)
72
+ self.IvMppBlocks.append(blck)
73
+ case 30:
74
+ blck = PvIrr(bts[(index * 9) + 4: (index * 9) + 13], self.uart)
75
+ self.PvIrrBlocks.append(blck)
76
+ case _:
77
+ blck = PvBlock(bts[(index * 9) + 4: (index * 9) + 13], self.uart)
78
+ self.Blocks.append(blck)
59
79
 
60
- def open_block(self, pvblock):
61
- self.uart.write(serial.to_bytes([1,
62
- constants.Rr1700Command.OpenModule,
63
- 0,
64
- pvblock.bytes[0],
65
- pvblock.bytes[1],
66
- pvblock.bytes[2],
67
- pvblock.bytes[3],
68
- pvblock.bytes[4],
69
- pvblock.bytes[5],
70
- pvblock.bytes[6],
71
- pvblock.bytes[7]]))
72
- sleep(0.5)
73
- bts = ReadSerial(self.uart)
74
-
75
- return len(bts) == 3
76
80
 
77
- def close_block(self, pvblock):
78
- self.uart.write(serial.to_bytes([1,
79
- constants.Rr1700Command.CloseModule,
80
- pvblock.bytes[0],
81
- pvblock.bytes[1],
82
- pvblock.bytes[2],
83
- pvblock.bytes[3],
84
- pvblock.bytes[4],
85
- pvblock.bytes[5],
86
- pvblock.bytes[6],
87
- pvblock.bytes[7]]))
88
- sleep(0.5)
89
- bts = ReadSerial(self.uart)
81
+ return module_count > 0
90
82
 
91
- return len(bts) == 3
83
+ def reset_controller(self):
84
+ if not self.uart.is_open:
85
+ self.uart.open()
92
86
 
93
- def read_data(self, pvblock):
94
- try:
95
- if pvblock.Type == 20:
96
- return self.read_ivpoint(pvblock)
97
- if pvblock.Type == 30:
98
- return self.read_irradiances(pvblock)
99
- except:
100
- print("Exception raised")
101
- finally:
102
- self.close_block(pvblock)
87
+ self.uart.write(serial.to_bytes([1, constants.Rr1700Command.ResetController]))
88
+ sleep(3)
103
89
 
104
- raise exceptions.NoReadDataImplementedException()
105
90
 
106
91
  def read_irradiances(self, pvblock):
107
92
  if self.open_block(pvblock):
@@ -126,13 +111,242 @@ class PvBlocks(object):
126
111
 
127
112
  return (0, 0, 0, 0)
128
113
 
129
- def read_ivpoint(self, pvblock):
130
- return (0, 0)
114
+
115
+
131
116
 
132
117
 
133
118
  class PvBlock(object):
134
- def __init__(self, bytes):
119
+ def __init__(self, bytes, uart):
135
120
  self.bytes = bytes[0:8]
136
121
  id = int.from_bytes(bytearray(self.bytes), 'little')
137
122
  self.Guid = uuid.UUID(int=id)
138
123
  self.Type = bytes[8]
124
+ self.uart = uart
125
+
126
+ def open(self):
127
+ self.uart.write(serial.to_bytes([1,
128
+ constants.Rr1700Command.OpenModule,
129
+ 0,
130
+ self.bytes[0],
131
+ self.bytes[1],
132
+ self.bytes[2],
133
+ self.bytes[3],
134
+ self.bytes[4],
135
+ self.bytes[5],
136
+ self.bytes[6],
137
+ self.bytes[7]]))
138
+ sleep(0.5)
139
+ bts = ReadSerial(self.uart)
140
+
141
+ return len(bts) == 3
142
+
143
+ def close(self):
144
+ self.uart.write(serial.to_bytes([1,
145
+ constants.Rr1700Command.CloseModule,
146
+ self.bytes[0],
147
+ self.bytes[1],
148
+ self.bytes[2],
149
+ self.bytes[3],
150
+ self.bytes[4],
151
+ self.bytes[5],
152
+ self.bytes[6],
153
+ self.bytes[7]]))
154
+ sleep(0.5)
155
+ bts = ReadSerial(self.uart)
156
+
157
+ return len(bts) == 3
158
+
159
+
160
+ def read_statusbyte(self):
161
+ self.open()
162
+ self.uart.write(serial.to_bytes([2, constants.Rr1700Command.GetStatus]))
163
+ sleep(0.5)
164
+ bts = ReadSerial(self.uart)
165
+ self.close()
166
+ if len(bts) < 10:
167
+ raise exceptions.UnexpectedResponseException()
168
+ return StatusByte(bts)
169
+
170
+ def get_info(self):
171
+ status = self.read_statusbyte()
172
+ d = {'firmware': status.firmware, 'hardware': status.hardware}
173
+ return d
174
+
175
+
176
+ class IvMpp(PvBlock):
177
+ def read_ivpoint(self):
178
+
179
+ self.open()
180
+ self.uart.write(serial.to_bytes([2, constants.Rr1700Command.ReadCommand]))
181
+ sleep(0.5)
182
+ bts = ReadSerial(self.uart)
183
+ self.close()
184
+ if len(bts) < 15:
185
+ raise exceptions.UnexpectedResponseException()
186
+
187
+ if bts[2] != 12:
188
+ raise exceptions.UnexpectedResponseException()
189
+
190
+ r1 = int.from_bytes(bts[3:7], "little") / 10000.0
191
+ r2 = int.from_bytes(bts[7:11], "little") / 100000.0
192
+ ivpoint = IvPoint(r1, r2)
193
+
194
+ return ivpoint
195
+
196
+ def ApplyVoc(self):
197
+ self.open()
198
+ self.uart.write(serial.to_bytes([2, constants.Rr1700Command.IdleCommand]))
199
+ sleep(0.5)
200
+ self.close()
201
+
202
+
203
+ def ApplyMpp(self):
204
+ self.open()
205
+ self.uart.write(serial.to_bytes([2, constants.Rr1700Command.MppCommand]))
206
+ sleep(0.5)
207
+ self.close()
208
+
209
+ def ApplyIsc(self):
210
+ voltage = 0.0;
211
+ self.open()
212
+ bytes = list(((int)(1000 * voltage)).to_bytes(4, "little"))
213
+ self.uart.write(serial.to_bytes([2, constants.Rr1700Command.VoltageCommand, bytes[0], bytes[1], bytes[2], bytes[3]]))
214
+ sleep(0.5)
215
+ self.close()
216
+
217
+ def ApplyVoltageBias(self, voltage):
218
+ self.open()
219
+ bytes = list(((int)(1000 * voltage)).to_bytes(4, "little"))
220
+ self.uart.write(
221
+ serial.to_bytes([2, constants.Rr1700Command.VoltageCommand, bytes[0], bytes[1], bytes[2], bytes[3]]))
222
+ sleep(0.5)
223
+ self.close()
224
+
225
+ def measure_ivcurve(self, points, delay_ms, sweepstyle):
226
+ self.open()
227
+
228
+ self.uart.write(
229
+ serial.to_bytes([2, constants.Rr1700Command.SetTriggerCommand, 0]))
230
+
231
+ sleep(0.5)
232
+
233
+ self.uart.write(
234
+ serial.to_bytes([2, constants.Rr1700Command.CurveCommand, points, delay_ms, 0, 0, 0, 0, sweepstyle]))
235
+
236
+ while self.uart.inWaiting() != 3:
237
+ sleep(0.01)
238
+
239
+ bts = ReadSerial(self.uart)
240
+
241
+ status = self.read_statusbyte()
242
+ while status.mode == 5:
243
+ sleep(0.5)
244
+ status = self.read_statusbyte()
245
+
246
+ self.close()
247
+
248
+ points_measured = status.statusbytes[0]
249
+ curve = self.transfer_curve(points_measured)
250
+
251
+ return curve
252
+
253
+ def transfer_curve(self, points):
254
+ self.open()
255
+ self.uart.write(serial.to_bytes([2, constants.Rr1700Command.TransferCurveCommand]))
256
+ sleep(0.5)
257
+ availablebytes = 8 + (points * 8) + 1
258
+ toread = self.uart.inWaiting()
259
+ while toread != availablebytes:
260
+ toread = self.uart.inWaiting()
261
+ print(toread)
262
+ sleep(0.1)
263
+ bts = ReadSerial(self.uart)
264
+ self.close()
265
+
266
+ voltages = []
267
+ currents = []
268
+
269
+
270
+ for i in range(int((availablebytes - 1)/8)):
271
+ index = (i * 8) + 1
272
+ voltages.append(int.from_bytes(bts[index:(index+4)], "little") / 10000.0)
273
+ index = index + 4
274
+ currents.append(int.from_bytes(bts[index:(index+4)], "little") / 100000.0)
275
+
276
+ return {'voltages': voltages, 'currents': currents}
277
+
278
+ def read_calibration(self):
279
+ c = {'A': 0.0, 'B': 0.0, 'C': 0.0, 'D': 0.0}
280
+ bts = self.read_eeprom(4, 16)
281
+ c['A'] = struct.unpack('<f', bytearray(bts[0:4]))
282
+ c['B'] = struct.unpack('<f', bytearray(bts[4:8]))
283
+ c['C'] = struct.unpack('<f', bytearray(bts[8:12]))
284
+ c['D'] = struct.unpack('<f', bytearray(bts[12:16]))
285
+
286
+ return c
287
+
288
+ def read_eeprom(self, address, length):
289
+ bts = list(address.to_bytes(2, 'little'))
290
+ self.open()
291
+ self.uart.write(
292
+ serial.to_bytes([2, constants.Rr1700Command.ReadEepromCommand, length, bts[0], bts[1]]))
293
+
294
+ while self.uart.inWaiting() != length + 3:
295
+ sleep(0.01)
296
+
297
+ bts = ReadSerial(self.uart)
298
+ self.close()
299
+ return bts[3:]
300
+
301
+
302
+ class PvIrr(PvBlock):
303
+
304
+ def ReadIrradiances(self):
305
+ self.open()
306
+ self.uart.write(serial.to_bytes([2, constants.Rr1700Command.ReadCommand]))
307
+ sleep(0.5)
308
+ bts = ReadSerial(self.uart)
309
+ if len(bts) < 10:
310
+ raise exceptions.UnexpectedResponseException()
311
+
312
+ irradiances = []
313
+
314
+ r1 = int.from_bytes(bts[3:7], "little") / 1000.0
315
+ r2 = int.from_bytes(bts[7:11], "little") / 1000.0
316
+ irradiances.append(r1)
317
+ irradiances.append(r2)
318
+ if bts[2] == 16:
319
+ r3 = int.from_bytes(bts[11:15], "little") / 1000.0
320
+ r4 = int.from_bytes(bts[15:19], "little") / 1000.0
321
+ irradiances.append(r3)
322
+ irradiances.append(r4)
323
+
324
+ self.close()
325
+ return irradiances
326
+
327
+ class StatusByte(object):
328
+ def __init__(self, bytes):
329
+ self.blocktype = bytes[2]
330
+ self.token = bytes[3]
331
+ self.mode = bytes[4]
332
+ self.statusbytes = bytes[5:]
333
+ self.firmware = bytes[9]
334
+ self.hardware = bytes[8]
335
+
336
+
337
+ class IvPoint(object):
338
+ def __init__(self, voltage, current):
339
+ self.voltage = voltage
340
+ self.current = current
341
+ self.power = voltage * current
342
+
343
+ def __str__(self):
344
+ return "(%f, %f)" % (self.voltage, self.current)
345
+
346
+
347
+ class SweepStyle(IntEnum):
348
+ ISC_TO_VOC = 0,
349
+ SWEEP_VOC_TO_ISC = 1,
350
+ EXTENT_CURVE_DELAY = 2,
351
+ SWEEP_VOC_ISC_VOC = 4,
352
+ SWEEP_ISC_VOC_ISC = 8
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: pvblocks
3
- Version: 0.0.1
3
+ Version: 0.1.0
4
4
  Summary: Python package to directly control pvblocks modules
5
5
  Author-email: Erik Haverkamp <erik@rera.nl>
6
6
  Project-URL: Homepage, https://github.com/rerasolutions/pvblocks-python
@@ -10,7 +10,12 @@ Classifier: Operating System :: OS Independent
10
10
  Requires-Python: >=3.8
11
11
  Description-Content-Type: text/markdown
12
12
  License-File: LICENSE
13
+ Dynamic: license-file
13
14
 
14
15
  ### pvblocks
15
16
 
16
17
  Package to control pvblocks modules directly
18
+
19
+ requires packages:
20
+
21
+ pyserial
@@ -0,0 +1,10 @@
1
+ pvblocks/__init__.py,sha256=S_4OBrHHm52POZt_Qij4obBhCqtqEVwFtZ734fSPZEY,40
2
+ pvblocks/__main__.py,sha256=fhvwtf6NzUeUsjP_ARtvxcmYjAvfwqz9_K1bHFwEjUg,84
3
+ pvblocks/constants.py,sha256=bvvk31fpjKb-oFyuEsq13jUmTc3xJ9OZxqIQ6ek28J8,1022
4
+ pvblocks/exceptions.py,sha256=we35JF-svaCDAFYqKFlDCp7ZwbCU0FQe7nksKpUfPnQ,850
5
+ pvblocks/pvblocks_system.py,sha256=frIG5r0VIUwkYkdhan-GJJWKUqytEfVnP2upbpEdoHE,11218
6
+ pvblocks-0.1.0.dist-info/licenses/LICENSE,sha256=8xnw0w04bL1ekO1BTZPbMkUbonvCNWVu6G6k4QIFRns,1091
7
+ pvblocks-0.1.0.dist-info/METADATA,sha256=WonJgm61yKOhITUDOnp7LYIGt__Kp2HMzDqmThI2hss,593
8
+ pvblocks-0.1.0.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
9
+ pvblocks-0.1.0.dist-info/top_level.txt,sha256=3jm7rpxZDuLfYKWbVj6i1IZJib2hTFVYxbsR68po7O8,9
10
+ pvblocks-0.1.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (72.1.0)
2
+ Generator: setuptools (80.3.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,10 +0,0 @@
1
- pvblocks/__init__.py,sha256=zcN732L9esRapW_Ntqw0NDmCJtHlHywlKzRPn8d2Rlg,40
2
- pvblocks/__main__.py,sha256=fhvwtf6NzUeUsjP_ARtvxcmYjAvfwqz9_K1bHFwEjUg,84
3
- pvblocks/constants.py,sha256=Wdp6NcBqOcEYjaz0PjKG0P8sh03zi6PAZdZD8WMHiMo,811
4
- pvblocks/exceptions.py,sha256=yCxzusmdwVpaoXA-NKEFODGqWa5S-umYCuL7WZ8sje8,570
5
- pvblocks/pvblocks_system.py,sha256=mQLmaliU7Xc_e90a4OCpcZQlLBF6h-XzC0bVUPYQBxw,4807
6
- pvblocks-0.0.1.dist-info/LICENSE,sha256=8xnw0w04bL1ekO1BTZPbMkUbonvCNWVu6G6k4QIFRns,1091
7
- pvblocks-0.0.1.dist-info/METADATA,sha256=-4KllHggt5l0t8Jv7leF18RnEZbmWdMTGq4VljX5rO4,536
8
- pvblocks-0.0.1.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
9
- pvblocks-0.0.1.dist-info/top_level.txt,sha256=3jm7rpxZDuLfYKWbVj6i1IZJib2hTFVYxbsR68po7O8,9
10
- pvblocks-0.0.1.dist-info/RECORD,,