def get_scopedata(self, out='SHAPED'): """Reads digital oscilloscope readout data. Args: out (str): The type of output signal to display on the scope. Raises: ValueError: `out` is not one of 'SHAPED', 'FAST', 'INPUT' or 'PEAK'. Returns: A tuple of two lists: (time, voltages) where `time` is in ms and `voltages` is in volts. """ if out.upper() not in ('SHAPED', 'FAST', 'INPUT', 'PEAK'): raise ValueError('Invalid output type') self.set_setting('DACO', out.upper()) reply = self.send(DP5Command(pids.GETSCOPE)) if reply.pid not in (pids.SCOPEDATA, pids.SCOPE_OVFL): raise UnexpectedReplyError(reply.pid) voltages = [byte2int(byte)/256. for byte in reply.data] fpga_clock = self.get_status()['clock_MHz'] if fpga_clock == 20: tb_dict = pids.SCOPE_TB_FPGA20 elif fpga_clock == 80: tb_dict = pids.SCOPE_TB_FPGA80 peaktime = float(self.get_setting('TPEA')) for key, value in tb_dict.iteritems(): if key[0] <= peaktime <= key[1]: timebase = value break time = [timebase*i for i in range(len(reply.data))] return time, voltages
def get_status(self): """Requests a status packet from the detector. Returns (dict): Parsed detector status information.""" reply = self.send(pids.GETSTAT) if reply.pid != pids.STATUS: raise UnexpectedReplyError(reply.pid) return parse_status(reply.data)
def clear_spectrum(self): """Clears the current MCA spectrum. Raises: UnexpectedReplyError: Device reply is not an Ack OK packet. """ reply = self.send(DP5Command(pids.CLRSPEC)) if reply.pid != pids.ACK_OK: raise UnexpectedReplyError(reply.pid)
def disable_mca(self): """Disables the MCA. Raises: UnexpectedReplyError: Device reply is not an Ack OK packet. """ reply = self.send(DP5Command(pids.DISMCA)) if reply.pid != pids.ACK_OK: raise UnexpectedReplyError(reply.pid)
def get_settings_dict(self, params_list): data = '' for param in params_list: data += param.upper() + ';' command = DP5Command(pids.CONFIG_REQ, data) reply = self.send(command) if reply.pid != pids.CONFIG_READ: raise UnexpectedReplyError(reply.pid) res = reply.data.rstrip(';').split(';') settings_dict = {} for s in res: key, value = s.split('=') settings_dict[key] = value return settings_dict
def get_spectrum(self): """Requests the spectrum in the buffer and status packet. Raises: UnexpectedReplyError: Reply is not a spectrum + status packet. Returns: A Spectrum object representing the reply received. """ reply = self.send(DP5Command(pids.GETSPECSTAT)) try: numchans = pids.SPEC_CHAN[reply.pid] except KeyError: raise UnexpectedReplyError(reply.pid) specdata = reply.data[:numchans*3] spectrum = [byte2int(specdata[i:i+3]) for i in range(0,len(specdata),3)] statdata = reply.data[numchans*3:] status = parse_status(statdata) return spectrum, status
def set_setting(self, param, value): """Sets the value of an ASCII setting parameter. Args: param(str): A 4 character ASCII string representing the setting to be edited. value: A number or string representing the value of the parameter to be set. Will be converted to a string. Raises: UnexpectedReplyError: Device returns an unexpected reply. Returns: A string representing the resulting parameter value pair. See DP5 Programmer's Guide section 5 for possible parameters and their allowed values. """ data = "{0}={1};".format(param.upper(), str(value)) command1 = DP5Command(pids.CONFIG, data) reply1 = self.send(command1) if reply1.pid != pids.ACK_OK: raise UnexpectedReplyError(reply1.pid)
def get_setting(self, arg): """Returns the value of a list of ASCII parameters. Args: arg: Either a list of four letter parameter strings, or a single string with parameters separated by semicolons. Raises: UnexpectedReplyError: Device returns an unexpected reply. Returns: A string containing the values of the requested parameters. See Section 5.1 in the DP5 Programmer's Guide for a list of allowed parameters. """ param = arg.upper() + ';' command = DP5Command(pids.CONFIG_REQ, param) reply = self.send(command) if reply.pid != pids.CONFIG_READ: raise UnexpectedReplyError(reply.pid) res = reply.data.rstrip(';').split('=')[1] return res
def arm_scope(self): """Arms the digital oscilloscope.""" reply = self.send(DP5Command(pids.ARMSCOPE)) if reply.pid != pids.ACK_OK: raise UnexpectedReplyError(reply.pid)