def testLVPM(serialno=None, Protcol=pmapi.USB_protocol()): Mon = LVPM.Monsoon() Mon.setup_usb(serialno, Protcol) print("LVPM Serial number: " + repr(Mon.getSerialNumber())) Mon.fillStatusPacket() Mon.setVout(4) engine = sampleEngine.SampleEngine(Mon) engine.enableCSVOutput("Main Example.csv") engine.ConsoleOutput(True) #test main channels testTime = 2 numSamples = sampleEngine.triggers.SAMPLECOUNT_INFINITE #Don't stop based on sample count, continue until the trigger conditions have been satisfied. engine.setStartTrigger(sampleEngine.triggers.GREATER_THAN, 0) #Start when we exceed 0 s engine.setStopTrigger(sampleEngine.triggers.GREATER_THAN, testTime) #Stop when we exceed 5 s. engine.setTriggerChannel( sampleEngine.channels.timeStamp ) #Start and stop judged by the timestamp channel. engine.startSampling(numSamples) engine.disableChannel(sampleEngine.channels.MainCurrent) engine.disableChannel(sampleEngine.channels.MainVoltage) #Disable Main channels #engine.disableChannel(sampleEngine.channels.MainCurrent) #engine.disableChannel(sampleEngine.channels.MainVoltage) #engine.setStartTrigger(sampleEngine.triggers.GREATER_THAN,5) #engine.setStopTrigger(sampleEngine.triggers.GREATER_THAN,10) #engine.setTriggerChannel(sampleEngine.channels.timeStamp) #Take measurements from the USB Channel #Mon.setVout(0) #Set USB Passthrough mode to 'on,' since it defaults to 'auto' and will turn off when sampling mode begins. #Mon.setUSBPassthroughMode(op.USB_Passthrough.On) #Enable USB channels #engine.enableChannel(sampleEngine.channels.USBCurrent) #engine.enableChannel(sampleEngine.channels.USBVoltage) #engine.enableCSVOutput("USB Test.csv") #engine.startSampling(5000) #Enable every channel, take measurements #engine.enableChannel(sampleEngine.channels.MainVoltage) #engine.enableChannel(sampleEngine.channels.MainCurrent) #Enable Aux channel #engine.enableChannel(sampleEngine.channels.AuxCurrent) #Mon.setVout(4.3) #engine.enableCSVOutput("All Test.csv") #engine.startSampling(5000) #Enable every channel, take measurements, and retrieve them as a Python list. #engine.disableCSVOutput() #engine.startSampling(5000) #samples = engine.getSamples() Mon.closeDevice()
def setup_monsoon(self): """Set up monsoon. 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 = LVPM.Monsoon() self.monsoon.setup_usb(self.serial) 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 initLVPM(serialno=None, Protcol=pmapi.USB_protocol()): Mon = LVPM.Monsoon() Mon.setup_usb(serialno, Protcol) print("LVPM Serial number: " + str(serialno)) Mon.fillStatusPacket() Mon.setVout(4) timetoBoot = 150 iterationsPerScenario = 30 print("Voltage enabled") print( "You have %d seconds to boot your phone, disable USB charging and check it is correctly detected (under adb " "devices) before measurements start." % timetoBoot) timer = timetoBoot - 1 while timer > -1: print("%d seconds remaining." % timer) sys.stdout.write("\033[F") # Cursor up one line timer -= 1 time.sleep(1) launchMeasurements(Mon, iterationsPerScenario)
"--save_file", type=str, 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
import Monsoon.LVPM as LVPM import Monsoon.sampleEngine as sampleEngine import Monsoon.Operations as op Mon = LVPM.Monsoon() Mon.setup_usb() Mon.setVout(4.0) engine = sampleEngine.SampleEngine(Mon) engine.enableCSVOutput("Main Example.csv") engine.ConsoleOutput(True) numSamples = 50000 #sample for one second engine.startSampling(numSamples) #Diable Main channels engine.disableChannel(sampleEngine.channels.MainCurrent) engine.disableChannel(sampleEngine.channels.MainVoltage) #Take measurements from the USB Channel Mon.setVout(0) #Set USB Passthrough mode to 'on,' since it defaults to 'auto' and will turn off when sampling mode begins. Mon.setUSBPassthroughMode(op.USB_Passthrough.On) #Enable USB channels engine.enableChannel(sampleEngine.channels.USBCurrent) engine.enableChannel(sampleEngine.channels.USBVoltage) engine.enableCSVOutput("USB Test.csv") engine.startSampling(5000) #Enable every channel, take measurements engine.enableChannel(sampleEngine.channels.MainVoltage) engine.enableChannel(sampleEngine.channels.MainCurrent) #Enable Aux channel
class MonsoonDAQ: # print("Monsoon Set up...") # 이거 뭐지..왜 돌지 mymon = LVPM.Monsoon() mymon.setup_usb() myengine = sampleEngine.SampleEngine(mymon) myengine.disableCSVOutput() myengine.ConsoleOutput(False) print("Monsoon Setting Finished...") def __init__(self): pass def getsamples(self): global count global bc print("getSamples() start...") self.myengine.startSampling(5000) mysamples1 = self.myengine.getSamples() self.myengine.startSampling(5000) mysamples2 = self.myengine.getSamples() self.myengine.startSampling(5000) mysamples3 = self.myengine.getSamples() self.myengine.startSampling(5000) mysamples4 = self.myengine.getSamples() self.myengine.startSampling(5000) mysamples5 = self.myengine.getSamples() self.myengine.startSampling(5000) mysamples6 = self.myengine.getSamples() self.myengine.startSampling(5000) mysamples7 = self.myengine.getSamples() self.myengine.startSampling(5000) mysamples8 = self.myengine.getSamples() self.myengine.startSampling(5000) mysamples9 = self.myengine.getSamples() self.myengine.startSampling(5000) mysamples10 = self.myengine.getSamples() # sample 중에서 전류채널은 [1]입니다. API guide 참고 mysamples_5 = mysamples1[1] + mysamples3[1] + mysamples5[ 1] + mysamples7[1] + mysamples9[1] mysamples_10 = mysamples_5 \ + mysamples2[1] + mysamples4[1] + mysamples6[1] + mysamples8[1] + mysamples10[1] print("getSamples() end...") # 샘플 처리 시작 sample_mean = numpy.mean(mysamples_5) sample_std = numpy.std(mysamples_5) sig_50 = 0.6745 * sample_std sig_40 = 0.4 * sample_std sig_20 = 0.2 * sample_std val_count50 = 0 mycurrents50 = 0 val_count40 = 0 mycurrents40 = 0 val_count20 = 0 mycurrents20 = 0 for i in range(len(mysamples_5)): if mysamples_5[i] < sample_mean + sig_50 and mysamples_5[ i] > sample_mean - sig_50: mycurrents50 = mycurrents50 + mysamples_5[i] val_count50 += 1 if mysamples_5[i] < sample_mean + sig_40 and mysamples_5[ i] > sample_mean - sig_40: mycurrents40 = mycurrents40 + mysamples_5[i] val_count40 += 1 if mysamples_5[i] < sample_mean + sig_20 and mysamples_5[ i] > sample_mean - sig_20: mycurrents20 = mycurrents20 + mysamples_5[i] val_count20 += 1 current50 = mycurrents50 / val_count50 current40 = mycurrents40 / val_count40 current20 = mycurrents20 / val_count20 print("[%6d][ 5samples][sig=50]" % count) print(repr(current50)) print("[%6d][ 5samples][sig=40]" % count) print(repr(current40)) print("[%6d][ 5samples][sig=20]" % count) print(repr(current20)) sample_mean = numpy.mean(mysamples_10) sample_std = numpy.std(mysamples_10) sig_50 = 0.6745 * sample_std sig_40 = 0.4 * sample_std sig_20 = 0.2 * sample_std val_count50 = 0 mycurrents50 = 0 val_count40 = 0 mycurrents40 = 0 val_count20 = 0 mycurrents20 = 0 for i in range(len(mysamples_10)): if mysamples_10[i] < sample_mean + sig_50 and mysamples_10[ i] > sample_mean - sig_50: mycurrents50 = mycurrents50 + mysamples_10[i] val_count50 += 1 if mysamples_10[i] < sample_mean + sig_40 and mysamples_10[ i] > sample_mean - sig_40: mycurrents40 = mycurrents40 + mysamples_10[i] val_count40 += 1 if mysamples_10[i] < sample_mean + sig_20 and mysamples_10[ i] > sample_mean - sig_20: mycurrents20 = mycurrents20 + mysamples_10[i] val_count20 += 1 current50 = mycurrents50 / val_count50 current40 = mycurrents40 / val_count40 current20 = mycurrents20 / val_count20 print("[%6d][10samples][sig=50]" % count) print(repr(current50)) print("[%6d][10samples][sig=40]" % count) print(repr(current40)) print("[%6d][10samples][sig=20]" % count) print(repr(current20)) ac = datetime.utcnow().strftime('%H:%M:%S.%f') print("[%s] " % ac, "[%s]" % bc) bc = ac print("Get ready for the next measurements...") threading.Timer(8.777, self.getsamples).start() count += 1
def test_get_voltage(self): voltage = 4.0 monsoon = LVPM.Monsoon() monsoon.setup_usb() monsoon.setVout(voltage) self.assertEqual(voltage, get_voltage(monsoon))
def power_on(serial_no=None, protocol=pmapi.USB_protocol()): Mon = LVPM.Monsoon() Mon.setup_usb(serial_no, protocol) print("LVPM Serial number: " + repr(Mon.getSerialNumber())) Mon.fillStatusPacket() Mon.setVout(4.2)