@@ -52,22 +52,22 @@ def __exit__(self, exception_type, execption_val, tb):
5252 "\n Cell 5:\t {:5f} A\t | Cell 6:\t {:5f} A\t | Cell 7:\t {:5f} A\t | Cell 8:\t {:5f} A" +
5353 "\n Cell 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 )
0 commit comments