<commit_before>from bitlib import *
import numpy as np
import argparse

def main(samples,sample_rate):
    assert BL_Open() == 1 # returns number devices opened

    """First, must select device. Returns index of selected entity.
    Note that it is 0-indexed."""
    assert BL_Select(BL_SELECT_DEVICE,0) == 0

    """Second, select the capture mode. This must happen after
    selecting the device but before selecting channels."""
    BL_Mode(BL_MODE_DUAL) # prefered capture mode

    """Now select each channel in turn and configure. Returns index
    of selected channel if channel has been successfully
    selected."""
    channels = [0,1]
    for channel in channels:
        assert BL_Select(BL_SELECT_CHANNEL,channel) == channel

        # not sure if this should be bnc
        BL_Select(BL_SELECT_SOURCE,BL_SOURCE_POD)

        """Set the voltage range. Can get the number of ranges from
        BL_Count(BL_COUNT_RANGE). This returns 5. Can set the maxi
        range using BL_Range(BL_Count(BL_COUNT_RANGE) (11 V) but I
        only want 5 V. This is an index of 3. BL_Range returns max
        voltage. """
        assert BL_Range(3) == 5.2
        
        # Enable the channel
        assert BL_Enable(True) == True

    """Now do trace parameters. BL_Rate must always be specified
    and it should be the first parameter assigned when preparing a
    new trace. Note that if this sample rate can't be selected, the
    nearest sample rate will be returned."""
    assert BL_Rate(sample_rate) == sample_rate

    """Next is number of samples. Returned value is actual number of
    samples returned."""
    assert samples == BL_Size(samples)
    
    # do trace, acquire data
    BL_Trace()

    # get first channel
    channel = 0
    assert BL_Select(BL_SELECT_CHANNEL,channel) == channel
    chA = BL_Acquire()

    # get second channel
    channel = 1
    assert BL_Select(BL_SELECT_CHANNEL,channel) == channel
    chB = BL_Acquire()

    BL_Close()

    # provide times samples were taken
    time = np.arange(0,1.0*samples/sample_rate,1.0/sample_rate)
    
    # print output: time (s), chA (V), chB (V)
    for t, chA, chB in zip(time, chA, chB):
        print '%f,%f,%f' % (t, chA, chB)

if __name__ == '__main__':
    # defaults
    samples = 5000
    sample_rate = 10000
    
    parser = argparse.ArgumentParser()
    parser.add_argument('-n', dest='samples',
                        help='number of samples to acquire (default %i)'
                        % samples, type=int)
    parser.add_argument('-r', dest='sample_rate', help='samples/second (default'
                        ' %i)' % sample_rate, type=int)
    parser.add_argument('-header', help='print header row', action='store_true')
    args = parser.parse_args()

    if args.samples:
        samples = args.samples

    if args.sample_rate:
        sample_rate = args.sample_rate

    if args.header:<commit_msg>Added argparser description<commit_after>from bitlib import *
import numpy as np
import argparse

def main(samples,sample_rate):
    assert BL_Open() == 1 # returns number devices opened

    """First, must select device. Returns index of selected entity.
    Note that it is 0-indexed."""
    assert BL_Select(BL_SELECT_DEVICE,0) == 0

    """Second, select the capture mode. This must happen after
    selecting the device but before selecting channels."""
    BL_Mode(BL_MODE_DUAL) # prefered capture mode

    """Now select each channel in turn and configure. Returns index
    of selected channel if channel has been successfully
    selected."""
    channels = [0,1]
    for channel in channels:
        assert BL_Select(BL_SELECT_CHANNEL,channel) == channel

        # not sure if this should be bnc
        BL_Select(BL_SELECT_SOURCE,BL_SOURCE_POD)

        """Set the voltage range. Can get the number of ranges from
        BL_Count(BL_COUNT_RANGE). This returns 5. Can set the maxi
        range using BL_Range(BL_Count(BL_COUNT_RANGE) (11 V) but I
        only want 5 V. This is an index of 3. BL_Range returns max
        voltage. """
        assert BL_Range(3) == 5.2
        
        # Enable the channel
        assert BL_Enable(True) == True

    """Now do trace parameters. BL_Rate must always be specified
    and it should be the first parameter assigned when preparing a
    new trace. Note that if this sample rate can't be selected, the
    nearest sample rate will be returned."""
    assert BL_Rate(sample_rate) == sample_rate

    """Next is number of samples. Returned value is actual number of
    samples returned."""
    assert samples == BL_Size(samples)
    
    # do trace, acquire data
    BL_Trace()

    # get first channel
    channel = 0
    assert BL_Select(BL_SELECT_CHANNEL,channel) == channel
    chA = BL_Acquire()

    # get second channel
    channel = 1
    assert BL_Select(BL_SELECT_CHANNEL,channel) == channel
    chB = BL_Acquire()

    BL_Close()

    # provide times samples were taken
    time = np.arange(0,1.0*samples/sample_rate,1.0/sample_rate)
    
    # print output: time (s), chA (V), chB (V)
    for t, chA, chB in zip(time, chA, chB):
        print '%f,%f,%f' % (t, chA, chB)

if __name__ == '__main__':
    # defaults
    samples = 5000
    sample_rate = 10000
    
    parser = argparse.ArgumentParser(description='Acquire data with BitScope on'
                                     ' channels A and B and print to stdout.')
    parser.add_argument('-n', dest='samples',
                        help='number of samples to acquire (default %i)'
                        % samples, type=int)
    parser.add_argument('-r', dest='sample_rate', help='samples/second (default'
                        ' %i)' % sample_rate, type=int)
    parser.add_argument('-header', help='print header row', action='store_true')
    args = parser.parse_args()

    if args.samples:
        samples = args.samples

    if args.sample_rate:
        sample_rate = args.sample_rate

    if args.header:
{'fraction_non_alphanumeric': 0.09147469312258281, 'fraction_numerical': 0.010089120564990752, 'mean_word_length': 2.685254027261462, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6046924', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1696, 'n_words': 605}