add a lot of current stuff
this is not (yet) in the frm2 repo Change-Id: Ia5b2996803c3dbb15b85ab1bc3a24717ac6297fb
This commit is contained in:
@ -247,3 +247,14 @@ def getfqdn(name=''):
|
||||
|
||||
def getGeneralConfig():
|
||||
return CONFIG
|
||||
|
||||
|
||||
def formatStatusBits(sword, labels, start=0):
|
||||
"""Return a list of labels according to bit state in `sword` starting
|
||||
with bit `start` and the first label in `labels`.
|
||||
"""
|
||||
result = []
|
||||
for i, lbl in enumerate(labels, start):
|
||||
if sword & (1 << i) and lbl:
|
||||
result.append(lbl)
|
||||
return result
|
||||
|
@ -125,6 +125,28 @@ class AsynConn:
|
||||
return None
|
||||
self._rxbuffer += data
|
||||
|
||||
def readbytes(self, nbytes, timeout=None):
|
||||
"""read one line
|
||||
|
||||
return either <nbytes> bytes or None if not enough data available within 1 sec (self.timeout)
|
||||
if a non-zero timeout is given, a timeout error is raised instead of returning None
|
||||
the timeout effectively used will not be lower than self.timeout (1 sec)
|
||||
"""
|
||||
if timeout:
|
||||
end = time.time() + timeout
|
||||
while len(self._rxbuffer) < nbytes:
|
||||
data = self.recv()
|
||||
if not data:
|
||||
if timeout:
|
||||
if time.time() < end:
|
||||
continue
|
||||
raise TimeoutError('timeout in readbytes (%g sec)' % timeout)
|
||||
return None
|
||||
self._rxbuffer += data
|
||||
line = self._rxbuffer[:nbytes]
|
||||
self._rxbuffer = self._rxbuffer[nbytes:]
|
||||
return line
|
||||
|
||||
def writeline(self, line):
|
||||
self.send(line + self.end_of_line)
|
||||
|
||||
@ -154,9 +176,10 @@ class AsynTcp(AsynConn):
|
||||
|
||||
def flush_recv(self):
|
||||
"""flush recv buffer"""
|
||||
data = []
|
||||
data = [self._rxbuffer]
|
||||
while select.select([self.connection], [], [], 0)[0]:
|
||||
data.append(self.recv())
|
||||
self._rxbuffer = b''
|
||||
return b''.join(data)
|
||||
|
||||
def recv(self):
|
||||
@ -244,7 +267,9 @@ class AsynSerial(AsynConn):
|
||||
self.connection.write(data)
|
||||
|
||||
def flush_recv(self):
|
||||
return self.connection.read(self.connection.in_waiting)
|
||||
result = self._rxbuffer + self.connection.read(self.connection.in_waiting)
|
||||
self._rxbuffer = b''
|
||||
return result
|
||||
|
||||
def recv(self):
|
||||
"""return bytes received within 1 sec"""
|
||||
|
@ -139,8 +139,11 @@ class Parameter(Accessible):
|
||||
datatype.setProperty('unit', unit)
|
||||
super(Parameter, self).__init__(**kwds)
|
||||
|
||||
if self.readonly and self.initwrite:
|
||||
raise ProgrammingError('can not have both readonly and initwrite!')
|
||||
if self.initwrite:
|
||||
if self.readonly:
|
||||
raise ProgrammingError('can not have both readonly and initwrite!')
|
||||
if not self.poll:
|
||||
raise ProgrammingError('only polled parameters can have initwrite!')
|
||||
|
||||
if self.constant is not None:
|
||||
self.properties['readonly'] = True
|
||||
|
Reference in New Issue
Block a user