示例#1
0
文件: wavegen.py 项目: whmrtm/daqmx
def main(period):
    taskHandle = daqmx.TaskHandle()
    daqmx.CreateTask("", taskHandle)

    physicalChannel = "Dev1/ao0"

    t = np.linspace(0, 2 * pi / period, 1000)
    data = 2 * np.sin(t)

    daqmx.CreateAOVoltageChan(taskHandle, physicalChannel, "", -10.0, 10.0,
                              daqmx.Val_Volts, None)

    daqmx.CfgSampClkTiming(taskHandle, "", 1000.0, daqmx.Val_Rising,
                           daqmx.Val_ContSamps, 1000)

    daqmx.WriteAnalogF64(taskHandle, 1000, 0, 10.0, daqmx.Val_GroupByChannel,
                         data)

    daqmx.StartTask(taskHandle)

    for n in range(100):
        time.sleep(0.3)

    daqmx.StopTask(taskHandle)
    daqmx.ClearTask(taskHandle)
示例#2
0
    def run(self):
        self.wavegen.enable = False

        while not self.wavegen.rampeddown:
            time.sleep(0.2)

        daqmx.ClearTask(self.wavegen.AOtaskHandle)
        self.wavegen.cleared = True
示例#3
0
def main():

    # Initializing task
    taskhandle = daqmx.TaskHandle()
    daqmx.CreateTask("", taskhandle)
    phys_chan = "Dev1/ctr0"

    #Timing parameters
    rate = 200.0
    initialdelay = 0
    lowtime = 1 / rate / 2
    hightime = 1 / rate / 2

    daqmx.CreateCOPulseChanTime(taskhandle, phys_chan, "", daqmx.Val_Seconds,
                                daqmx.Val_Low, initialdelay, lowtime, hightime,
                                False)

    print "Sending trigger pulse to", phys_chan + "..."
    daqmx.StartTask(taskhandle, fatalerror=True)
    print "Success!"

    daqmx.WaitUntilTaskDone(taskhandle, timeout=10, fatalerror=False)
    daqmx.ClearTask(taskhandle, fatalerror=False)
示例#4
0
def main():

    taskhandle = daqmx.TaskHandle()

    daqmx.CreateTask("", taskhandle)
    phys_chan = "cDAQ9188-16D66BBMod3/ctr2"
    globalchan = "VecPulse"

    #Timing parameters
    rate = 200  # Pulse rate in Hz
    initialdelay = 0
    lowtime = 1 / rate / 2
    hightime = 1 / rate / 2

    #    daqmx.CreateCOPulseChanTime(taskhandle, phys_chan, "", daqmx.Val_Seconds,
    #                                daqmx.Val_Low, initialdelay, lowtime, hightime,
    #                                False)

    daqmx.AddGlobalChansToTask(taskhandle, globalchan)

    daqmx.CfgImplicitTiming(taskhandle, daqmx.Val_FiniteSamps, 1)

    # Set up communication with motion controller
    simulator = False

    # Parameters for plotting
    plotting = False
    plot_dynamic = False

    if simulator == True:
        hcomm = acsc.OpenCommDirect()
    else:
        hcomm = acsc.OpenCommEthernetTCP("10.0.0.100", 701)

    axis = 5
    buffno = 7
    target = 0
    timeout = 10

    # Initialize arrays for storing time and position
    t = np.array(0)
    x = np.array(0)

    if plotting == True and plot_dynamic == True:
        plt.ioff()
        fig = plt.figure()
        ax = fig.add_subplot(111)
        #    plt.xlim(0, timeout)
        #    plt.ylim(0, target)
        line, = ax.plot([], [])
        fig.show()

    if hcomm == acsc.INVALID:
        print "Cannot connect to controller. Error:", acsc.GetLastError()

    else:
        #        acsc.Enable(hcomm, axis)
        rpos = acsc.GetRPosition(hcomm, axis)
        x = rpos
        t0 = time.time()

        if simulator == True:
            acsc.ToPoint(hcomm, 0, axis, target + 50000)
        else:
            acsc.RunBuffer(hcomm, buffno, None, None)

        while True:
            rpos = acsc.GetRPosition(hcomm, axis)
            if rpos >= target: break
            x = np.append(x, rpos)
            t = np.append(t, time.time() - t0)

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

            print "Axis is", acsc.GetAxisState(hcomm, axis) + '...'

            if time.time() - t0 > timeout:
                print "Motion timeout"
                print "Final axis position:", rpos
                break

            time.sleep(0.001)

        print "Target reached. Sending trigger pulse to", globalchan + "..."

        daqmx.StartTask(taskhandle, fatalerror=False)
        daqmx.WaitUntilTaskDone(taskhandle, timeout=10, fatalerror=False)

    daqmx.ClearTask(taskhandle, fatalerror=False)
    acsc.CloseComm(hcomm)

    print "Triggered at", np.max(x)

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

    return t, x
示例#5
0
 def stop_DAQmx(self):
     daqmx.StopTask(self.AOtask)
     daqmx.StopTask(self.AItask)
     daqmx.ClearTask(self.AItask)
     daqmx.ClearTask(self.AOtask)
示例#6
0
文件: tasks.py 项目: whmrtm/daqmx
 def clear(self):
     daqmx.ClearTask(self.handle)
示例#7
0
 def clear(self):
     daqmx.ClearTask(self.th)
示例#8
0
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"

plt.plot(dataread)

daqmx.StopTask(AItaskHandle)
daqmx.ClearTask(AItaskHandle)
daqmx.StopTask(AOtaskHandle)
daqmx.ClearTask(AOtaskHandle)
示例#9
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
示例#10
0
文件: tests.py 项目: whmrtm/daqmx
def test_global_virtual_channel():
    th = daqmx.TaskHandle()
    daqmx.CreateTask("", th)
    daqmx.AddGlobalChansToTask(th, "drag_left")
    daqmx.AddGlobalChansToTask(th, ["drag_right", "torque_trans"])
    daqmx.ClearTask(th)
示例#11
0
文件: tests.py 项目: whmrtm/daqmx
 def clear(self):
     self.stopdaq()
     daqmx.ClearTask(self.analogtask)
     daqmx.ClearTask(self.carpostask)
     daqmx.ClearTask(self.turbangtask)
     self.collect = False
示例#12
0
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,
                            1000, 1)
ddata = daqmx.ReadDigitalU32(diTaskHandle, 1000, 10.0,
                             daqmx.Val_GroupByChannel, 1000, 1)

print adata
print ddata

daqmx.StopTask(diTaskHandle)
daqmx.StopTask(aiTaskHandle)
daqmx.ClearTask(diTaskHandle)
daqmx.ClearTask(aiTaskHandle)