triggering ScanImage with ACQ4 - using external reference clock

21 views
Skip to first unread message

Michael Graupner

unread,
Feb 26, 2019, 10:25:54 AM2/26/19
to ac...@googlegroups.com
Hello, 

I have outsourced the 2p scanning from ACQ4 to ScanImage was we are using a resonant scanner now. As for now, ACQ4 tells ScanImage with a TTL pulse when to start and stop imaging, which works nicely. In particular, this type of interaction is builtin in ScanImage and setting it up is straightforward. 

However, in order to achieve consistent timing between signals recorded in ScanImage and in ACQ4, I think I need to sync the reference clocks of the two NIDAQ cards in use. ScanImage runs on a NI PXI chassis while ACQ4 uses a NI PCIe card. There is a setting in ScanImage to export a 10Mhz Reference Clock. My idea was to syn the reference clock for tasks in ACQ4 with this reference clock. For example through the following code in configureClocks of SuperClass.py 

if refClkSrc :
    for k in self.tasks:
        self.tasks[k].SetRefClkRate(10e6)
        self.tasks[k].SetRefClkSrc(refClkSrc)

refClkSrc would be an option given with a 'NiDaq' device specifying the input terminal of the reference clock signal. 

Any thoughts or suggestions regarding the endeavor of communicating btw. ACQ4 and ScanImage or the clock synchronization would be greatly appreciated. Thanks in advance.

Best regards,
Michael 

Luke Campagnola

unread,
Feb 26, 2019, 11:59:55 AM2/26/19
to acq4
Sounds like you are on the right track, and it should be straightforward to implement. Taking it a few steps further, you can:
- Modify devices/NiDAQ/nidaq.py Task.configure:

          self.st.configureClocks(rate=self.cmd['rate'], nPts=self.cmd['numPts'], refClockSource=self.cmd.get('refClockSource', None))

- Add a ComboBox that lets you select the reference clock source to devices/NiDAQ/taskGui.py, which gets inserted into the command structure in NiDAQTask.generateTask().  

- Add a key to devices.cfg that will be used to populate the clock source combobox, like:

    DAQ:
        driver: 'NiDAQ'
        refClockSources:
            scanimage: '/Dev1/PFI3'

Does that all make sense?

--
You received this message because you are subscribed to the Google Groups "ACQ4" group.
To unsubscribe from this group and stop receiving emails from it, send an email to acq4+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/acq4/CAFVjdW%2BdJFoMstr4nFPTbz3Vu%3DocHaezhXkXJqDAjM%2B7eonvUQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Michael Graupner

unread,
Feb 26, 2019, 1:04:22 PM2/26/19
to ac...@googlegroups.com
Thank you for your prompt feedback, Luke !

I seems to work and the reference clocks look synced on the oscilloscope. So far so good. 

However, I get the following error when running a buffered task from the task manager and a monitor from the ACQ4 manager. The monitor regularly checks the state of pfi ports on the nidaq card. I don't understand the error as the monitor should not engage the refClockSource (and it doesn't which I checked with print-outs SuperTask.py). 

--------------
2019.02.26 18:57:59 Error in task thread, exiting. 

Error starting task:
Error starting device 'DAQ'; aborting task.
NIDAQError: NiDAQ Error while running function 'DAQmxWriteDigitalU32(153138680L, 40000L, False, 10.0, 0, <acq4.pyqtgraph.util.colorama.win32.LP_c_ulong object at 0x000000001EC6AD48>)':
Specified route cannot be satisfied, because it requires resources that are currently in use by another route.
Property: DAQmx_RefClk_Src
Source Device: Dev2
Source Terminal: PFI8

Required Resources in Use by
Task Name: _unnamedTask<13>
Source Device: Dev2
Source Terminal: None
Destination Device: Dev2
Destination Terminal: RefClockInternal

Task Name: _unnamedTask<15>

Status Code: -89137

Error starting task:
  File "acq4\util\Thread.py", line 23, in __run_wrapper
    self.__subclass_run()
  File "acq4\modules\TaskRunner\TaskRunner.py", line 973, in run
    printExc("Error in task thread, exiting.")
  File "acq4\util\debug.py", line 42, in printExc
    acq4.Manager.logExc(msg=msg, msgType=msgType)
------- exception caught ---------->
  File "acq4\modules\TaskRunner\TaskRunner.py", line 963, in run
    self.runOnce()
  File "acq4\modules\TaskRunner\TaskRunner.py", line 1046, in runOnce
    raise HelpfulException("\nError starting task:", exc)

Error starting device 'DAQ'; aborting task.
  File "acq4\modules\TaskRunner\TaskRunner.py", line 1032, in runOnce
    task.execute(block=False)
  File "acq4\Manager.py", line 975, in execute
    raise HelpfulException("Error starting device '%s'; aborting task." % devName)

NIDAQError: NiDAQ Error while running function 'DAQmxWriteDigitalU32(153138680L, 40000L, False, 10.0, 0, <acq4.pyqtgraph.util.colorama.win32.LP_c_ulong object at 0x000000001EC6AD48>)':
Specified route cannot be satisfied, because it requires resources that are currently in use by another route.
Property: DAQmx_RefClk_Src
Source Device: Dev2
Source Terminal: PFI8

Required Resources in Use by
Task Name: _unnamedTask<13>
Source Device: Dev2
Source Terminal: None
Destination Device: Dev2
Destination Terminal: RefClockInternal

Task Name: _unnamedTask<15>

Status Code: -89137
  File "acq4\Manager.py", line 972, in execute
    self.tasks[devName].start()
  File "acq4\devices\NiDAQ\nidaq.py", line 320, in start
    self.st.start()
  File "acq4\drivers\nidaq\SuperTask.py", line 349, in start
    self.writeTaskData()  ## Only writes if needed.
  File "acq4\drivers\nidaq\SuperTask.py", line 194, in writeTaskData
    self.tasks[k].write(d)
  File "acq4\drivers\nidaq\nidaq.py", line 396, in write
    nPts = getattr(self, fName)(data.size / numChans, False, timeout, LIB.Val_GroupByChannel, cbuf)
  File "acq4\drivers\nidaq\nidaq.py", line 286, in <lambda>
    return lambda *args: func(self.handle, *args)
  File "acq4\drivers\nidaq\nidaq.py", line 87, in <lambda>
    return lambda *args: self.call(attr, *args)
  File "acq4\drivers\nidaq\nidaq.py", line 116, in call
    raise NIDAQError(errCode, msg)

-------------------------

Thanks for having a look at this. 

Cheers,
Michael 








Luke Campagnola

unread,
Feb 26, 2019, 4:22:47 PM2/26/19
to Michael Graupner, ac...@googlegroups.com
I'm not sure about that .. I would start by (1) verifying that your monitor is indeed creating the SuperTask with the expected configuration, and (2) finding out whether the monitor and the TaskRunner task are attempting to run at the same time. If so, then I have some work to do figuring out why these two are not sharing hardware nicely.


Luke

From: ac...@googlegroups.com <ac...@googlegroups.com> on behalf of Michael Graupner <graupner...@gmail.com>
Sent: Tuesday, February 26, 2019 10:04 AM
To: ac...@googlegroups.com
Subject: Re: [acq4] triggering ScanImage with ACQ4 - using external reference clock
 
Reply all
Reply to author
Forward
0 new messages