pvblocks 0.0.1__tar.gz → 0.1.0__tar.gz

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.

@@ -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,7 @@
1
+ ### pvblocks
2
+
3
+ Package to control pvblocks modules directly
4
+
5
+ requires packages:
6
+
7
+ pyserial
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pvblocks"
3
- version = "0.0.1"
3
+ version = "0.1.0"
4
4
  authors = [
5
5
  { name="Erik Haverkamp", email="erik@rera.nl" },
6
6
  ]
@@ -0,0 +1,2 @@
1
+ VERSION = '0.0.2'
2
+ __version__ = VERSION
@@ -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
@@ -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__
@@ -0,0 +1,352 @@
1
+ from . import VERSION
2
+ from . import exceptions
3
+ from . import constants
4
+ import serial
5
+ import uuid
6
+ import struct
7
+ from time import sleep
8
+ from enum import IntEnum
9
+
10
+
11
+
12
+ def show_version():
13
+ return VERSION
14
+
15
+
16
+ def ReadSerial(ser):
17
+ out = []
18
+ while ser.inWaiting() > 0:
19
+ out.append(ser.read(1)[0])
20
+ return out
21
+
22
+
23
+ class PvBlocks(object):
24
+ TYPES = {
25
+ 20: 'IV/MPP IV-Curve control and measure PvBlock',
26
+ 30: 'PV-IRR 4x analog voltage readout block',
27
+ 40: 'PV-TEMP 4x Pt100 readout block',
28
+ 50: 'PV-MOD digital modbus module'
29
+ }
30
+
31
+ def __init__(self, serialport):
32
+ # type: (UART_Adapter) -> None
33
+ self.uart = serial.Serial(serialport,
34
+ baudrate=115200,
35
+ bytesize=serial.EIGHTBITS,
36
+ parity=serial.PARITY_NONE,
37
+ stopbits=serial.STOPBITS_ONE,
38
+ timeout=1)
39
+ self.Blocks = []
40
+ self.IvMppBlocks = []
41
+ self.PvIrrBlocks = []
42
+
43
+ def init_system(self):
44
+ self.uart.write(serial.to_bytes([1, constants.Rr1700Command.Alive]))
45
+ sleep(0.5)
46
+ bts = ReadSerial(self.uart)
47
+ if len(bts) != 2:
48
+ raise exceptions.NoResponseException()
49
+ return bts[0] == 3 and bts[1] == constants.Rr1700Command.Alive
50
+
51
+
52
+ def close_system(self):
53
+ self.uart.close()
54
+
55
+
56
+ def scan_blocks(self):
57
+ self.uart.write(serial.to_bytes([1, constants.Rr1700Command.ListModules]))
58
+ sleep(2)
59
+ bts = ReadSerial(self.uart)
60
+
61
+ if (bts[0] != 3) or (bts[1] != constants.Rr1700Command.ListModules):
62
+ raise exceptions.UnexpectedResponseException()
63
+
64
+ module_count = bts[3]
65
+ self.Blocks = []
66
+ self.IvMppBlocks = []
67
+ self.PvIrrBlocks = []
68
+ for index in range(module_count):
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)
79
+
80
+
81
+ return module_count > 0
82
+
83
+ def reset_controller(self):
84
+ if not self.uart.is_open:
85
+ self.uart.open()
86
+
87
+ self.uart.write(serial.to_bytes([1, constants.Rr1700Command.ResetController]))
88
+ sleep(3)
89
+
90
+
91
+ def read_irradiances(self, pvblock):
92
+ if self.open_block(pvblock):
93
+ self.uart.write(serial.to_bytes([2, constants.Rr1700Command.ReadCommand]))
94
+ sleep(0.5)
95
+ bts = ReadSerial(self.uart)
96
+ if len(bts) < 10:
97
+ raise exceptions.UnexpectedResponseException()
98
+
99
+ r1 = int.from_bytes(bts[3:7], "little") / 1000.0
100
+ r2 = int.from_bytes(bts[7:11], "little") / 1000.0
101
+ if bts[2] == 16:
102
+ r3 = int.from_bytes(bts[11:15], "little") / 1000.0
103
+ r4 = int.from_bytes(bts[15:19], "little") / 1000.0
104
+ return r1, r2, r3, r4
105
+ else:
106
+ return r1, r2
107
+
108
+
109
+ else:
110
+ raise exceptions.CannotOpenBlockException()
111
+
112
+ return (0, 0, 0, 0)
113
+
114
+
115
+
116
+
117
+
118
+ class PvBlock(object):
119
+ def __init__(self, bytes, uart):
120
+ self.bytes = bytes[0:8]
121
+ id = int.from_bytes(bytearray(self.bytes), 'little')
122
+ self.Guid = uuid.UUID(int=id)
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,42 @@
1
+ from pvblocks import pvblocks_system
2
+ from time import sleep
3
+
4
+ print("PV-Blocks version: " + pvblocks_system.show_version())
5
+
6
+ pvblocks = pvblocks_system.PvBlocks('COM16')
7
+
8
+
9
+ if pvblocks.init_system():
10
+ print("init ok")
11
+ else:
12
+ print("failed")
13
+
14
+ print("scanning available blocks")
15
+
16
+ if pvblocks.scan_blocks():
17
+ print("ok")
18
+ else:
19
+ print("failed")
20
+
21
+
22
+
23
+ iv_mpp = None
24
+
25
+ for b in pvblocks.Blocks:
26
+ print(pvblocks_system.PvBlocks.TYPES[b.Type])
27
+
28
+ for b in pvblocks.IvMppBlocks:
29
+ print(pvblocks_system.PvBlocks.TYPES[b.Type])
30
+
31
+ for b in pvblocks.PvIrrBlocks:
32
+ print(pvblocks_system.PvBlocks.TYPES[b.Type])
33
+
34
+ if len(pvblocks.IvMppBlocks) > 0:
35
+ iv_mpp = pvblocks.IvMppBlocks[0]
36
+
37
+ #print(iv_mpp.get_info())
38
+ ivpoint = iv_mpp.read_ivpoint()
39
+ print(ivpoint)
40
+ #curve = iv_mpp.MeasureIvCurve(100, 20, 0)
41
+
42
+ #pvblocks.close_system()
pvblocks-0.0.1/README.md DELETED
@@ -1,3 +0,0 @@
1
- ### pvblocks
2
-
3
- Package to control pvblocks modules directly
@@ -1,2 +0,0 @@
1
- VERSION = '0.0.1'
2
- __version__ = VERSION
@@ -1,138 +0,0 @@
1
- from . import VERSION
2
- from . import exceptions
3
- from . import constants
4
- import serial
5
- import uuid
6
- from time import sleep
7
-
8
-
9
- def show_version():
10
- return VERSION
11
-
12
-
13
- def ReadSerial(ser):
14
- out = []
15
- while ser.inWaiting() > 0:
16
- out.append(ser.read(1)[0])
17
- return out
18
-
19
-
20
- class PvBlocks(object):
21
- TYPES = {
22
- 20: 'IV/MPP IV-Curve control and measure PvBlock',
23
- 30: 'PV-IRR 4x analog voltage readout block',
24
- 40: 'PV-TEMP 4x Pt100 readout block'
25
- }
26
-
27
- def __init__(self, serialport):
28
- # type: (UART_Adapter) -> None
29
- self.uart = serial.Serial(serialport,
30
- baudrate=115200,
31
- bytesize=serial.EIGHTBITS,
32
- parity=serial.PARITY_NONE,
33
- stopbits=serial.STOPBITS_ONE,
34
- timeout=1)
35
-
36
- def init_system(self):
37
- self.uart.write(serial.to_bytes([1, constants.Rr1700Command.Alive]))
38
- sleep(0.5)
39
- bts = ReadSerial(self.uart)
40
- if len(bts) != 2:
41
- raise exceptions.NoResponseException()
42
- return bts[0] == 3 and bts[1] == constants.Rr1700Command.Alive
43
-
44
- def scanblocks(self):
45
- self.uart.write(serial.to_bytes([1, constants.Rr1700Command.ListModules]))
46
- sleep(2)
47
- bts = ReadSerial(self.uart)
48
-
49
- if (bts[0] != 3) or (bts[1] != constants.Rr1700Command.ListModules):
50
- raise exceptions.UnexpectedResponseException()
51
-
52
- module_count = bts[3]
53
- self.Blocks = []
54
- 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
59
-
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
-
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)
90
-
91
- return len(bts) == 3
92
-
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)
103
-
104
- raise exceptions.NoReadDataImplementedException()
105
-
106
- def read_irradiances(self, pvblock):
107
- if self.open_block(pvblock):
108
- self.uart.write(serial.to_bytes([2, constants.Rr1700Command.ReadCommand]))
109
- sleep(0.5)
110
- bts = ReadSerial(self.uart)
111
- if len(bts) < 10:
112
- raise exceptions.UnexpectedResponseException()
113
-
114
- r1 = int.from_bytes(bts[3:7], "little") / 1000.0
115
- r2 = int.from_bytes(bts[7:11], "little") / 1000.0
116
- if bts[2] == 16:
117
- r3 = int.from_bytes(bts[11:15], "little") / 1000.0
118
- r4 = int.from_bytes(bts[15:19], "little") / 1000.0
119
- return r1, r2, r3, r4
120
- else:
121
- return r1, r2
122
-
123
-
124
- else:
125
- raise exceptions.CannotOpenBlockException()
126
-
127
- return (0, 0, 0, 0)
128
-
129
- def read_ivpoint(self, pvblock):
130
- return (0, 0)
131
-
132
-
133
- class PvBlock(object):
134
- def __init__(self, bytes):
135
- self.bytes = bytes[0:8]
136
- id = int.from_bytes(bytearray(self.bytes), 'little')
137
- self.Guid = uuid.UUID(int=id)
138
- self.Type = bytes[8]
@@ -1,17 +0,0 @@
1
-
2
- from pvblocks_io_rera import pvblocks_system
3
-
4
- print(pvblocks_system.show_version())
5
-
6
- pvblock = pvblocks_system.PvBlocks('COM16')
7
-
8
-
9
- print(pvblock.init_system())
10
- print(pvblock.scanblocks())
11
-
12
- for b in pvblock.Blocks:
13
- print(b.Guid)
14
- print(pvblocks_system.PvBlocks.TYPES[b.Type])
15
-
16
- for b in pvblock.Blocks:
17
- print(pvblock.read_data(b))
File without changes
File without changes