コード例 #1
0
ファイル: controller.py プロジェクト: tapczan666/GUI_Analyzer
class USBController():
    def __init__(self):
        try:
            self.bb = BitBangDevice()
            self.bb.port = 0xFF
            self.state = self.bb.read_pins()
            self.attenuation = 0
            self.switch_1 = 1
            self.switch_2 = 1
            print self.state
        except:
            raise Exception("Failed to initialize USB controller")
            print "Failed to initialize USB controller. Please reconnect."
            
        
    def set_att(self, att):
        if att >=0 and att <=31:
            self.attenuation = att
            value = self.switch_1*32 + self.switch_2*64 + self.attenuation^0b11111
            self.bb.port = value
            self.state = self.bb.read_pins()
        else:
            print "Attenuation value out of range"
        
        
    def set_switches(self, a, b):
        if a in [0,1] and b in [0,1]:
            self.switch_1 = a
            self.switch_2 = b
            
            value = self.switch_1*32 + self.switch_2*64 + self.attenuation^0b11111
            self.bb.port = value
            self.state = self.bb.read_pins()
        else:
            print "Incorrent switch setting. Enter 0 or 1."
コード例 #2
0
ファイル: controller.py プロジェクト: tapczan666/GUI_Analyzer
class USBController():
    def __init__(self):
        try:
            self.bb = BitBangDevice()
            self.bb.port = 0xFF
            self.state = self.bb.read_pins()
            self.attenuation = 0
            self.switch_1 = 1
            self.switch_2 = 1
            print self.state
        except:
            raise Exception("Failed to initialize USB controller")
            print "Failed to initialize USB controller. Please reconnect."

    def set_att(self, att):
        if att >= 0 and att <= 31:
            self.attenuation = att
            value = self.switch_1 * 32 + self.switch_2 * 64 + self.attenuation ^ 0b11111
            self.bb.port = value
            self.state = self.bb.read_pins()
        else:
            print "Attenuation value out of range"

    def set_switches(self, a, b):
        if a in [0, 1] and b in [0, 1]:
            self.switch_1 = a
            self.switch_2 = b

            value = self.switch_1 * 32 + self.switch_2 * 64 + self.attenuation ^ 0b11111
            self.bb.port = value
            self.state = self.bb.read_pins()
        else:
            print "Incorrent switch setting. Enter 0 or 1."
コード例 #3
0
class RelaySwitcher(object):
    def __init__(self):
        try:
            self.ft245 = BitBangDevice()
        except:
            print 'It may be possible that your device it is not connected, check that and try again\n'
            sys.exit()
        self.__output_names = {"RELE1": 0, "RELE2": 1, "RELE3": 2, "RELE4": 3}

    def __del__(self):
        self.ft245.close()
        pass

    def set_sw_by_name(self, sw_names):
        output_numbers = [self.__output_names[i] for i in sw_names]
        output_word = [output_mask[i] for i in output_numbers]
        output_word = sum(output_word)
        self.ft245.port |= output_word

    def clear_sw_by_name(self, sw_names):
        output_numbers = [self.__output_names[i] for i in sw_names]
        output_word = [output_mask[i] for i in output_numbers]
        output_word = sum(output_word)^255
        self.ft245.port &= output_word

    def get_states(self):
        pins_status = self.ft245.read_pins()
        for k in sorted(self.__output_names.keys()):
            print "{}: {}\n".format(k,'ON'if output_mask[self.__output_names[k]]&pins_status else 'OFF')

    def set_names(self, rele1, rele2, rele3, rele4):
        self.__output_names = {rele1: 0, rele2: 1, rele3: 2, rele4: 3}
        return self.__output_names

    def get_names(self):
        return self.__output_names