def __init__(self, name, config, hardware_engine, file_folder): # parameters self.output_waveform_path = None # device info self.name = None self.config = None # Saleae instance self.saleae_dev = None # execution info self.execution_start_time = None # parse config if "output_waveform_file" not in config: raise Exception('"output_waveform_file" field is required') self.output_waveform_path = os.path.join( file_folder, config['output_waveform_file']) self.seleae_dev = saleae.Saleae() if not self.seleae_dev: raise Exception('No Logic Seleae detected') active_channels_A = config[ 'active_channels_A'] if 'active_channels_A' in config else [] active_channels_B = config[ 'active_channels_B'] if 'active_channels_B' in config else [] self.seleae_dev.set_active_channels(active_channels_A, active_channels_B) self.name = name self.config = config
def __init__(self): rospy.init_node(self.NODE_NAME) self.server = actionlib.SimpleActionServer(self.ACTION_NAME, SaleaeAction, self.execute, False) self.server.start() self.saleae = saleae.Saleae(self.IP_ADDRESS, self.PORT) rospy.spin()
def test(): close_logic() clear_crash_log() build() saleae.Saleae.launch_logic(logic_path=LOGIC_PATH + 'Logic', quiet=False) time.sleep(1) s = saleae.Saleae() s.capture_start()
def init_saleae(): ''' Connects to SALEAE Logic, loads the config file and returns the connection ''' saleae_con = saleae.Saleae(LOGIC_HOST, LOGIC_PORT) # config_saleae(saleae_con) return saleae_con
def __init__(self, output_basename, device='/dev/ttyUSB0', baudrate=115200, use_cache=False): self.output_basename = output_basename self.events = list() self.next_slot = 0 self.nb_step_loaded = -1 self.event_count = 0 self.use_cache = use_cache if (self.use_cache): return # try to connect on serial port try: self.ser = serial.Serial(device, baudrate, timeout=None) except Exception as e: print('Serial player not connected.', file=sys.stderr) sys.exit(0) # wait for ready message self._receive() # reset target board self.reset_target() self._send("start") time.sleep(4) self._reset_player() # launch logic if needed self.logic_was_running = saleae.Saleae.is_logic_running() self.s = saleae.Saleae(quiet=True) # check saleae device is connected if (len(self.s.get_connected_devices()) == 4): self.ser.close() print('Saleae device not connected.', file=sys.stderr) sys.exit(0) # configure capture self.s.set_trigger_one_channel(0, saleae.Trigger.Posedge) self.s.set_sample_rate((1000000, 0)) # prepare event file self.event_file = open(self.output_basename + '.event', "w") self.nb_step_loaded = 0
def __init__(self): rospy.init_node(self.NODE_NAME) self.server = actionlib.SimpleActionServer(self.ACTION_NAME, SaleaeAction, self.execute, False) # Delete the saleae settings file to get around this issue: # https://github.com/saleae/SaleaeSocketApi/issues/14 if os.path.exists(self.SALEAE_SETTINGS): os.remove(self.SALEAE_SETTINGS) self.saleae = saleae.Saleae(args='-disablepopups -socket') rospy.loginfo("Saleae started") self.server.start() rospy.spin()
def capture_img(self, filename): t = time.time() print("\t\tlibraView : snooping image with Saleae") if os.path.exists(filename): os.remove(filename) sal = saleae.Saleae() sal.capture_start_and_wait_until_finished() #sal.export_data2(os.path.abspath(filename),[0,1,2],None,None,'binary') #binary is fastest sal.export_data2(os.path.abspath(filename), [2, 1, 0], None, None, 'binary') #binary is fastest [2]: EXTDATA1 , [1]: EXTDATA0, [0]: CLK while not os.path.exists(filename) or not (os.path.getsize( filename) > 1000) or not sal.is_processing_complete(): #wait time.sleep(0.5) time.sleep(5) print("\t\t>snooping : time = %.1f sec" % (time.time() - t)) time.sleep(1) return
def recordFirstListen(host='localhost', port=10429): #folder = firstListen #os.mkdir(folder) s=saleae.Saleae() #s=Saleae(host=host, port=port) #s.set_num_samples(1e6) # for i in range(5): # path = os.path.abspath(os.path.join(folder, str(i))) # s.capture_to_file(path) digital = [] #analog = [0, 1, 2] analog = [1] s.set_active_channels(digital, analog) #no digital? #print(s.get_all_sample_rates()) s.set_sample_rate((0, 625000)) s.set_capture_seconds(2.05) StartTime=time.time() print(StartTime) s.capture_start() file_path_on_target_machine="/Users/Kelsey/Desktop/Hydrophone/firstListen.csv" s.export_data2(file_path_on_target_machine, #digital_channels=None, #analog_channels=[0, 1, 2], format="csv", analog_channels=[1], analog_format="voltage" ) print(time.time()) ##filter it using normal cheby filter ##find start of ping #find where time of start of ping #return this time return 0
def getPingerData(host='localhost', port=10429): s = saleae.Saleae() digital = [] analog = [0, 1, 2] s.set_active_channels(digital, analog) s.set_sample_rate((0, 625000)) s.set_capture_seconds(2.2) s.capture_start_and_wait_until_finished() t = time.time() file_path_on_target_machine = str(PING_CAP_DIR + str(t) + ".csv") s.export_data2(file_path_on_target_machine, digital_channels=digital, analog_channels=analog, format="csv", analog_format="voltage" ) return t, file_path_on_target_machine
def __init__(self, sample_rate=10 * MHZ, max_duration=600, outputs=None): channels = [o.index - 1 for o in outputs] self.channels = channels self.sample_rate = sample_rate self.sal = saleae.Saleae() self.sal.set_active_channels(digital=channels, analog=None) self.sal.set_sample_rate((sample_rate, 0)) self.sal.set_capture_seconds(max_duration) for output in outputs: self.sal.set_trigger_one_channel(output.index - 1, output.trigger) self.start_time = time.monotonic() self.sal.capture_start() print("Sleeping for 3 seconds...") time.sleep(3) """
def getPingerData(host='localhost', port=10429, TimerClock=time.time()): currentTime=time.time() while currentTime > TimerClock: TimerClock+=2 #this should probably 1.9 depending on pinger properties time.sleep(TimerClock-currentTime) #may have to add wake up time s=saleae.Saleae() digital = [] analog=[0, 1, 2] s.set_active_channels(digital, analog) s.set_sample_rate((0, 625000)) s.set_capture_seconds(0.2) s.capture_start() file_path_on_target_machine="/Users/Kelsey/Desktop/Hydrophone/normalListen.csv" s.export_data2(file_path_on_target_machine, digital_channels=None, analog_channels=[0, 1, 2], format="csv", analog_format="voltage" ) return TimerClock
def sample_and_write_analog(channels, duration, save_folder, sample_id): s = saleae.Saleae() # set capture settings for the saleae s.set_sample_rate( (0, 125000)) # default sampling rate needed for our sensor s.set_active_channels(None, channels) # no digital channels, all analog channels s.set_capture_seconds(duration) # 60 second integration # file to be saved out to # folder = time.strftime('%Y-%m-%d--%H-%M') # os.mkdir(folder) path = os.path.abspath(os.path.join(save_folder, str(sample_id))) # print path # capture and save, keep original and also make a matlab file s.capture_to_file(path) #s.export_data # save also to matlab s.export_data2(path, None, channels, None, 'matlab') #save to matlab # sample_and_write_analog([0,1,2,3], 2, '../automated_tests_data', 10)
def __init__(self): """ Creates the analyzer and sets default settings """ self.analyzer = saleae.Saleae(quiet=True) self.sample_rate = 24000000 self.sample_time = 10 self.analyzer.set_sample_rate_by_minimum(self.sample_rate)
def __init__(self): self.s = saleae.Saleae()
#!/usr/bin/python3 # Trigger a capture from an already enabled Saleae logic instance # # To install: # sudo apt install python3-pip # sudo pip3 install saleae import saleae sal = saleae.Saleae() sal._cmd('CAPTURE')
'--ip', metavar='IP', default='localhost', help='optional, IP address to connect to. Default localhost') parser.add_argument('--port', metavar='PORT', default=10429, help='optional, Port to connect to. Default 10429') args = parser.parse_args() validate_path(args.save_captures, '--save-captures') validate_path(args.export_data, '--export-data') validate_path(args.export_analyzers, '--export-analyzers') s = saleae.Saleae(args.ip, args.port) for x in range(args.capture_count): #set capture duration s.set_capture_seconds(args.capture_duration) #start capture. Only save to disk if the --save-captures option was specified. if args.save_captures != None: file_name = '{0}.logicdata'.format(x) save_path = os.path.join(args.save_captures, file_name) print('starting capture and saving to ' + save_path) s.capture_to_file(save_path) else: #currently, the python library doesn't provide a CAPTURE command that blocks until an ACK is received s._cmd('CAPTURE') #raw export
while (elapsedTimeHours < totalDurationHours): fileNameStats = fileNameStatsPrefix + str( ambientSetTemp) + "Count" + str(count) + "DataStats.csv" with open(fileNameStats, 'w') as hFile2: # Use hfile to refer to the file object if (count == 0): statsOut = "TotalTime(s)" + "," + "meanPeakToPeak" + "," + "stdev peak to peak" + "," "SN Ratio" + "ambient Temp" + "furnace Temp" + "ThermistorTemp" + "mean DC" + '\n' hFile2.write(statsOut) count = count + 1 for n in range(0, nAmbient): #initalize Salae Drive print("Running Saleae connection.\n") s = saleae.Saleae(host, port) print("Saleae connected.") devices = s.get_connected_devices() print("Connected devices") for device in devices: print("\t{}".format(device)) print("Setting active channels (digital={}, analog={})".format( digitalChannelList, analogChannelList)) s.set_active_channels(digitalChannelList, analogChannelList) digital, analog = s.get_active_channels() print("Reading back active channels:") print("\tdigital={}\n\tanalog={}".format(digital, analog)) sampleRateKHz = sampleRate / 1e3 sampledurationS = sampleDurationMs / 1e3 nSamples = sampleRate * sampledurationS
def setup_class(cls): cls.s = saleae.Saleae()
# Import needed packages import os import re from os import listdir from os.path import isfile, join from os.path import basename import time # See https://github.com/ppannuto/python-saleae import saleae # folder = time.strftime('%Y-%m-%d--%H-%M-%S') # os.mkdir(folder) # Instance of Saleae API interface class sObj = saleae.Saleae() # Paths for files and export # rootFilePath = r'\\171.65.115.78\pain\data\behavior\p700\SNI' rootFilePath = r'INPUTPATH' rootExportPath = r'OUTPUTPATH' os.makedirs(rootExportPath, exist_ok=True) # sessionName = '2018_04_25_p700_m608_preSNI01' # listFileNames = ['01habit', '02lickSession', '03thresholds', '04stimuliBlockOne', '05stimuliBlockTwo', '06stimuliBlockThree', '07stimuliBlockFour', '08stimuliBlockFive','09lickSession'] # Salaea channels for logicdata files with both digital and analog data cDigitalChans = [0, 4, 5] cAnalogChans = [1, 2, 3] # Regexp for digital only and mixed digital/analog files
import sys import saleae import argparse parser = argparse.ArgumentParser(description='Saleae OpenMV test') parser.add_argument('--test-data', metavar='PATH', help='Capture and compare test data') parser.add_argument('--export-data', metavar='PATH', help='Capture and export test data') args = parser.parse_args() if (args.test_data == None and args.export_data == None): parser.print_help() sys.exit(1) # Init device. s = saleae.Saleae() # Capture samples. s.set_num_samples(10e6) # Set falling trigger on channel 0. s.set_trigger_one_channel(0, saleae.Trigger.Negedge) # Start capture. s.capture_start_and_wait_until_finished() # Export and exit. if args.export_data: s.export_data2(args.export_data) sys.exit(0)
def sample_rates(channels): sal = saleae.Saleae() sal.set_active_channels(digital=channels, analog=None) return [r[0] for r in sal.get_all_sample_rates()]