I am using python, ctypes to talk to a National Instrument DAQ in a measurement setup. I am sometimes (yes sometimes) getting the error: OSError: exception: access violation reading 0x00007FFB1F945B50 (The code 0x00007FFB1F945B50 is a different one every time the error occurs). My Operating System is Windows 10, Python is 3.4. By 'sometimes' I mean that most of the times our measurements work fine but with the same settings roundabout every 40th time the above error occurs. In a first step I am intersted in how to reproduce this error, and understanding the nature of it´s origen. Which circumstances can lead to the effect that this error occurs sometimes only with the same settings.
The relevant part of Python Traceback is:
File "modulum.py", line 5422, in updateLaserIntensity
outthread = daqio.Output("Dev1/ao0", np.ones(10)*intensity_in_volts, 1e3, -10.0, 10.0) # setting channel ao1 of DAQ to given value
File "D:\development\codebase\daqio.py", line 209, in __init__
None))
OSError: exception: access violation reading 0x00007FFB1F945B50
The code of daqio.Output class is
class Output( threading.Thread ):
def __init__( self, target, waveform, sampleRate, Uoutmin, Uoutmax):
self.running = True
self.sampleRate = sampleRate
self.periodLength = len( waveform )
# target = 'Dev1/ao0' # obsolete, used as argument of init now
target = target.encode('ascii')
self.OUT = TaskHandle( 0 )
self.data = np.zeros( ( self.periodLength, ), dtype=np.float64 )
# convert waveform to a np array
for i in range( self.periodLength ):
self.data[ i ] = waveform[ i ]
# setup the DAQ hardware
try:
CHK(nidaq.DAQmxCreateTask("",
ctypes.byref( self.OUT )))
# global threadedTask
# threadedTask = self.OUT
# print('Output task is:', threadedTask)
print('')
except:
pass
print('Output Task creation failed, current task pointer is:', runningTask)
CHK(nidaq.DAQmxCreateAOVoltageChan( self.OUT,
target,
"",
float64(Uoutmin),
float64(Uoutmax),
DAQmx_Val_Volts,
None))
CHK(nidaq.DAQmxCfgSampClkTiming( self.OUT,
"",
float64(self.sampleRate),
DAQmx_Val_Rising,
DAQmx_Val_ContSamps,
uInt64(self.periodLength)))
CHK(nidaq.DAQmxWriteAnalogF64( self.OUT,
int32(self.periodLength),
0,
float64(-1),
DAQmx_Val_GroupByChannel,
self.data.ctypes.data,
None,
None))
threading.Thread.__init__( self )
self.runningThread = True
def run( self ):
# try:
# if self.runningThread == True:
CHK(nidaq.DAQmxStartTask( self.OUT ))
def stop( self ):
CHK(nidaq.DAQmxStopTask( self.OUT ))
CHK(nidaq.DAQmxClearTask( self.OUT ))
global threadedTask
threadedTask = TaskHandle( 0 )
nidaq is the DLL of the DAQ.
nidaq = ctypes.windll.LoadLibrary('nicaiu.dll')
Since this is an error which is hard to resolve due to it´s statistically occuring nature, I'd be very about about some help on this issue.