def testCPP(serialno=None, Protocol=pmapi.CPP_Backend_Protocol()): HVMON = HVPM.Monsoon() HVMON.Protocol = Protocol #HVMON.setup_usb(serialno, Protocol) Protocol.Connect(1, serialno) print("HVPM Serial Number: " + repr(Protocol.getValue(op.OpCodes.getSerialNumber, 1))) HVMON.setVout(3.7) HVengine = sampleEngine.SampleEngine(HVMON) HVengine.enableCSVOutput("HV Main Example3.csv") HVengine.ConsoleOutput(True) HVengine.enableChannel(sampleEngine.channels.MainCurrent) HVengine.enableChannel(sampleEngine.channels.MainVoltage) numSamples = sampleEngine.triggers.SAMPLECOUNT_INFINITE HVengine.setStartTrigger(sampleEngine.triggers.GREATER_THAN, 0) HVengine.setStopTrigger(sampleEngine.triggers.GREATER_THAN, 10) HVengine.setTriggerChannel(sampleEngine.channels.timeStamp) HVengine.startSampling(numSamples, 1) #Protocol.startSampling(1250,10000) #packets = Protocol.BulkRead() Protocol.closeDevice()
def setup_voltage(device_voltage): HVMON = HVPM.Monsoon() HVMON.setup_usb() print("HVPM Serial Number: " + repr(HVMON.getSerialNumber())) HVMON.fillStatusPacket() HVMON.setVout(device_voltage) HVMON.closeDevice()
def testHVPM(serialno=None,Protocol=pmapi.USB_protocol()): HVMON = HVPM.Monsoon() HVMON.setup_usb(serialno,Protocol) print("HVPM Serial Number: " + repr(HVMON.getSerialNumber())) HVMON.fillStatusPacket() HVMON.setVout(3) HVengine = sampleEngine.SampleEngine(HVMON) #Output to CSV HVengine.enableCSVOutput("HV Main Example " + str(serialno) + ".csv") #Turning off periodic console outputs. HVengine.ConsoleOutput(True) #Setting all channels enabled HVengine.enableChannel(sampleEngine.channels.MainCurrent) HVengine.enableChannel(sampleEngine.channels.MainVoltage) #HVengine.enableChannel(sampleEngine.channels.USBCurrent) #HVengine.enableChannel(sampleEngine.channels.USBVoltage) #HVengine.enableChannel(sampleEngine.channels.AuxCurrent) HVengine.enableChannel(sampleEngine.channels.timeStamp) #Setting trigger conditions numSamples=sampleEngine.triggers.SAMPLECOUNT_INFINITE HVengine.setStartTrigger(sampleEngine.triggers.GREATER_THAN,0) HVengine.setStopTrigger(sampleEngine.triggers.GREATER_THAN,600) HVengine.setTriggerChannel(sampleEngine.channels.timeStamp) #Actually start collecting samples HVengine.startSampling(numSamples) #startSampling() continues until the trigger conditions have been met, and then ends automatically. HVMON.closeDevice();
def reflashUnit(serialno=None): print("Reflashing unit number " + repr(serialno)) Mon = HVPM.Monsoon() Mon.setup_usb(serialno) Mon.resetToBootloader() time.sleep( 1 ) #Gives time for unit re-enumeration. This may need to be longer on some machines. Ref = reflash.bootloaderMonsoon() Ref.setup_usb() Header, Hex = Ref.getHeaderFromFWM('../../Firmware/debug/HVPM27.fwm') if (Ref.verifyHeader(Header)): Ref.writeFlash(Hex) Ref.resetToMainSection() time.sleep( 1 ) #Gives time for unit re-enumeration. This may need to be longer on some machines. #Verify the firmware was flashed properly. Mon.setup_usb(serialno) Mon.fillStatusPacket() print("Unit number " + repr(Mon.getSerialNumber()) + " finished. New firmware revision: " + repr(Mon.statusPacket.firmwareVersion)) Mon.closeDevice()
def __init__(self): self.HVMON = HVPM.Monsoon() self.HVMON.setup_usb() print("HVPM Serial Number: " + repr(self.HVMON.getSerialNumber())) self.HVMON.fillStatusPacket() self.HVengine = sampleEngine.SampleEngine(self.HVMON) self.HVengine.ConsoleOutput(False) self.HVengine.disableCSVOutput()
def __init__(self, serial): super().__init__() self.serial = serial self._mon = HVPM.Monsoon() self._mon.setup_usb(serial) self._allocated = True if self._mon.Protocol.DEVICE is None: raise ValueError('HVPM Monsoon %s could not be found.' % serial)
def main(): if FLAGS.v is not None: # Setup the Power Monitor. power_monitor_device = HVPM.Monsoon() power_monitor_device.setup_usb() # Set the out voltage to the given number. # Set 0 for disabling the output voltage power_monitor_device.setVout(FLAGS.v)
def collectPowerData(hash, sample_time, voltage, num_iters): serialno = _getSerialno(hash) if serialno is not None: getLogger().info("Collecting current from " "monsoon {} for {}".format(str(serialno), hash)) # wait till all actions are performed sleep(1) Mon = HVPM.Monsoon() Mon.setup_usb(serialno) # Need to sleep to be functional correctly sleep(0.2) getLogger().info("Setup Vout") Mon.setVout(voltage) getLogger().info("Setup setPowerupTime") Mon.setPowerupTime(60) getLogger().info("Setup setPowerUpCurrentLimit") Mon.setPowerUpCurrentLimit(14) getLogger().info("Setup setRunTimeCurrentLimit") Mon.setRunTimeCurrentLimit(14) # main channel getLogger().info("Setup setVoltageChannel") Mon.setVoltageChannel(0) engine = sampleEngine.SampleEngine(Mon) getLogger().info("Setup enableCSVOutput") # we may leak the file content f = tempfile.NamedTemporaryFile(delete=False) f.close() filename = f.name engine.enableCSVOutput(filename) getLogger().info("Setup ConsoleOutput") engine.ConsoleOutput(False) sleep(1) # 200 us per sample num_samples = sample_time / 0.0002 getLogger().info("startSampling on {}".format(filename)) engine.startSampling(num_samples) engine.disableCSVOutput() getLogger().info("Written power data to file: {}".format(filename)) # retrieve statistics from the power data getLogger().info("Reading data from CSV file") power_data = _getPowerData(filename) getLogger().info("Calculating the benchmark data range from " "{} data points".format(len(power_data))) start_idx, end_idx = _calculatePowerDataRange(power_data) getLogger().info("Collecting data from " "{} to {}".format(start_idx, end_idx)) getLogger().info("Benchmark time: " "{} - {} s".format(power_data[start_idx]["time"], power_data[end_idx]["time"])) data = _retrievePowerData(power_data, start_idx, end_idx, num_iters) data["power_data"] = filename return data
def __init__(self, monsoon_status_packet): super().__init__() self.cal_constants = HvpmCalibrationConstants(monsoon_status_packet) monsoon = HVPM.Monsoon() self.fine_threshold = monsoon.fineThreshold self._main_voltage_scale = monsoon.mainvoltageScale self._usb_voltage_scale = monsoon.usbVoltageScale # According to Monsoon.sampleEngine.__ADCRatio, each tick of the ADC # represents this much voltage self._adc_ratio = 6.25e-5
def testHVPM(serialno=None, Protocol=pmapi.USB_protocol()): HVMON = HVPM.Monsoon() HVMON.setup_usb(serialno, Protocol) print("HVPM Serial Number: " + repr(HVMON.getSerialNumber())) HVMON.fillStatusPacket() HVMON.setVout(3) HVengine = sampleEngine.SampleEngine(HVMON) #Output to CSV HVengine.enableCSVOutput("HV Main Example.csv") #Turning off periodic console outputs. HVengine.ConsoleOutput(True) #Setting all channels enabled HVengine.enableChannel(sampleEngine.channels.MainCurrent) HVengine.enableChannel(sampleEngine.channels.MainVoltage) HVengine.enableChannel(sampleEngine.channels.USBCurrent) HVengine.enableChannel(sampleEngine.channels.USBVoltage) HVengine.enableChannel(sampleEngine.channels.AuxCurrent) HVengine.enableChannel(sampleEngine.channels.timeStamp) #Setting trigger conditions numSamples = sampleEngine.triggers.SAMPLECOUNT_INFINITE HVengine.setStartTrigger(sampleEngine.triggers.GREATER_THAN, 0) HVengine.setStopTrigger(sampleEngine.triggers.GREATER_THAN, 5) HVengine.setTriggerChannel(sampleEngine.channels.timeStamp) #Actually start collecting samples HVengine.startSampling(numSamples) #startSampling() continues until the trigger conditions have been met, and then ends automatically. #Measurements are automatically saved to the filename passed in enableCSVOutput() #Disable CSV Output HVengine.disableCSVOutput() #Collect another 5 seconds worth of samples HVengine.startSampling(numSamples) #Get those samples as a Python list samples = HVengine.getSamples() #Samples has the format [[timestamp], [mainCurrent], [usbCurrent], [auxCurrent], [mainVolts],[usbVolts]] #Use sampleEngine.channel to select the appropriate list index. timestamp = samples[sampleEngine.channels.timeStamp] mainCurrent = samples[sampleEngine.channels.MainCurrent] auxCurrent = samples[sampleEngine.channels.AuxCurrent] usbCurrent = samples[sampleEngine.channels.USBCurrent] mainVoltage = samples[sampleEngine.channels.MainVoltage] usbVoltage = samples[sampleEngine.channels.USBVoltage] #Perform analysis on the resulting data. For example, in order to calculate, perform the following: #mainCurrent is given in mA. Divide by 1000 to convert to Amps scaledMainCurrent = [x / 1000 for x in mainCurrent] #Element-wise multiply to produce Watts. Power = Current * Voltage. mainPower = np.multiply(scaledMainCurrent, mainVoltage) #When finished, close the device. HVMON.closeDevice()
def main(unused_argv): """Simple command-line interface for Monsoon.""" useful_flags = [ "voltage", "status", "usbpassthrough", "samples", "current", "startcurrent" ] if not [ f for f in useful_flags if FLAGS.get_flag_value(f, None) is not None ]: print(__doc__.strip()) print(FLAGS.main_module_help()) return if FLAGS.avg and FLAGS.avg < 0: print("--avg must be greater than 0") return mon = HVPM.Monsoon() mon.setup_usb() if FLAGS.voltage is not None: if FLAGS.ramp is not None: RampVoltage(mon, 0, FLAGS.voltage) else: mon.setVout(FLAGS.voltage) if FLAGS.status: print("Serialno : %d\n" % mon.getSerialNumber()) mon.fillAllStatusPacket() status = mon.statusPacket attrs = vars(status) print('\n'.join("%s : %s" % item for item in attrs.items())) if FLAGS.current is not None: current = AmpsToApi(FLAGS.current) mon.setRunTimeCurrentLimit(current) print("Set runtime current to %d" % FLAGS.current) if FLAGS.startcurrent is not None: startcurrent = AmpsToApi(FLAGS.startcurrent) mon.setPowerUpCurrentLimit(startcurrent) print("Set start current to %d" % FLAGS.startcurrent) if FLAGS.usbpassthrough: if FLAGS.usbpassthrough == "off": mon.setUSBPassthroughMode(0) elif FLAGS.usbpassthrough == "on": mon.setUSBPassthroughMode(1) elif FLAGS.usbpassthrough == "auto": mon.setUSBPassthroughMode(2) else: sys.exit("bad passthrough flag: %s" % FLAGS.usbpassthrough)
def _initialize_monsoon(self): """Initializes the monsoon object. Note that this must be done after the Transformer has started. Otherwise, this transformer will have c-like objects, preventing the transformer from being used with the multiprocess libraries. """ self._monsoon = HVPM.Monsoon() self._monsoon.setup_usb(self._monsoon_id) self._monsoon.stopSampling() self._monsoon.fillStatusPacket() self._monsoon.StartSampling()
def __init__(self): self.power = 0 self.voltage = 0 self.current = 0 self.power_data = [] self.voltage_data = [] self.current_data = [] self.Mon = HVPM.Monsoon() self.Mon.setup_usb() self.engine = sampleEngine.SampleEngine(self.Mon) self.engine.disableCSVOutput() self.engine.ConsoleOutput(False)
def __create_engine(self): HVMON = HVPM.Monsoon() HVMON.setup_usb() print("HVPM Serial Number: " + repr(HVMON.getSerialNumber())) HVMON.fillStatusPacket() #HVMON.setVout(device_voltage) HVengine = sampleEngine.SampleEngine(HVMON) HVengine.ConsoleOutput(False) HVengine.disableCSVOutput() #HVengine.enableChannel(sampleEngine.channels.MainCurrent) #HVengine.enableChannel(sampleEngine.channels.MainVoltage) #HVengine.enableChannel(sampleEngine.channels.timeStamp) return HVMON, HVengine
def _transform(self, input_stream): # We need to gather the status packet before sampling so we can use the # static calibration during sample normalization. monsoon = HVPM.Monsoon() monsoon.setup_usb(self.monsoon_serial) monsoon.fillStatusPacket() monsoon_status_packet = monsoon.statusPacket() monsoon.closeDevice() # yapf: disable. Yapf doesn't handle fluent interfaces well. (ProcessAssemblyLineBuilder() .source(PacketCollector(self.monsoon_serial, self.duration)) .into(SampleNormalizer(monsoon_status_packet=monsoon_status_packet)) .build(output_stream=self.output_stream).run())
def main(): global engine # Setup the Power Monitor. power_monitor_device = HVPM.Monsoon() power_monitor_device.setup_usb() power_monitor_device.setDefaultScaleValues() # Create a sampling engine engine = sampleEngine.SampleEngine(power_monitor_device) # Set output to stdout depending on the CLI option -s. Default is False engine.ConsoleOutput(FLAGS.s) # Set the filename for the output CSV file. Default is sample.csv in pwd. if FLAGS.o: engine.enableCSVOutput(FLAGS.o) # We can define two different termination conditions. # First: time, second: number of samples. # Therefore, we have to define the timestamp as the channel for the time condition. # Than, start the measurement immediately and set the stop trigger to 30, # which will terminate the measurement after 30 seconds per default. # Finally, do not terminate the measurement after a number of samples. engine.setTriggerChannel(sampleEngine.channels.timeStamp) engine.setStartTrigger(sampleEngine.triggers.GREATER_THAN, 0) engine.setStopTrigger(sampleEngine.triggers.GREATER_THAN, sampleEngine.triggers.SAMPLECOUNT_INFINITE) num_samples = sampleEngine.triggers.SAMPLECOUNT_INFINITE # If the -t parameter is set, set the stop trigger to the given seconds. if FLAGS.t: engine.setStopTrigger(sampleEngine.triggers.GREATER_THAN, FLAGS.t) # If the -n parameter is set, set the maximum sample number to the given numnber. if FLAGS.n: num_samples = FLAGS.n engine.disableChannel(sampleEngine.channels.MainCurrent) engine.disableChannel(sampleEngine.channels.MainVoltage) if FLAGS.u: power_monitor_device.setUSBPassthroughMode(op.USB_Passthrough.On) else: power_monitor_device.setUSBPassthroughMode(op.USB_Passthrough.Off) engine.enableChannel(sampleEngine.channels.USBCurrent) engine.enableChannel(sampleEngine.channels.USBVoltage) # Finally, start the measuremen. engine.startSampling(num_samples)
def testCSVOutput(serialno=None, Protocol=pmapi.USB_protocol()): """Test case 2: CSV Output.""" #Setting all channels enabled Mon = HVPM.Monsoon() Mon.setup_usb(serialno, Protocol) Engine = sampleEngine.SampleEngine(Mon) Engine.ConsoleOutput(False) Engine.enableChannel(sampleEngine.channels.MainCurrent) Engine.enableChannel(sampleEngine.channels.MainVoltage) Engine.enableChannel(sampleEngine.channels.USBCurrent) Engine.enableChannel(sampleEngine.channels.USBVoltage) Engine.enableChannel(sampleEngine.channels.AuxCurrent) Engine.enableChannel(sampleEngine.channels.timeStamp) Engine.enableCSVOutput("Test3.csv") Engine.startSampling( 3000000, 100) #Collect 10 minutes worth of samples a 1/100 granularity Mon.closeDevice()
def testHVPM(serialno=None, Protocol=pmapi.USB_protocol()): HVMON = HVPM.Monsoon() HVMON.setup_usb(serialno, Protocol) print("HVPM Serial Number: " + repr(HVMON.getSerialNumber())) HVMON.fillStatusPacket() HVMON.setVout(3) HVengine = sampleEngine.SampleEngine(HVMON) HVengine.enableCSVOutput("HV Main Example.csv") HVengine.ConsoleOutput(True) numSamples = sampleEngine.triggers.SAMPLECOUNT_INFINITE #Don't stop based on sample count, continue until the trigger conditions have been satisfied. HVengine.setStartTrigger(sampleEngine.triggers.GREATER_THAN, 0) #Start when we exceed 0 s HVengine.setStopTrigger(sampleEngine.triggers.GREATER_THAN, 5) #Stop when we exceed 5 s. HVengine.setTriggerChannel( sampleEngine.channels.timeStamp ) #Start and stop judged by the timestamp channel. HVengine.startSampling(numSamples) HVMON.closeDevice()
def setup_monsoon(self): """Set up monsoon HVPM. Args: voltage: Voltage output of the power monitor. serial: serial number of the power monitor. """ click.secho("Setting up Monsoon {} with {}V...".format( self.serial, self.voltage), fg='blue') self.monsoon = HVPM.Monsoon() self.monsoon.setup_usb(self.serial, pmapi.USB_protocol()) set_voltage_if_different(self.monsoon, self.voltage) self.engine = SampleEngine(self.monsoon) self.engine.ConsoleOutput(False) if android.is_android_device_available(): android.reconnect_adb_through_usb() self.monsoon_usb_enabled(True)
def testDisconnectBug(serialno=None, Protocol=pmapi.USB_protocol()): """Test for start sampling disconnect bug. This is the normal use case for customers who encounter the bug. In an ideal solution, it will pass.""" Mon = HVPM.Monsoon() Mon.setup_usb(serialno, Protocol) Engine = sampleEngine.SampleEngine(Mon) Engine.ConsoleOutput(False) i = 0 for i in range(5000): i += 1 try: Engine.startSampling(10) print(i) except usb.core.USBError as e: print("Expected error hit. Reconnecting") print(e.backend_error_code) Mon.Reconnect() Mon.stopSampling() Mon.closeDevice()
def testListOutput(serialno=None, Protocol=pmapi.USB_protocol()): """Test case 1. Basic connection, outputs as a Python list.""" Mon = HVPM.Monsoon() Mon.setup_usb(serialno, Protocol) Engine = sampleEngine.SampleEngine(Mon) Engine.ConsoleOutput(False) numSamples = 5000 Engine.startSampling(numSamples) samples = Engine.getSamples() timestamp = samples[sampleEngine.channels.timeStamp] mainCurrent = samples[sampleEngine.channels.MainCurrent] auxCurrent = samples[sampleEngine.channels.AuxCurrent] usbCurrent = samples[sampleEngine.channels.USBCurrent] mainVoltage = samples[sampleEngine.channels.MainVoltage] usbVoltage = samples[sampleEngine.channels.USBVoltage] #Do something with this information pass
def testDisconnectBugSevere(serialno=None, Protocol=pmapi.USB_protocol()): """This will force the disconnect bug to occur in a short period of time. This one doesn't necessarily need to pass, but an ideal fix would allow it to do so.""" Mon = HVPM.Monsoon() Mon.setup_usb(serialno, Protocol) Engine = sampleEngine.SampleEngine(Mon) Engine.ConsoleOutput(False) i = 0 for i in range(5000): i += 1 try: Mon.StartSampling() Mon.stopSampling() print(i) except usb.core.USBError as e: print("Expected error hit. Reconnecting") print(e.backend_error_code) Mon.Reconnect() Mon.stopSampling() Mon.closeDevice()
def __init__(self, plot, plot_win, file_IO, USB_PANEL): self.p = plot self.w1 = plot_win self.file_io = file_IO self.data = [] self.time_data = [] self.temp_data = 0 self.idx = 0 self.is_start = True self.usb_panel = USB_PANEL super(PowerMonitorHandler, self).__init__() self.Mon = HVPM.Monsoon() self.Mon.setup_usb() self.Mon.setVout(4.0) self.engine = sampleEngine.SampleEngine(self.Mon) self.engine.signal_samp_trigger.connect(self.pass_through2) self.engine.enableChannel(sampleEngine.channels.USBCurrent) self.Mon.setUSBPassthroughMode(op.USB_Passthrough.On) self.engine.disableCSVOutput() self.engine.ConsoleOutput(False) self.numSamples = sampleEngine.triggers.SAMPLECOUNT_INFINITE
def testVoltageBug(serialno=None, Protocol=pmapi.USB_protocol()): """If a command is sent to the Power Monitor to setVout while it is in sample mode, there is a high probability the voltage will be set to a random value, and the unit will crash. During normal operation, this can occur if setVout is called immediately after stopSampling(). Depending on the timing, the unit might not actually be out of sample mode when the setVout command is received.""" Mon = HVPM.Monsoon() Mon.setup_usb(serialno, Protocol) Engine = sampleEngine.SampleEngine(Mon) Engine.ConsoleOutput(False) i = 0 reconnects = 0 Mon.setVout(0.8) for i in range(5000): i += 1 Engine.startSampling(50) Mon.setVout(0.8) samples = Engine.getSamples() voltage = np.array(samples[sampleEngine.channels.MainVoltage]) if (np.any(voltage > 1.0)): #Here we're checking to see if there's a condition where it didn't fail, but the voltage is still wrong. #This should probably never happen, but let's be sure about that. print("Error, voltage is wrong") assert (False) print(i) Mon.closeDevice()
def main(): #Standard setup HVMON = HVPM.Monsoon() HVMON.setup_usb() print("HVPM Serial Number: " + repr(HVMON.getSerialNumber())) HVMON.fillStatusPacket() HVMON.setVout(2.5) HVengine = sampleEngine.SampleEngine(HVMON) HVengine.ConsoleOutput(False) #Puts the Power monitor in sample mode, and starts collecting samples automatically. HVengine.periodicStartSampling() for i in range(5): #Collect the most recent 100 samples samples = HVengine.periodicCollectSamples(100) #samples has the same format as returned by getSamples(): [[timestamp], [mainCurrent], [usbCurrent], [auxCurrent], [mainVolts],[usbVolts]] print("iteration " + repr(i) + " samples collected " + repr(len(samples[0]))) time.sleep(1) #Represents doing something else for a bit. #In order to change parameters like voltage and USB passthrough mode, the unit needs to exit sample mode. HVengine.periodicStopSampling() HVMON.setVout(4.0) #Use CSV output HVengine.enableCSVOutput("periodicExample.csv") #Restart tests after changing. HVengine.periodicStartSampling() for i in range(5): #CSV output consumes samples, so we can't use them as a python list. #Samples are automatically appended to the end of the csv file HVengine.periodicCollectSamples(100) print("CSV out, iteration " + repr(i)) time.sleep(1) #When testing is concluded, stop sampling, turn off voltage, and close the device. HVengine.periodicStopSampling(closeCSV=True) HVMON.setVout(0) HVMON.closeDevice()
def main(): Dev = HVPM.Monsoon() serialNumbers = Dev.enumerateDevices() for serialno in serialNumbers: reflashUnit(serialno)
default=None, # 'data/power_samples.csv', help="file to save power samples") parser.add_argument("-t", "--trigger", type=float, default=float("inf"), help="threshold to trigger sampling, unit is mA") args = parser.parse_args() sample_number = args.number_of_samples if args.number_of_samples > 0 else sampleEngine.triggers.SAMPLECOUNT_INFINITE monsoon_model = args.monsoon_model if monsoon_model.startswith('l') or monsoon_model.startswith('w'): monsoon = LVPM.Monsoon() # white else: monsoon = HVPM.Monsoon() monsoon.setup_usb() print("Monsoon Power Monitor Serial number: {}".format( monsoon.getSerialNumber())) engine = sampleEngine.SampleEngine(monsoon) trigger = args.trigger if args.save_file: dir_name = os.path.dirname(args.save_file) if not os.path.exists(dir_name): os.makedirs(dir_name) if trigger < float("inf"): # set trigger engine.disableCSVOutput() # global csv_name csv_file = args.save_file csv_file_handle = open(csv_file, 'w')
def testHVPM(serialno=None, Protocol=pmapi.USB_protocol()): HVMON = HVPM.Monsoon() HVMON.setup_usb(serialno, Protocol) print("HVPM Serial Number: " + repr(HVMON.getSerialNumber())) HVMON.setPowerUpCurrentLimit(8) HVMON.setRunTimeCurrentLimit(8) HVMON.fillStatusPacket() #HVMON.calibrateVoltage() HVMON.setVout(1) HVengine = sampleEngine.SampleEngine(HVMON) #Output to CSV #HVengine.enableCSVOutput("HV Main Example2.csv") #Turning off periodic console outputs. HVengine.ConsoleOutput(True) #Setting all channels enabled HVengine.enableChannel(sampleEngine.channels.MainCurrent) HVengine.enableChannel(sampleEngine.channels.MainVoltage) #HVengine.enableChannel(sampleEngine.channels.USBCurrent) #HVengine.enableChannel(sampleEngine.channels.USBVoltage) #HVengine.enableChannel(sampleEngine.channels.AuxCurrent) #HVengine.enableChannel(sampleEngine.channels.timeStamp) #Setting trigger conditions numSamples = sampleEngine.triggers.SAMPLECOUNT_INFINITE HVengine.setStartTrigger(sampleEngine.triggers.GREATER_THAN, 0) HVengine.setStopTrigger(sampleEngine.triggers.GREATER_THAN, 60) HVengine.setTriggerChannel(sampleEngine.channels.timeStamp) #Actually start collecting samples HVengine.startSampling(numSamples, 1) #startSampling() continues until the trigger conditions have been met, and then ends automatically. #Measurements are automatically saved to the filename passed in enableCSVOutput() #Disable CSV Output #HVengine.disableCSVOutput() #Collect another 5 seconds worth of samples #HVengine.startSampling(numSamples) #Get those samples as a Python list #samples = HVengine.getSamples() #Samples has the format [[timestamp], [mainCurrent], [usbCurrent], [auxCurrent], [mainVolts],[usbVolts]] #Use sampleEngine.channel to select the appropriate list index. #timestamp = samples[sampleEngine.channels.timeStamp] #mainCurrent = samples[sampleEngine.channels.MainCurrent] #auxCurrent = samples[sampleEngine.channels.AuxCurrent] #usbCurrent = samples[sampleEngine.channels.USBCurrent] #mainVoltage = samples[sampleEngine.channels.MainVoltage] #usbVoltage = samples[sampleEngine.channels.USBVoltage] #Perform analysis on the resulting data. For example, in order to calculate, perform the following: #mainCurrent is given in mA. Divide by 1000 to convert to Amps #scaledMainCurrent = [x / 1000 for x in mainCurrent] #Element-wise multiply to produce Watts. Power = Current * Voltage. #mainPower = np.multiply(scaledMainCurrent, mainVoltage) #When finished, close the device. #print("Firmware version: ", HVMON.statusPacket.firmwareVersion) #print("auxCoarseOffset: ", HVMON.statusPacket.auxCoarseResistorOffset) #print("auxCoarseScale: ", HVMON.statusPacket.auxCoarseScale) #print("auxFineOffset: ", HVMON.statusPacket.auxFineResistorOffset) #print("auxFineScale: ", HVMON.statusPacket.auxFineScale) print("dacCalHigh: ", HVMON.statusPacket.dacCalHigh) print("dacCalLow: ", HVMON.statusPacket.dacCalLow) #print("hardwareModel: ", HVMON.statusPacket.hardwareModel) #print("mainCoarseOffset: ", HVMON.statusPacket.mainCoarseResistorOffset) #print("mainCoarseScale: ", HVMON.statusPacket.mainCoarseScale) #print("mainCoarseZeroOffset: ", HVMON.statusPacket.mainCoarseZeroOffset) #print("mainFineResistorOffset: ", HVMON.statusPacket.mainFineResistorOffset) #print("mainFineScale: ", HVMON.statusPacket.mainFineScale) #print("mainFineZeroOffset: ", HVMON.statusPacket.mainFineZeroOffset) print("powerupCurrentLimit: ", HVMON.statusPacket.powerupCurrentLimit) #print("powerupTime: ", HVMON.statusPacket.powerupTime) #print("protocolVersion: ", HVMON.statusPacket.protocolVersion) print("runtimeCurrentLimit: ", HVMON.statusPacket.runtimeCurrentLimit) print("serialNumber: ", HVMON.statusPacket.serialNumber) #print("temperature: ", HVMON.statusPacket.temperature) #print("temperatureLimit: ", HVMON.statusPacket.temperatureLimit) #print("usbCoarseResistorOffset: ", HVMON.statusPacket.usbCoarseResistorOffset) #print("usbCoarseScale: ", HVMON.statusPacket.usbCoarseScale) #print("usbCoarseZeroOffset: ", HVMON.statusPacket.usbCoarseZeroOffset) #print("usbFineResistorOffset: ", HVMON.statusPacket.usbFineResistorOffset) #print("usbFineScale: ", HVMON.statusPacket.usbFineScale) #print("usbFineZeroOffset: ", HVMON.statusPacket.usbFineZeroOffset) #print("usbPassthroughMode: ", HVMON.statusPacket.usbPassthroughMode) HVMON.closeDevice()