pvblocks 0.0.1__tar.gz → 0.1.1__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.
- {pvblocks-0.0.1 → pvblocks-0.1.1}/PKG-INFO +7 -2
- pvblocks-0.1.1/README.md +7 -0
- {pvblocks-0.0.1 → pvblocks-0.1.1}/pyproject.toml +1 -1
- pvblocks-0.1.1/src/pvblocks/__init__.py +2 -0
- pvblocks-0.1.1/src/pvblocks/constants.py +43 -0
- {pvblocks-0.0.1 → pvblocks-0.1.1}/src/pvblocks/exceptions.py +14 -0
- pvblocks-0.1.1/src/pvblocks/pvblocks_system.py +318 -0
- {pvblocks-0.0.1 → pvblocks-0.1.1}/src/pvblocks.egg-info/PKG-INFO +7 -2
- pvblocks-0.1.1/tests/test.py +42 -0
- pvblocks-0.0.1/README.md +0 -3
- pvblocks-0.0.1/src/pvblocks/__init__.py +0 -2
- pvblocks-0.0.1/src/pvblocks/constants.py +0 -32
- pvblocks-0.0.1/src/pvblocks/pvblocks_system.py +0 -138
- pvblocks-0.0.1/tests/test.py +0 -17
- {pvblocks-0.0.1 → pvblocks-0.1.1}/LICENSE +0 -0
- {pvblocks-0.0.1 → pvblocks-0.1.1}/setup.cfg +0 -0
- {pvblocks-0.0.1 → pvblocks-0.1.1}/src/pvblocks/__main__.py +0 -0
- {pvblocks-0.0.1 → pvblocks-0.1.1}/src/pvblocks.egg-info/SOURCES.txt +0 -0
- {pvblocks-0.0.1 → pvblocks-0.1.1}/src/pvblocks.egg-info/dependency_links.txt +0 -0
- {pvblocks-0.0.1 → pvblocks-0.1.1}/src/pvblocks.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: pvblocks
|
|
3
|
-
Version: 0.
|
|
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
|
pvblocks-0.1.1/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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
|
|
29
|
+
|
|
30
|
+
IVMPP_READ_IVPOINT = 20
|
|
31
|
+
IVMPP_APPLY_STATE = 21
|
|
32
|
+
PV_IRR_READ_IRRADIANCES = 30
|
|
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
|
|
@@ -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,318 @@
|
|
|
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.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.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.LIST_MODULES]))
|
|
58
|
+
sleep(2)
|
|
59
|
+
bts = ReadSerial(self.uart)
|
|
60
|
+
|
|
61
|
+
if (bts[0] != 3) or (bts[1] != constants.LIST_MODULES):
|
|
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.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):
|
|
100
|
+
self.uart.write(serial.to_bytes([1,
|
|
101
|
+
constants.OPEN_MODULE,
|
|
102
|
+
0,
|
|
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]]))
|
|
111
|
+
sleep(0.5)
|
|
112
|
+
bts = ReadSerial(self.uart)
|
|
113
|
+
|
|
114
|
+
return len(bts) == 3
|
|
115
|
+
|
|
116
|
+
def close(self):
|
|
117
|
+
self.uart.write(serial.to_bytes([1,
|
|
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]]))
|
|
127
|
+
sleep(0.5)
|
|
128
|
+
bts = ReadSerial(self.uart)
|
|
129
|
+
|
|
130
|
+
return len(bts) == 3
|
|
131
|
+
|
|
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:
|
|
216
|
+
sleep(0.5)
|
|
217
|
+
status = self.read_statusbyte()
|
|
218
|
+
|
|
219
|
+
self.close()
|
|
220
|
+
|
|
221
|
+
points_measured = status.statusbytes[0]
|
|
222
|
+
curve = self.transfer_curve(points_measured)
|
|
223
|
+
|
|
224
|
+
return curve
|
|
225
|
+
|
|
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()
|
|
238
|
+
|
|
239
|
+
voltages = []
|
|
240
|
+
currents = []
|
|
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)
|
|
248
|
+
|
|
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):
|
|
301
|
+
def __init__(self, bytes):
|
|
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
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: pvblocks
|
|
3
|
-
Version: 0.
|
|
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,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.measure_ivcurve(100, 20, 0)
|
|
41
|
+
|
|
42
|
+
pvblocks.close_system()
|
pvblocks-0.0.1/README.md
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
from enum import IntEnum
|
|
2
|
-
|
|
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
|
|
32
|
-
|
|
@@ -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]
|
pvblocks-0.0.1/tests/test.py
DELETED
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|