pvblocks 0.0.1__py3-none-any.whl → 0.1.1__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'
2
- __version__ = VERSION
1
+ VERSION = '0.1.1'
2
+ __version__ = VERSION
pvblocks/constants.py CHANGED
@@ -1,32 +1,43 @@
1
- from enum import IntEnum
1
+ IDLE_COMMAND = 0
2
+ BLINK_COMMAND = 1
3
+ VOLTAGE_COMMAND = 2
4
+ MPP_COMMAND = 3
5
+ READ_COMMAND = 4
6
+ CURVE_COMMAND = 5
7
+ TRANSFER_CURVE_COMMAND = 6
8
+ EXTERNAL_MPP_COMMAND = 7
9
+ TRIGGERED_CURVE_COMMAND = 8
10
+ GET_STATUS = 13
11
+ WRITE_EEPROM_COMMAND = 14
12
+ SET_TRIGGER_COMMAND = 15
13
+ READ_EEPROM_COMMAND = 16
14
+ UPDATE_CONFIG_COMMAND = 17
15
+ GET_CONFIG_COMMAND = 18
16
+ START_FIRMWARE_UPDATE = 19
17
+ ENABLE_FAST_COMMUNICATIONS = 20
18
+ DISABLE_BROADCAST = 21
19
+ TRIGGERED_READ_COMMAND = 50
20
+ ALIVE = 100
21
+ LIST_MODULES = 101
22
+ OPEN_MODULE = 106
23
+ CLOSE_MODULE = 107
24
+ RESET_MODULE = 108
25
+ RESET_CONTROLLER = 109
26
+ TRIGGER_ALL = 110
27
+ BROADCAST_THRESHOLD_EXCEEDED = 111
28
+ CURVE_RUNNING = 250
2
29
 
3
- class Rr1700Command(IntEnum):
4
- IdleCommand = 0,
5
- BlinkCommand = 1,
6
- VoltageCommand = 2,
7
- MppCommand = 3,
8
- ReadCommand = 4,
9
- CurveCommand = 5,
10
- TransferCurveCommand = 6,
11
- ExternalMppCommand = 7,
12
- TriggeredCurveCommand = 8,
13
- GetStatus = 13,
14
- WriteEepromCommand = 14,
15
- SetTriggerCommand = 15,
16
- ReadEepromCommand = 16,
17
- UpdateConfigCommand = 17,
18
- GetConfigCommand = 18,
19
- StartFirmwareUpdate = 19,
20
- EnableFastCommunications = 20,
21
- DisableBroadcast = 21,
22
- TriggeredReadCommand = 50,
23
- Alive = 100,
24
- ListModules = 101,
25
- OpenModule = 106,
26
- CloseModule = 107,
27
- ResetModule = 108,
28
- ResetController = 109,
29
- TriggerAll = 110,
30
- BroadcastThresholdExceeded = 111,
31
- CurveRunning = 250
30
+ IVMPP_READ_IVPOINT = 20
31
+ IVMPP_APPLY_STATE = 21
32
+ PV_IRR_READ_IRRADIANCES = 30
32
33
 
34
+ VOC = 0
35
+ ISC = 1
36
+ MPP = 2
37
+ VOLTAGE_BIAS = 3
38
+
39
+ ISC_TO_VOC = 0,
40
+ SWEEP_VOC_TO_ISC = 1
41
+ EXTENT_CURVE_DELAY = 2
42
+ SWEEP_VOC_ISC_VOC = 4
43
+ SWEEP_ISC_VOC_ISC = 8
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,107 +36,283 @@ 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
- self.uart.write(serial.to_bytes([1, constants.Rr1700Command.Alive]))
44
+ self.uart.write(serial.to_bytes([1, constants.ALIVE]))
38
45
  sleep(0.5)
39
46
  bts = ReadSerial(self.uart)
40
47
  if len(bts) != 2:
41
48
  raise exceptions.NoResponseException()
