Пример #1
0
 def add_channel(self, channel):
     """Add existing channel object to channels dict."""
     self.channels.append(channel)
     phys_chan = channel.physical_channel.encode()
     name = channel.name.encode()
     term_conf = daqmx.parameters[channel.terminal_config]
     maxval = channel.maxval
     minval = channel.minval
     units = daqmx.parameters[channel.units]
     cust_scale_name = channel.custom_scale_name
     if cust_scale_name:
         units = daqmx.Val_FromCustomScale
     if channel.channel_type.lower() == "analog input voltage":
         daqmx.CreateAIVoltageChan(self.handle, phys_chan, name, term_conf,
                                   minval, maxval, units, cust_scale_name)
         self.task_type = "analog input"
     elif channel.channel_type.lower() == "analog input bridge":
         bridge_config = daqmx.parameters[channel.bridge_config]
         voltage_exc_source = daqmx.parameters[channel.voltage_exc_source]
         voltage_exc_value = channel.voltage_exc_value
         nominal_bridge_resistance = channel.nominal_bridge_resistance
         daqmx.CreateAIBridgeChan(self.handle, phys_chan, name, minval,
                                  maxval, units, bridge_config,
                                  voltage_exc_source, voltage_exc_value,
                                  nominal_bridge_resistance,
                                  cust_scale_name)
         self.task_type = "analog input"
Пример #2
0
 def start_daq(self):
     # Task parameters
     self.th = daqmx.TaskHandle()
     daqmx.CreateTask("", self.th)
     self.sr = 100.0
         
     daqmx.CreateAIVoltageChan(self.th, self.phys_chan, "", 
                               daqmx.Val_Diff, -10.0, 10.0, 
                               daqmx.Val_Volts, None)  
     daqmx.CfgSampClkTiming(self.th, "", self.sr, daqmx.Val_Rising, 
                            daqmx.Val_ContSamps, 1000)
     daqmx.StartTask(self.th, fatalerror=False)
Пример #3
0
    def setup_DAQmx(self):
        # daqmx tasks
        self.AItask = daqmx.TaskHandle()
        self.AOtask = daqmx.TaskHandle()
        daqmx.CreateTask("", self.AItask)
        daqmx.CreateTask("", self.AOtask)
        # AI task setup
        for i in range(self.num_i):
            daqmx.CreateAIVoltageChan(self.AItask, self.i_channels[i], "", daqmx.Val_Diff,
                                  -10.0, 10.0, daqmx.Val_Volts, None) 

        daqmx.CfgSampClkTiming(self.AItask, "",  self.i_frequency, daqmx.Val_Rising, 
                                daqmx.Val_ContSamps, self.i_size)
        # AO task setup
        daqmx.CreateAOVoltageChan(self.AOtask, self.o_channel, "", 
                                -10.0, 10.0, daqmx.Val_Volts, None)
        daqmx.CfgSampClkTiming(self.AOtask, "", self.o_fre, daqmx.Val_Rising, 
                            daqmx.Val_ContSamps, self.o_buffer)
        daqmx.SetWriteRegenMode(self.AOtask,daqmx.Val_DoNotAllowRegen)     
Пример #4
0
    def setup_DAQmx(self):
        # daqmx tasks
        self.AItask = daqmx.TaskHandle()
        self.AOtask = daqmx.TaskHandle()
        daqmx.CreateTask("", self.AItask)
        daqmx.CreateTask("", self.AOtask)
        # AI task setup
        for i in range(self.NCH):
            daqmx.CreateAIVoltageChan(self.AItask, self.AIs[i], "", daqmx.Val_Diff,
                                  -10.0, 10.0, daqmx.Val_Volts, None) 

        daqmx.CfgSampClkTiming(self.AItask, "",  self.IF, daqmx.Val_Rising, 
                                daqmx.Val_ContSamps, self.ASS)
        # AO task setup
        daqmx.CreateAOVoltageChan(self.AOtask, self.O1, "", 
                                -10.0, 10.0, daqmx.Val_Volts, None)
        daqmx.CfgSampClkTiming(self.AOtask, "", self.OF, daqmx.Val_Rising, 
                            daqmx.Val_ContSamps, self.OB)
        daqmx.SetWriteRegenMode(self.AOtask,daqmx.Val_DoNotAllowRegen)     
Пример #5
0
daqmx.CreateTask("", AItaskHandle)
daqmx.CreateTask("", AOtaskHandle)

