Skip to content

Commit f1440f6

Browse files
committed
1.2.11 voltage byte packing fix
1 parent 4f60f54 commit f1440f6

4 files changed

Lines changed: 16 additions & 16 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "BS1200_driver"
3-
version = "1.2.10"
3+
version = "1.2.11"
44
authors = [{ name = "Mikhail Kharitonov", email = "mikhail.kharitonov@bloomy.com"}]
55
description= "Python interface to the Bloomy BS1200"
66
readme = "README.md"

src/bs1200/can_frames.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ def ao_set_1_2(box_id: int, ao1_voltage: float, ao2_voltage: float) -> Message:
107107
"""
108108
try:
109109
arb_id = 544 + box_id
110-
ao1 = pack("<e", ao1_voltage)
111-
ao2 = pack("<e", ao2_voltage)
110+
ao1 = pack("<h", ao1_voltage)
111+
ao2 = pack("<h", ao2_voltage)
112112
ao_payload = ao1 + ao2 + bytes(4) #pad payload with 4 empty bytes (as seen in CAN DB)
113113
frame = Message(arbitration_id = arb_id,
114114
is_extended_id = False,
@@ -210,7 +210,7 @@ def cell_voltage_set_all(box_id, v_all: float) -> Message:
210210
"""
211211
try:
212212
arb_id = 1280 + box_id
213-
volt_val = pack("<e", v_all)
213+
volt_val = pack("<h", v_all)
214214
frame = Message(arbitration_id= arb_id,
215215
is_extended_id = False,
216216
data = volt_val,
@@ -224,13 +224,13 @@ def cell_voltage_set_all(box_id, v_all: float) -> Message:
224224
return None
225225

226226

227-
def cell_voltage_setpoint(box_id, channel: int, volt_val: float) -> Message:
227+
def cell_voltage_setpoint(box_id, channel: int, volt_val: int) -> Message:
228228
"""
229229
Generates a message to set the source current for a signle channel
230230
"""
231231
try:
232232
arb_id = 1296 + box_id
233-
source_val = pack("<e", volt_val)
233+
source_val = pack("<h", volt_val)
234234
frame = Message(arbitration_id= arb_id,
235235
is_extended_id = False,
236236
data = bytes([channel-1])+source_val,

src/bs1200/driver.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,22 @@ def __exit__(self, exception_type, execption_val, tb):
5252
"\nCell 5:\t{:5f} A\t| Cell 6:\t{:5f} A\t| Cell 7:\t{:5f} A\t| Cell 8:\t{:5f} A"+
5353
"\nCell 9:\t{:5f} A\t| Cell 10:\t{:5f} A\t| Cell 11:\t{:5f} A\t| Cell 12:\t{:5f} A")
5454

55-
def scale_volts(self, voltsIn: float, to_eng_units: bool) -> float:
55+
def scale_volts(self, voltsIn, recieving : bool):
5656
"""
5757
Helper method to scale voltage value from or to microvolts.
58-
Set to_eng_units True to scale from microvolts-> volts (for recieved vals)
59-
Set False to scale from volts -> microvolts (for transmitted vals)
58+
(for recieved vals) Set recieving True to scale from millivolts (int) -> volts
59+
(for transmitted vals) Set False to scale from volts (float) -> millivolts (int)
6060
"""
61-
return (voltsIn*0.0001) if to_eng_units else (voltsIn/0.0001)
61+
return (float(voltsIn*0.0001)) if recieving else (int(voltsIn/0.0001))
6262

63-
def scale_current(self, currentIn, to_eng_units: bool):
63+
def scale_current(self, currentIn, recieving: bool):
6464
"""
6565
Helper method to scale current values from Amps to scaled values used by BS1200
6666
set to_eng_units.
6767
True to convert Scaled milliamps -> Amps (for recieved vals)
6868
set False to convert Amps -> scaled Milliamps (to transmit)
6969
"""
70-
return (((currentIn/10) - 3276.8)/1000) if to_eng_units else int((currentIn*10)*1000)
70+
return (((currentIn/10) - 3276.8)/1000) if recieving else int((currentIn*10)*1000)
7171

7272
def close(self):
7373
self.bus.shutdown()
@@ -192,7 +192,7 @@ def readback_cell_V(self, boxid: int, channel: int) -> float:
192192
if msg.arbitration_id == readbacks[frame_i].arbitration_id:
193193
rx_msg = msg
194194
break
195-
cell_volts = self.scale_volts(unpack('<e', rx_msg.data[cell_i*2:cell_i*2+2])[0], True)
195+
cell_volts = self.scale_volts(unpack('<h', rx_msg.data[cell_i*2:cell_i*2+2])[0], True)
196196
return cell_volts
197197
except pcan.PcanError as e:
198198
print("Error getting cell "+str(channel)+" Voltage: ", e)
@@ -218,7 +218,7 @@ def readback_V_all(self, boxid) -> list:
218218
break
219219
for channel in range(1,13):
220220
frame, start, end = ((channel-1)//4, 2*((channel-1)%4), 2*((channel-1)%4)+2)
221-
cell_volts[channel-1] = self.scale_volts(unpack('<e', rx_frames[frame].data[start:end])[0], True)
221+
cell_volts[channel-1] = self.scale_volts(unpack('<h', rx_frames[frame].data[start:end])[0], True)
222222
return cell_volts
223223

224224
def set_cell_I_sink(self, boxid: int, channel: int, sink_current: float) -> Message:
@@ -318,7 +318,7 @@ def readback_ai_v(self, boxid: int, channel: int) -> float:
318318
if msg.arbitration_id == readbacks[frame_i].arbitration_id:
319319
rx_msg = msg
320320
break
321-
ai_volts = self.scale_volts(unpack('<e', rx_msg.data[cell_i*2:cell_i*2+2])[0], True)
321+
ai_volts = self.scale_volts(unpack('<h', rx_msg.data[cell_i*2:cell_i*2+2])[0], True)
322322
return ai_volts
323323
except pcan.PcanError as e:
324324
print("Error getting AI Channel "+str(channel)+" Voltage: ", e)

tests/bs1200_cfg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Protocol" : "CAN",
3-
"Updated_IP" : "192.168.1.102",
3+
"IP_Address" : "192.168.1.102",
44
"Ethernet_Settings" :
55
{
66
"TCP_Cmd_Port" : 12345,

0 commit comments

Comments
 (0)