39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import serial
|
|
import time
|
|
import traceback
|
|
|
|
from frappy.core import Readable, Parameter, FloatRange, HasIO, StringIO, Property, IntRange, IDLE, BUSY, WARN, ERROR, Drivable, BoolType, Attached
|
|
|
|
class TSSOP16_IO(StringIO):
|
|
end_of_line = '\r'
|
|
wait_before = 3.0
|
|
timeout=1
|
|
identification = [ ('*IDN?', r'0x48,ACM1219,.*') ]
|
|
|
|
class TSSOP16(HasIO, Readable):
|
|
'''only configured for channel 1'''
|
|
|
|
ioClass = TSSOP16_IO
|
|
value = Parameter('value', FloatRange(unit='pF'), readonly=True, default=-1)
|
|
pollinterval = Parameter(default=1)
|
|
|
|
def custom_read_off_cvt(self, recursive_layer=0):
|
|
try:
|
|
l = self.communicate('readCVT')
|
|
vals = l.split(',')
|
|
vals = [ float(v) for v in vals ]
|
|
return vals[0]
|
|
except:
|
|
print('Retrying: ', recursive_layer+1)
|
|
traceback.print_exc()
|
|
self.io.closeConnection()
|
|
self.io.connectStart()
|
|
#time.sleep(3.0)
|
|
if(recursive_layer > 2):
|
|
return -1
|
|
else:
|
|
return self.custom_read_off_cvt(recursive_layer+1)
|
|
|
|
def read_value(self):
|
|
res = self.custom_read_off_cvt()
|
|
return res |