I have a script running on loop which reads/writes from/to a U3 labjack every 0.1 seconds. I keep getting the following error:
Traceback (most recent call last):
File "ServoCompsToEPICS.py", line 74, in <module>
PVs[0].put(3.0/2.0*(PLL1.getAIN(1)-PLL1.getAIN(0)))#Subtract AIN0 to get rid of GND offset
File "/usr/local/lib/python2.7/dist-packages/u3.py", line 567, in getAIN
bits = self.getFeedback(AIN(posChannel, negChannel, longSettle, quickSample))[0]
File "/usr/local/lib/python2.7/dist-packages/u3.py", line 740, in getFeedback
rcvBuffer = self._writeRead(sendBuffer, readLen, [], checkBytes = False, stream = False, checksum = True)
File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 541, in _writeRead
self.write(command, checksum = checksum)
File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 264, in write
wb = self._writeToExodriver(writeBuffer, modbus)
File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 214, in _writeToExodriver
raise LabJackException( "Could only write %s of %s bytes." % (writeBytes, len(writeBuffer) ) )
LabJackPython.LabJackException: Could only write 0 of 10 bytes.
This seems to be an error which occured while reading an analog output. Sometimes the program hangs up while writing the DAC and Digital output channels as well (I get the same error). The code for this loop is below. I'm fairly new to this. Am I doing anything obviously wrong, or do you have any suggestions on how I can make this more robust? Please let me know
while True:
PVs[0].put(3.0/2.0*(PLL1.getAIN(1)-PLL1.getAIN(0)))#Subtract AIN0 to get rid of GND offset
PVs[1].put(3.0/2.0*(PLL1.getAIN(2)-PLL1.getAIN(0)))#Multiply by 3/2 to account for 0.667 AA filter gain
PVs[2].put(3.0/2.0*(PLL1.getAIN(3)-PLL1.getAIN(0)))
#Set Binary Outputs
for i in BOUTChans:
if (i==5 or i==6):
iVal = not(PVs[i-1].get())
PLL1.setDOState(i,iVal) #Correct for error on Servo comps for boost En logic
else:
iVal = PVs[i-1].get()
PLL1.setDOState(i,iVal)
#Set DAC Outputs
InOfsCurrent = PVs[14].get()
if InOfsCurrent != InOfsOld:
PLL1.writeRegister(5000,CalcDACOutput(InOfsCurrent)) #Input Offset
InOfsOld = InOfsCurrent
OutOfsCurrent = PVs[15].get()
if OutOfsCurrent != OutOfsOld:
PLL1.writeRegister(5002,CalcDACOutput(OutOfsCurrent)) #Output Offset
OutOfsOld = OutOfsCurrent
#If Gain has changed, Set PWM duty cycle based on desired Gain
GainCurrent=PVs[7].get()
if GainCurrent != GainOld:
PLL1.getFeedback(u3.Timer0(Value=CalcPWMValue(GainCurrent),UpdateReset=True))
GainOld = GainCurrent
sleep(0.1)