42
- return bts[0] == 3 and bts[1] == constants.Rr1700Command.Alive
49
+ return bts[0] == 3 and bts[1] == constants.ALIVE
50
+
51
+
52
+ def close_system(self):
53
+ self.uart.close()
54
+
43
55
 
44
- def scanblocks(self):
45
- self.uart.write(serial.to_bytes([1, constants.Rr1700Command.ListModules]))
56
+ def scan_blocks(self):
57
+ self.uart.write(serial.to_bytes([1, constants.LIST_MODULES]))
46
58
  sleep(2)
47
59
  bts = ReadSerial(self.uart)
48
60
 
49
- if (bts[0] != 3) or (bts[1] != constants.Rr1700Command.ListModules):
61
+ if (bts[0] != 3) or (bts[1] != constants.LIST_MODULES):
50
62
  raise exceptions.UnexpectedResponseException()
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)
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
+
57
80
 
58
81
  return module_count > 0
59
82
 
60
- def open_block(self, pvblock):
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.RESET_CONTROLLER]))
88
+ sleep(3)
89
+
90
+
91
+ class PvBlock(object):
92
+ def __init__(self, bytes, uart):
93
+ self.bytes = bytes[0:8]
94
+ id = int.from_bytes(bytearray(self.bytes), 'little')
95
+ self.Guid = uuid.UUID(int=id)
96
+ self.Type = bytes[8]
97
+ self.uart = uart
98
+
99
+ def open(self):
61
100
  self.uart.write(serial.to_bytes([1,
62
- constants.Rr1700Command.OpenModule,
101
+ constants.OPEN_MODULE,
63
102
  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]]))
103
+ self.bytes[0],
104
+ self.bytes[1],
105
+ self.bytes[2],
106
+ self.bytes[3],
107
+ self.bytes[4],
108
+ self.bytes[5],
109
+ self.bytes[6],
110
+ self.bytes[7]]))
72
111
  sleep(0.5)
73
112
  bts = ReadSerial(self.uart)
74
113
 
75
114
  return len(bts) == 3
76
115
 
77
- def close_block(self, pvblock):
116
+ def close(self):
78
117
  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]]))
118
+ constants.CLOSE_MODULE,
119
+ self.bytes[0],
120
+ self.bytes[1],
121
+ self.bytes[2],
122
+ self.bytes[3],
123
+ self.bytes[4],
124
+ self.bytes[5],
125
+ self.bytes[6],
126
+ self.bytes[7]]))
88
127
  sleep(0.5)
89
128
  bts = ReadSerial(self.uart)
90
129
 
91
130
  return len(bts) == 3
