Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronisation of two M devices

Hey, I need to measure synchronized on two M series devices. The implementation is written in Python, but using the C DLLs ("translated" via ctypes).

 

Analogous to the example found in the NI folders I used the following code snippet to realize the synchronization:

 

str1=string()
clkRate=float64()

CHK(nidaq.DAQmxSetRefClkSrc(OutTaskHandle,"OnboardClock"))
CHK(nidaq.DAQmxGetRefClkSrc(OutTaskHandle,str1,256))
CHK(nidaq.DAQmxGetRefClkRate(OutTaskHandle,ctypes.byref(clkRate)))
CHK(nidaq.DAQmxSetRefClkSrc(MasterTaskHandle,str1))
CHK(nidaq.DAQmxSetRefClkRate(MasterTaskHandle,clkRate))
CHK(nidaq.DAQmxSetRefClkSrc(SlaveTaskHandle,str1))
CHK(nidaq.DAQmxSetRefClkRate(SlaveTaskHandle,clkRate))

 CHK is an error analyzing function, which yields possible errors or warnings and breaks with a runtimeerror if necessary.

 

If I run a measurement the program terminates with the warning "NI-488 Table error" (errorcode 20). I can't find a useful explanation of what that is. Could you help me out here?

Also I can't find proper documentation about the DAQmxGetRefClkSrc command, especially what the arguments describe. Just copied that from the example, maybe that might cause the problems?

 

Would help me greatly, I am kinda stuck here. Thanks in advance.

Jakob

0 Kudos
Message 1 of 2
(2,816 Views)

Hi Jakob,

 

Python strings are immutable, so you need to pass a mutable buffer to DAQmxGetRefClkSrc(). You can use ctypes.create_string_buffer() to allocate one.

 

DAQmxGetRefClkSrc() has the following signature:

int32 __CFUNC DAQmxGetRefClkSrc(TaskHandle taskHandle, char *data, uInt32 bufferSize);

It writes the reference clock source string to the buffer that 'data' points to. 'bufferSize' must correspond to the size of the buffer. If you tell it your buffer size is 256 bytes when it's really 0 bytes, DAQmxGetRefClkSrc() will write past the end of the buffer, which may crash the Python interpreter or cause more subtle undefined behavior.

 

If you pass data=NULL and bufferSize=0, DAQmxGetRefClkSrc() returns the required buffer size (instead of returning an error code), so that your program knows how much room to allocate.

 

Brad

---
Brad Keryan
NI R&D
0 Kudos
Message 2 of 2
(2,809 Views)