sr = 100.0

t = np.linspace(0, 100.0, 1000)
data = 2 * np.sin(t)

daqmx.CreateAOVoltageChan(AOtaskHandle, "Dev1/ao0", "", -10.0, 10.0,
                          daqmx.Val_Volts, None)

daqmx.CfgSampClkTiming(AOtaskHandle, "", sr, daqmx.Val_Rising,
                       daqmx.Val_ContSamps, 1000)

daqmx.CreateAIVoltageChan(AItaskHandle, "Dev1/ai1", "", daqmx.Val_Diff, -10.0,
                          10.0, daqmx.Val_Volts, None)

daqmx.CfgSampClkTiming(AItaskHandle, "", sr, daqmx.Val_Rising,
                       daqmx.Val_ContSamps, 1000)

written = daqmx.WriteAnalogF64(AOtaskHandle, 1000, 0, 10.0,
                               daqmx.Val_GroupByChannel, data)

dataread, nread = daqmx.ReadAnalogF64(AItaskHandle, 1000, 10.0,
                                      daqmx.Val_GroupByChannel, 1000, 1)

daqmx.StartTask(AOtaskHandle)
daqmx.StartTask(AItaskHandle)

print written, "samples written"
print nread, "samples read"
Пример #6
0
def main():

    # Task parameters
    taskhandle = daqmx.TaskHandle()
    daqmx.CreateTask("", taskhandle)
    phys_chan = b"Dev1/ai0"
    nchan = 1
    sr = 100.0
    dt = 1 / sr
    totaltime = 3
    nloops = int(sr * totaltime / 10)

    # Analog read parameters
    samps_per_chan = 10
    timeout = 10
    fillmode = daqmx.Val_GroupByChannel
    array_size_samps = 1000

    daqmx.CreateAIVoltageChan(taskhandle, phys_chan, "", daqmx.Val_Diff, -10.0,
                              10.0, daqmx.Val_Volts, None)

    daqmx.CfgSampClkTiming(taskhandle, "", sr, daqmx.Val_Rising,
                           daqmx.Val_ContSamps, 1000)

    # Parameters for plotting
    plotting = True
    plot_dynamic = True

    if plotting == True and plot_dynamic == True:
        plt.ioff()
        fig = plt.figure()
        ax = fig.add_subplot(111)
        line, = ax.plot([], )
        fig.show()

    daqmx.StartTask(taskhandle, fatalerror=False)

    v = np.array([])

    for n in range(nloops):
        data, spc = daqmx.ReadAnalogF64(taskhandle, samps_per_chan, timeout,
                                        fillmode, array_size_samps, nchan)
        v = np.append(v, data[:, 0])
        time.sleep(0.001)
        t = np.float64(range(len(v))) * dt

        if plotting == True and plot_dynamic == True:
            line.set_xdata(t)
            line.set_ydata(v)
            ax.relim()
            ax.autoscale_view()
            fig.canvas.draw()

    daqmx.ClearTask(taskhandle)
    print("Task complete")

    if plotting == True:
        if plot_dynamic == False:
            plt.plot(t, v)
    plt.show()

    return t, data
Пример #7
0
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 07 00:29:49 2013

@author: Pete
"""
import daqmx
import time
import numpy as np

aiTaskHandle = daqmx.TaskHandle()
diTaskHandle = daqmx.TaskHandle()

daqmx.CreateTask("", aiTaskHandle)
daqmx.CreateAIVoltageChan(aiTaskHandle, "Dev1/ai0", "", daqmx.Val_Diff, 0.0,
                          10.0, daqmx.Val_Volts)

daqmx.CfgSampClkTiming(aiTaskHandle, "", 100.0, daqmx.Val_Rising,
                       daqmx.Val_ContSamps, 1000)

trigname = daqmx.GetTerminalNameWithDevPrefix(aiTaskHandle, "ai/SampleClock")

daqmx.CreateTask("", diTaskHandle)
daqmx.CreateDIChan(diTaskHandle, "Dev1/port0", "", daqmx.Val_ChanForAllLines)
daqmx.CfgSampClkTiming(diTaskHandle, trigname, 100.0, daqmx.Val_Rising,
                       daqmx.Val_ContSamps, 1000)

daqmx.StartTask(diTaskHandle)
daqmx.StartTask(aiTaskHandle)

adata = daqmx.ReadAnalogF64(aiTaskHandle, 1000, 10.0, daqmx.Val_GroupByChannel,