92
131
 
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]))
132
+
133
+ def read_statusbyte(self):
134
+ self.open()
135
+ self.uart.write(serial.to_bytes([2, constants.GET_STATUS]))
136
+ sleep(0.5)
137
+ bts = ReadSerial(self.uart)
138
+ self.close()
139
+ if len(bts) < 10:
140
+ raise exceptions.UnexpectedResponseException()
141
+ return StatusByte(bts)
142
+
143
+ def get_info(self):
144
+ status = self.read_statusbyte()
145
+ d = {'firmware': status.firmware, 'hardware': status.hardware}
146
+ return d
147
+
148
+
149
+ class IvMpp(PvBlock):
150
+ def read_ivpoint(self):
151
+
152
+ self.open()
153
+ self.uart.write(serial.to_bytes([2, constants.READ_COMMAND]))
154
+ sleep(0.5)
155
+ bts = ReadSerial(self.uart)
156
+ self.close()
157
+ if len(bts) < 15:
158
+ raise exceptions.UnexpectedResponseException()
159
+
160
+ if bts[2] != 12:
161
+ raise exceptions.UnexpectedResponseException()
162
+
163
+ r1 = int.from_bytes(bts[3:7], "little") / 10000.0
164
+ r2 = int.from_bytes(bts[7:11], "little") / 100000.0
165
+ ivpoint = IvPoint(r1, r2)
166
+
167
+ return ivpoint
168
+
169
+ def ApplyVoc(self):
170
+ self.open()
171
+ self.uart.write(serial.to_bytes([2, constants.IDLE_COMMAND]))
172
+ sleep(0.5)
173
+ self.close()
174
+
175
+
176
+ def ApplyMpp(self):
177
+ self.open()
178
+ self.uart.write(serial.to_bytes([2, constants.MPP_COMMAND]))
179
+ sleep(0.5)
180
+ self.close()
181
+
182
+ def ApplyIsc(self):
183
+ voltage = 0.0;
184
+ self.open()
185
+ bytes = list(((int)(1000 * voltage)).to_bytes(4, "little"))
186
+ self.uart.write(serial.to_bytes([2, constants.Rr1700Command.VoltageCommand, bytes[0], bytes[1], bytes[2], bytes[3]]))
187
+ sleep(0.5)
188
+ self.close()
189
+
190
+ def ApplyVoltageBias(self, voltage):
191
+ self.open()
192
+ bytes = list(((int)(1000 * voltage)).to_bytes(4, "little"))
193
+ self.uart.write(
194
+ serial.to_bytes([2, constants.Rr1700Command.VoltageCommand, bytes[0], bytes[1], bytes[2], bytes[3]]))
195
+ sleep(0.5)
196
+ self.close()
197
+
198
+ def measure_ivcurve(self, points, delay_ms, sweepstyle):
199
+ self.open()
200
+
201
+ self.uart.write(
202
+ serial.to_bytes([2, constants.SET_TRIGGER_COMMAND, 0]))
203
+
204
+ sleep(0.5)
205
+
206
+ self.uart.write(
207
+ serial.to_bytes([2, constants.CURVE_COMMAND, points, delay_ms, 0, 0, 0, 0, sweepstyle]))
208
+
209
+ while self.uart.inWaiting() != 3:
210
+ sleep(0.01)
211
+
212
+ bts = ReadSerial(self.uart)
213
+
214
+ status = self.read_statusbyte()
215
+ while status.mode == 5:
109
216
  sleep(0.5)
110
- bts = ReadSerial(self.uart)
111
- if len(bts) < 10:
112
- raise exceptions.UnexpectedResponseException()
217
+ status = self.read_statusbyte()
113
218
 
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
219
+ self.close()
122
220
 
221
+ points_measured = status.statusbytes[0]
222
+ curve = self.transfer_curve(points_measured)
123
223
 
124
- else:
125
- raise exceptions.CannotOpenBlockException()
224
+ return curve
126
225
 
127
- return (0, 0, 0, 0)
226
+ def transfer_curve(self, points):
227
+ self.open()
228
+ self.uart.write(serial.to_bytes([2, constants.TRANSFER_CURVE_COMMAND]))
229
+ sleep(0.5)
230
+ availablebytes = 8 + (points * 8) + 1
231
+ toread = self.uart.inWaiting()
232
+ while toread != availablebytes:
233
+ toread = self.uart.inWaiting()
234
+ print(toread)
235
+ sleep(0.1)
236
+ bts = ReadSerial(self.uart)
237
+ self.close()
128
238
 
129
- def read_ivpoint(self, pvblock):
130
- return (0, 0)
239
+ voltages = []
240
+ currents = []
131
241
 
242
+ print(availablebytes)
243
+ for i in range(1, int((availablebytes - 1)/8)):
244
+ index = (i * 8) + 1
245
+ voltages.append(int.from_bytes(bts[index:(index+4)], "little") / 10000.0)
246
+ index = index + 4
247
+ currents.append(int.from_bytes(bts[index:(index+4)], "little") / 100000.0)
132
248
 
