def get_nburst(self, verbose=True): if verbose: self.debug('get nburst') v = 0 resp = self._send_query(22, 2, verbose=verbose) if resp is not None and len(resp) == 8: high = resp[4:] low = resp[:4] high = make_bitarray(int(high, 16), width=16) low = make_bitarray(int(low, 16), width=16) v = int(high + low, 2) return v
def _read_limits(self, verbose=False): cb = '00001000' inb = self.read_status(cb, verbose=False) if inb: # resp_byte consists of input_byte ba = make_bitarray(int(inb[2:-2], 16)) return ba
def get_process_status(self): ps = '0000000000000000' r = self._send_query(1000, 1) if r is not None: r = int(r, 16) ps = make_bitarray(r, width=16) return ps
def _moving(self, verbose=True): status_byte = self.read_defined_status(verbose=verbose) if status_byte in ('simulation', None): status_byte = 'DFDF' status_register = map(int, make_bitarray(int(status_byte[:2], 16))) return not status_register[7]
def get_process_status(self): #ps = '0000000000000000' r = self._send_query(1000, 1) self.debug('get process status {}'.format(r)) if r is not None: r = int(r, 16) ps = make_bitarray(r, width=16) return ps
def _moving(self, verbose=True): status_byte = self.read_defined_status(verbose=verbose) if status_byte == "simulation": status_byte = "DFDF" status_register = map(int, make_bitarray(int(status_byte[:2], 16))) return status_register[7]
def _moving(self, verbose=True): status_byte = self.read_defined_status(verbose=verbose) if status_byte == 'simulation': status_byte = 'DFDF' status_register = [int(bi) for bi in make_bitarray(int(status_byte[:2], 16))] return status_register[7]
def _make_integer_pair(self, n): try: n = int(n) except (ValueError, TypeError): return v = make_bitarray(n, width=32) h, l = int(v[:16], 2), int(v[16:], 2) return l, h
def _moving(self, verbose=True): status_byte = self.read_defined_status(verbose=verbose) if status_byte in ('simulation', None): status_byte = 'DFDF' status_register = [int(bi) for bi in make_bitarray(int.from_bytes(status_byte[:1], 'little'))] return not status_register[7]
def _moving(self, *args, **kw): ''' unidex 511 6-12 Serial Pol ''' cmd = 'Q' sb = self.ask(cmd, verbose=False) if sb is not None: # cover status bit to binstr b = make_bitarray(int(sb)) return int(b[2])
def _moving_(self, *args, **kw): ''' unidex 511 6-12 Serial Pol ''' cmd = 'Q' sb = self.ask(cmd, verbose=False) if sb is not None: # cover status bit to binstr b = make_bitarray(int(sb)) return int(b[2])
def get_contact_state(self, channel, bank=None, *args, **w): if bank is None: idx, bank = self._get_bank_idx(channel) else: idx = self._get_channel_idx(channel) cmdstr = self._make_cmdstr(254, 175, bank - 1) resp = self.ask(cmdstr, nchars=1) a = ord(resp) ba = make_bitarray(a) return bool(int(ba[8 - idx]))
def set_input_type(self, v): """ """ commandindex = "07" input_class = "00" # bits 7,6 meaningless for thermocouple bits = "00{}{}".format(make_bitarray(TC_KEYS.index(v), width=4), input_class) value = "{:02X}".format(int(bits, 2)) self._write_command(commandindex, value=value)
def set_input_type(self, v): ''' ''' commandindex = '07' input_class = '00' # bits 7,6 meaningless for thermocouple bits = '00{}{}'.format(make_bitarray(TC_KEYS.index(v), width=4), input_class) value = '{:02X}'.format(int(bits, 2)) self._write_command(commandindex, value=value)
def read_input_type(self): """ """ cmd = 'R', '07' re = self.repeat_command(cmd) self.debug('read input type {}'.format(re)) if re is not None: re = re.strip() re = make_bitarray(int(re, 16)) input_class = INPUT_CLASS_MAP[int(re[:2], 2)] if input_class == 'TC': self._input_type = TC_MAP[int(re[2:6], 2)] self.debug('Input Class={}'.format(input_class)) self.debug('Input Type={}'.format(self._input_type)) return True
def set_input_type(self, v): ''' ''' commandindex = '07' input_class = '00' # bits 7,6 meaningless for thermocouple bits = '00{}{}'.format(make_bitarray(TC_KEYS.index(v), width=4), input_class ) value = '{:02X}'.format(int(bits, 2)) self._write_command(commandindex, value=value)
def read_defined_status(self, verbose=True): addr = self.address cmd = '0E' cmd = self._build_command(addr, cmd) status_byte = self.ask(cmd, is_hex=True, delay=100, nbytes=2, info='get defined status', verbose=verbose) status_register = make_bitarray( int.from_bytes(status_byte[:1], 'little')) self.debug('Defined Status Byte={}'.format(status_register)) return status_byte
def get_faults(self, verbose=False, **kw): """ """ cmd = self._get_read_command_str(FAULT_BITS) resp = self.ask(cmd, nbytes=1, verbose=verbose) if self.simulation: resp = '0' # parse the fault byte fault_byte = make_bitarray(int.from_bytes(resp, 'big')) # faults = [] # for i, fault in enumerate(FAULTS_TABLE): # if fault and fault_byte[7 - i] == '1': # faults.append(fault) faults = [fault for i, fault in enumerate(FAULTS_TABLE) if fault and fault_byte[7 - i] == '1'] return faults
def get_faults(self, **kw): ''' ''' cmd = self._get_read_command_str(FAULT_BITS) resp = self.ask(cmd, nbytes=1) if self.simulation: resp = '0' # parse the fault byte fault_byte = make_bitarray(int(resp, 16)) # faults = [] # for i, fault in enumerate(FAULTS_TABLE): # if fault and fault_byte[7 - i] == '1': # faults.append(fault) faults = [fault for i, fault in enumerate(FAULTS_TABLE) if fault and fault_byte[7 - i] == '1'] return faults
def set_setpoint(self, v): ''' input temp in c thermorack whats f ''' if self.convert_to_C: v = 9 / 5. * v + 32 cmd = self._get_write_command_str(SETPOINT_BITS) self.write(cmd) data_bits = make_bitarray(int(v * 10), 16) high_byte = '{:02x}'.format(int(data_bits[:8], 2)) low_byte = '{:02x}'.format(int(data_bits[8:], 2)) self.write(low_byte) self.write(high_byte) return cmd, high_byte, low_byte
def read_input_type(self): ''' ''' # commandindex = '07' # com = self._build_command('R', commandindex) # re = self.ask(com) cmd = 'R', '07' re = self.repeat_command(cmd) if re is not None: re = re.strip() # strip off first three command characters # compare with sent command for error checking if re[:3] == 'R07': re = make_bitarray(int(re[3:], 16)) input_class = INPUT_CLASS_MAP[int(re[:2], 2)] if input_class == 'TC': self._input_type = TC_MAP[int(re[2:6], 2)] return True
def _moving(self, verbose=True): """ return True if motion is still in progress. @param verbose: @return: """ status_byte = self.read_defined_status(verbose=verbose) if status_byte in ('simulation', None): status_byte = b'\xdf\xdf' # else: # status_byte = binascii.hexlify(status_byte).decode('utf-8') # status_register = list(map(int, make_bitarray(int.from_bytes(status_byte[:1], 'little')))) status_register = [ int(i) for i in make_bitarray(int.from_bytes(status_byte[:1], 'little')) ] # status_register = list(map(int, make_bitarray(int.from_bytes(status_byte[:1], sys.byteorder)))) return not status_register[7]
def _moving(self, axis=None, verbose=False): """ use TX to read the controllers state. see manual 3-141 return value of P==0101000 bits 7654321 7,6,5=reserved 4=trajectory executing yes=1 return True if moving """ moving = False if axis is not None: if isinstance(axis, str): axis = self.axes[axis].id if self.mode == 'grouped': return self.group_moving() else: r = self.repeat_command(('MD?', axis), 5, check_type=int, verbose=verbose) if r is not None: # stage is moving if r==0 moving = not int(r) elif not self.simulation: r = self.repeat_command('TX', 5, check_type=str, verbose=verbose) if r is not None and len(r) > 0: controller_state = ord(r[0]) cs = make_bitarray(controller_state, width=8) moving = cs[3] == '1' else: time.sleep(0.5) return moving
def read_input_type(self): """ """ # commandindex = '07' # com = self._build_command('R', commandindex) # re = self.ask(com) # if self.multipoint: # cmd = '{}R'.format(self.address), '07' # else: # cmd = 'R', '07' cmd = 'R', '07' re = self.repeat_command(cmd) if re is not None: re = re.strip() if re[:3] == 'R07': re = make_bitarray(int(re[3:], 16)) input_class = INPUT_CLASS_MAP[int(re[:2], 2)] if input_class == 'TC': self._input_type = TC_MAP[int(re[2:6], 2)] self.debug('Input Class={}'.format(input_class)) self.debug('Input Type={}'.format(self._input_type)) return True
def read_input_type(self): """ """ # commandindex = '07' # com = self._build_command('R', commandindex) # re = self.ask(com) # if self.multipoint: # cmd = '{}R'.format(self.address), '07' # else: # cmd = 'R', '07' cmd = "R", "07" re = self.repeat_command(cmd) if re is not None: re = re.strip() if re[:3] == "R07": re = make_bitarray(int(re[3:], 16)) input_class = INPUT_CLASS_MAP[int(re[:2], 2)] if input_class == "TC": self._input_type = TC_MAP[int(re[2:6], 2)] self.debug("Input Class={}".format(input_class)) self.debug("Input Type={}".format(self._input_type)) return True
def _moving_(self, axis=None, verbose=False): ''' use TX to read the controllers state. see manual 3-141 return value of P==0101000 bits 7654321 7,6,5=reserved 4=trajectory executing yes=1 return True if moving ''' moving = False if axis is not None: if isinstance(axis, str): axis = self.axes[axis].id if self.mode == 'grouped': return self.group_moving() else: r = self.repeat_command(('MD?', axis), 5, check_type=int, verbose=verbose) if r is not None: # stage is moving if r==0 moving = not int(r) elif not self.simulation: r = self.repeat_command('TX', 5, check_type=str, verbose=verbose) if r is not None and len(r) > 0: controller_state = ord(r[0]) cs = make_bitarray(controller_state, width=8) moving = cs[3] == '1' else: time.sleep(0.5) return moving
def parse_categories(cint, av): v = map(int, make_bitarray(cint))[::-1] cs = [av[i] for i, vi in enumerate(v) if vi] return cs