10-31-2012 12:39 PM
I am trying to acquire 2 channels of analog data using SCAN_Op in Python. I call SCAN_Op directly after using ctypes to convert the function parameters. I only get data from one channel. I am looking for examples, or help.
ni=windll.nidaq32
c_intVector = numChans*c_int
sampleChans = c_intVector()
sampleGains = c_intVector()
for i in range(numChans):
sampleChans[i] = chans[i]
sampleGains[i] = gains[i]
self.DAQ_OpStatus = ni.SCAN_Op(sampleDeviceNumber, sampleNumChans, sampleChans, sampleGains, sampleBuffer, sampleNum, sampleRate, sampleScanRate)
Solved! Go to Solution.
11-01-2012 03:33 PM
ERamer,
What hardware and drivers are you using to acquire 2 channels of analog data?
I found another forum post that seems to have a similar issue here.
11-01-2012 03:56 PM
I am using a Windows XP computer and the windll.nidaq32 driver.The hardware is a DACPad-6020E. The programming language is Python and I am using ctypes to convert the Python parameters to the SCAN_Op function to int16. I think the problem is constructing arrays of int16 for the channel id's and the gain.
11-02-2012 08:16 AM
You should probably use c_int16 arrays instead of c_int:
c_intVector = numChans*c_int16
11-09-2012 03:46 PM
Theller, you are correct. Here is the code that works:
def SCAN_VOp (self, deviceNumber=1, numChans=2, chans=(0, 1), gains=(-1, -1), num=2, rate=1000.0, scanRate=0.0, numMuxBrds=0):
#print "Entering DAQ_VOp"
sampleDeviceNumber = c_int16(deviceNumber)
sampleNumChans = c_int16(numChans)
c_int16Vector = numChans*c_int16
sampleChans = c_int16Vector()
sampleGains = c_int16Vector()
for i in range(numChans):
sampleChans[i] = chans[i]
sampleGains[i] = gains[i]
sampleBuffer = create_string_buffer(2*num)
sampleNum = c_ulong(num)
sampleRate = c_double(rate)
sampleScanRate = c_double(scanRate)
sampleNumMuxBrds = c_int16(numMuxBrds)
#When DAQ_Op returns with an error number equal to zero, buffer contains the acquired data.
self.DAQ_OpStatus = ni.SCAN_Op(sampleDeviceNumber, sampleNumChans, sampleChans, sampleGains, sampleBuffer, sampleNum, sampleRate, sampleScanRate)
self.DAQ_OpStatus = ni.SCAN_Demux (sampleBuffer, sampleNum, sampleNumChans, sampleNumMuxBrds)
#convert buffer to scaled array
br = sampleBuffer.raw
fmt = 'h'*num
unpacked = unpack(fmt, br)
unpackedarray = array(unpacked)
ScaledArray = unpackedarray * ((self.max - self.min)/(2 ** self.bits))
#print "Leaving DAQ_VOp"
return self.DAQ_OpStatus, ScaledArray