fix issue sending numbers in exp. format
numbers must be fixed point, with maximum 8 digits
This commit is contained in:
parent
cf42119f85
commit
7379ea91e5
@ -40,7 +40,8 @@ class PhytronIO(StringIO):
|
|||||||
_, _, reply = super().communicate('\x02' + command).partition('\x02')
|
_, _, reply = super().communicate('\x02' + command).partition('\x02')
|
||||||
if reply[0] == '\x06': # ACK
|
if reply[0] == '\x06': # ACK
|
||||||
break
|
break
|
||||||
raise CommunicationFailedError('missing ACK %r' % reply)
|
raise CommunicationFailedError('missing ACK %r (cmd: %r)'
|
||||||
|
% (reply, command))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if ntry == 1:
|
if ntry == 1:
|
||||||
raise
|
raise
|
||||||
@ -87,10 +88,19 @@ class Motor(PersistentMixin, HasIO, Drivable):
|
|||||||
self.loadParameters()
|
self.loadParameters()
|
||||||
|
|
||||||
def get(self, cmd):
|
def get(self, cmd):
|
||||||
return self.communicate('\x02%x%s%s' % (self.address, self.axis, cmd))
|
return self.communicate('%x%s%s' % (self.address, self.axis, cmd))
|
||||||
|
|
||||||
def set(self, cmd, value):
|
def set(self, cmd, value):
|
||||||
self.communicate('\x02%x%s%s%g' % (self.address, self.axis, cmd, value))
|
# make sure e format is not used, max 8 characters
|
||||||
|
strvalue = '%.6g' % value
|
||||||
|
if 'e' in strvalue:
|
||||||
|
if abs(value) <= 1: # very small number
|
||||||
|
strvalue = '%.7f' % value
|
||||||
|
elif abs(value) < 99999999: # big number
|
||||||
|
strvalue = '%.0f' % value
|
||||||
|
else:
|
||||||
|
raise ValueError('number (%g) must not have more than 8 digits' % value)
|
||||||
|
self.communicate('%x%s%s%s' % (self.address, self.axis, cmd, strvalue))
|
||||||
|
|
||||||
def set_get(self, cmd, value, query):
|
def set_get(self, cmd, value, query):
|
||||||
self.set(cmd, value)
|
self.set(cmd, value)
|
||||||
@ -103,7 +113,7 @@ class Motor(PersistentMixin, HasIO, Drivable):
|
|||||||
enc = self.read_encoder()
|
enc = self.read_encoder()
|
||||||
else:
|
else:
|
||||||
enc = pos
|
enc = pos
|
||||||
status = self.communicate('\x02%xSE' % self.address)
|
status = self.communicate('%xSE' % self.address)
|
||||||
status = status[0:4] if self.axis == 'X' else status[4:8]
|
status = status[0:4] if self.axis == 'X' else status[4:8]
|
||||||
self.log.debug('run %s enc %s end %s', status[1], status[2], status[3])
|
self.log.debug('run %s enc %s end %s', status[1], status[2], status[3])
|
||||||
status = self.get('=H')
|
status = self.get('=H')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user