133
- class PvBlock(object):
249
+ return {'voltages': voltages, 'currents': currents}
250
+
251
+ def read_calibration(self):
252
+ c = {'A': 0.0, 'B': 0.0, 'C': 0.0, 'D': 0.0}
253
+ bts = self.read_eeprom(4, 16)
254
+ c['A'] = struct.unpack('<f', bytearray(bts[0:4]))
255
+ c['B'] = struct.unpack('<f', bytearray(bts[4:8]))
256
+ c['C'] = struct.unpack('<f', bytearray(bts[8:12]))
257
+ c['D'] = struct.unpack('<f', bytearray(bts[12:16]))
258
+
259
+ return c
260
+
261
+ def read_eeprom(self, address, length):
262
+ bts = list(address.to_bytes(2, 'little'))
263
+ self.open()
264
+ self.uart.write(
265
+ serial.to_bytes([2, constants.READ_EEPROM_COMMAND, length, bts[0], bts[1]]))
266
+
267
+ while self.uart.inWaiting() != length + 3:
268
+ sleep(0.01)
269
+
270
+ bts = ReadSerial(self.uart)
271
+ self.close()
272
+ return bts[3:]
273
+
274
+
275
+ class PvIrr(PvBlock):
276
+
277
+ def ReadIrradiances(self):
278
+ self.open()
279
+ self.uart.write(serial.to_bytes([2, constants.READ_COMMAND]))
280
+ sleep(0.5)
281
+ bts = ReadSerial(self.uart)
282
+ if len(bts) < 10:
283
+ raise exceptions.UnexpectedResponseException()
284
+
285
+ irradiances = []
286
+
287
+ r1 = int.from_bytes(bts[3:7], "little") / 1000.0
288
+ r2 = int.from_bytes(bts[7:11], "little") / 1000.0
289
+ irradiances.append(r1)
290
+ irradiances.append(r2)
291
+ if bts[2] == 16:
292
+ r3 = int.from_bytes(bts[11:15], "little") / 1000.0
293
+ r4 = int.from_bytes(bts[15:19], "little") / 1000.0
294
+ irradiances.append(r3)
295
+ irradiances.append(r4)
296
+
297
+ self.close()
298
+ return irradiances
299
+
300
+ class StatusByte(object):
134
301
  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]
302
+ self.blocktype = bytes[2]
303
+ self.token = bytes[3]
304
+ self.mode = bytes[4]
305
+ self.statusbytes = bytes[5:]
306
+ self.firmware = bytes[9]
307
+ self.hardware = bytes[8]
308
+
309
+
310
+ class IvPoint(object):
311
+ def __init__(self, voltage, current):
312
+ self.voltage = voltage
313
+ self.current = current
314
+ self.power = voltage * current
315
+
316
+ def __str__(self):
317
+ return "(%f, %f)" % (self.voltage, self.current)
318
+
@@ -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.1
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=IIowXUr-xAaZCUhjyVsp1GPDlYaCN8kOX_OZ0i2mWnA,42
2
+ pvblocks/__main__.py,sha256=fhvwtf6NzUeUsjP_ARtvxcmYjAvfwqz9_K1bHFwEjUg,84
3
+ pvblocks/constants.py,sha256=MzQ_7Kgmks8F7KqRwEsGIdkFzP5pubjJzfxgbtwFvGk,889
4
+ pvblocks/exceptions.py,sha256=we35JF-svaCDAFYqKFlDCp7ZwbCU0FQe7nksKpUfPnQ,850
5
+ pvblocks/pvblocks_system.py,sha256=zrxS6_3v2OiQMuSqSGBTNBQhk61ZfxDcnHdpgj-6fZE,10056
6
+ pvblocks-0.1.1.dist-info/licenses/LICENSE,sha256=8xnw0w04bL1ekO1BTZPbMkUbonvCNWVu6G6k4QIFRns,1091
7
+ pvblocks-0.1.1.dist-info/METADATA,sha256=HLzD4VMcfEa5p6s0ZN5W6NLo4PxEKbIwuz7Bk8BDXmU,593
8
+ pvblocks-0.1.1.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
9
+ pvblocks-0.1.1.dist-info/top_level.txt,sha256=3jm7rpxZDuLfYKWbVj6i1IZJib2hTFVYxbsR68po7O8,9
10
+ pvblocks-0.1.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (72.1.0)
2
+ Generator: setuptools (80.4.0)
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,,