Beispiel #1
0
def initialize_scope():
    scope = niScope.Scope(dev)
    scope.ConfigureHorizontalTiming(**Horizontal)
    scope.ConfigureTrigger(**Trigger)
    #    scope.ConfigureVertical(**VerticalRef)
    scope.ConfigureVertical(**VerticalSample)
    return scope
Beispiel #2
0
 def initialize(self):
     try:
         self.scope = niScope.Scope(resourceName=self.DeviceName.value)
         logger.info('Initializing niScope')
     except Exception as e:
         logger.error(
             "Failed to initialize niScope (name: {}). Exception: {}".
             format(self.DeviceName.value, e))
         raise PauseError
     self.isInitialized = True
Beispiel #3
0
def configure_scope(mode, config):
    try:
        import niScope
    except Exception:
        print "niScope missing, continuing anyway"

    def fetch(self, memory):
        ch = config['VerticalSample']['channelList']
        logger.info("Fetching channel: %s" % ch)
        self.Fetch(ch, memory)

    niScope.Scope.fetch_sample_signal = fetch
    scope = niScope.Scope(config['dev'])
    scope.ConfigureHorizontalTiming(**config['Horizontal'])
    scope.ExportSignal(**config['ExportSignal'])
    scope.ConfigureTrigger(**config['Trigger'])
    scope.ConfigureVertical(**config['VerticalRef'])
    scope.ConfigureVertical(**config['VerticalSample'])
    return scope
import niScope
from nidaqmx import AnalogOutputTask
import numpy as np

scope = niScope.Scope("Dev4")
task = AnalogOutputTask()
task.create_voltage_channel("Dev3/ao3")
task.configure_timing_sample_clock(source="RTSI0")
data = np.sin(0.5*np.pi*np.arange(10000))**2
task.write(data)
scope.ConfigureHorizontalTiming(sampleRate=30000,numPts=1000000)
scope.ConfigureVertical()
scope.ConfigureTrigger("Edge")
scope.ExportSignal(signal=4, outputTerminal='VAL_RTSI_0')
raw_input("signal exported")
scope.Commit()
raw_input("committed")
scope.InitiateAcquisition()
raw_input("Acquisition initiated")
Beispiel #5
0
import niScope
import numpy as np
from time import sleep
import matplotlib.pyplot as plt
import timeit
X, Y, Z = 2420, 1000, 2
scope = niScope.Scope("Dev2")
scope.ConfigureHorizontalTiming(numPts=X,
                                sampleRate=40000000.0,
                                enforceRealtime=True,
                                numRecords=Y,
                                refPosition=0.0)
scope.ConfigureVertical(
    coupling=1,
    channelList="0",
    enabled=True,
    probeAttenuation=1.0,
    offset=0.0,
    voltageRange=10.0,
)
scope.ConfigureTrigger(
    "Edge",
    slope=1,
    delay=5.5e-06,
    triggerCoupling=1,
    level=0.0,
    triggerSource='VAL_EXTERNAL',
    holdoff=0.0,
)
scope.ExportSignal(
    signal=4,
Beispiel #6
0
def read_analog(
    Scope_slot,
    Scope_channels,
    DAQmx_channels,
    volt_range,
    samples_per_chan,
    sample_rate,
):
    """
    Simultaneous NI Scope / NI DAQmx acquisition
    """

    # Configure the scope
    scope = niScope.Scope(Scope_slot)
    scope.ConfigureClock("VAL_PXI_CLOCK", "VAL_NO_SOURCE", "VAL_RTSI_0", True)
    scope.ConfigureHorizontalTiming(sampleRate=sample_rate,
                                    numPts=samples_per_chan)
    scope.ConfigureVertical(channelList=Scope_channels,
                            voltageRange=volt_range)
    scope.ConfigureTrigger("Immediate")
    scope.ExportSignal(niScope.NISCOPE_VAL_REF_TRIGGER, "VAL_RTSI_1",
                       "VAL_RTSI_1")
    sampling = scope.ActualSamplingRate
    if sampling != sample_rate:
        print("Warning: sample rate changed to", sampling)

    # Configure DAQmx channels
    task = PyDAQmx.Task()
    for chan in DAQmx_channels:
        task.CreateAIVoltageChan(
            chan,
            "",
            PyDAQmx.DAQmx_Val_Diff,
            -volt_range,
            volt_range,
            PyDAQmx.DAQmx_Val_Volts,
            None,
        )
        task.SetChanAttribute(chan, PyDAQmx.DAQmx_AI_Coupling,
                              PyDAQmx.DAQmx_Val_DC)

    task.CfgDigEdgeStartTrig("RTSI1", PyDAQmx.DAQmx_Val_Rising)
    task.CfgSampClkTiming(
        "OnboardClock",
        sampling,
        PyDAQmx.DAQmx_Val_Rising,
        PyDAQmx.DAQmx_Val_FiniteSamps,
        samples_per_chan,
    )
    task.CfgInputBuffer(samples_per_chan)

    # Start DAQmx task and initiate Scope acquisition
    task.StartTask()
    scope.InitiateAcquisition()

    # Read scope data
    data_scope = scope.Fetch(Scope_channels)
    length = scope.ActualRecordLength
    print("NI-Scope: {:} samples read at {:} Hz".format(length, sampling))
    scope.close()

    # Read DAQmx data
    timeout = float(10 * samples_per_chan / sample_rate)
    buffer_size_in_samps = int(samples_per_chan * len(DAQmx_channels))
    data_daqmx = np.zeros((buffer_size_in_samps, ), dtype=np.float64)
    samples_per_chan_read = PyDAQmx.int32()
    task.ReadAnalogF64(
        samples_per_chan,
        timeout,
        PyDAQmx.DAQmx_Val_GroupByChannel,
        data_daqmx,
        buffer_size_in_samps,
        PyDAQmx.byref(samples_per_chan_read),
        None,
    )
    print("DAQmx: %d samples read." % samples_per_chan_read.value)

    return (data_scope, data_daqmx)
Beispiel #7
0
 def setUp(self):
     self.scope = niScope.Scope("Dev4")