@@ -988,62 +988,62 @@ def get_vmon_values(self) -> list[dict]:
988988 raise # Re-raise the exception for the caller to handle
989989
990990 def set_raw_dac (self , dac_id : int = 0 , dac_value : int = 0 ) -> int :
991- """
992- Set Raw DAC value.
993-
994- Args:
995- dac_id (int): The desired DAC to set (default is 0). Valid IDs are 0, 1, 2, and 3.
996- dac_value (int): The desired DAC value (default is 0). Must be between 0 and 4095.
997- Returns:
998- int: The current output DAC value.
999-
1000- Raises:
1001- ValueError: If the controller is not connected.
1002- """
1003- if not self .uart .is_connected ():
1004- raise ValueError ("High voltage controller not connected" )
1005-
1006- if dac_id not in [0 , 1 , 2 ,3 ]:
1007- raise ValueError ("Invalid DAC ID. Must be 0, 1, 2, or 3" )
1008-
1009- if dac_value not in range (4096 ):
1010- raise ValueError ("Invalid DAC value. Must be 0 to 4095" )
1011-
1012- try :
1013- if self .uart .demo_mode :
1014- return dac_value
1015- logger .info ("Setting Raw DAC value." )
1016- data = bytes (
1017- [
1018- (dac_value >> 8 ) & 0xFF , # High byte (most significant bits)
1019- dac_value & 0xFF , # Low byte (least significant bits)
1020- ]
1021- )
1022- r = self .uart .send_packet (
1023- id = None ,
1024- addr = dac_id ,
1025- packetType = OW_POWER ,
1026- command = OW_POWER_RAW_DAC ,
1027- data = data ,
1028- )
1029-
1030- self .uart .clear_buffer ()
1031- # r.print_packet()
1032-
1033- if r .packet_type == OW_ERROR :
1034- logger .error ("Error setting DAC value" )
1035- return - 1
1036-
1037- logger .info (f"Set DAC value to { dac_value } " )
991+ """
992+ Set Raw DAC value.
993+
994+ Args:
995+ dac_id (int): The desired DAC to set (default is 0). Valid IDs are 0, 1, 2, and 3.
996+ dac_value (int): The desired DAC value (default is 0). Must be between 0 and 4095.
997+ Returns:
998+ int: The current output DAC value.
999+
1000+ Raises:
1001+ ValueError: If the controller is not connected.
1002+ """
1003+ if not self .uart .is_connected ():
1004+ raise ValueError ("High voltage controller not connected" )
1005+
1006+ if dac_id not in [0 , 1 , 2 ,3 ]:
1007+ raise ValueError ("Invalid DAC ID. Must be 0, 1, 2, or 3" )
1008+
1009+ if dac_value not in range (4096 ):
1010+ raise ValueError ("Invalid DAC value. Must be 0 to 4095" )
1011+
1012+ try :
1013+ if self .uart .demo_mode :
10381014 return dac_value
1015+ logger .info ("Setting Raw DAC value." )
1016+ data = bytes (
1017+ [
1018+ (dac_value >> 8 ) & 0xFF , # High byte (most significant bits)
1019+ dac_value & 0xFF , # Low byte (least significant bits)
1020+ ]
1021+ )
1022+ r = self .uart .send_packet (
1023+ id = None ,
1024+ addr = dac_id ,
1025+ packetType = OW_POWER ,
1026+ command = OW_POWER_RAW_DAC ,
1027+ data = data ,
1028+ )
10391029
1040- except ValueError as v :
1041- logger .error ("ValueError: %s" , v )
1042- raise # Re-raise the exception for the caller to handle
1030+ self .uart .clear_buffer ()
1031+ # r.print_packet()
10431032
1044- except Exception as e :
1045- logger .error ("Unexpected error during process: %s" , e )
1046- raise # Re-raise the exception for the caller to handle
1033+ if r .packet_type == OW_ERROR :
1034+ logger .error ("Error setting DAC value" )
1035+ return - 1
1036+
1037+ logger .info (f"Set DAC value to { dac_value } " )
1038+ return dac_value
1039+
1040+ except ValueError as v :
1041+ logger .error ("ValueError: %s" , v )
1042+ raise # Re-raise the exception for the caller to handle
1043+
1044+ except Exception as e :
1045+ logger .error ("Unexpected error during process: %s" , e )
1046+ raise # Re-raise the exception for the caller to handle
10471047
10481048 def hv_enable (self , enable : bool = False ) -> bool :
10491049 """
0 commit comments