コード例 #1
0
def main():
    config_filename = "GBS20V1_I2C_Config.txt"  # need to change by users
    COM_Port = "COM3"  # need to change according com port

    I2C_Addr = 0x20
    Reg_Addr = []
    Reg_Val = []
    with open(config_filename, 'r') as infile:  # read configuration file
        for line in infile.readlines():
            if len(line.split()) == 1:  # read I2C address
                I2C_Addr = hex(int(line.split()[0], 16))
            else:  # read register address and value
                Reg_Addr += [int(line.split()[0], 16)]
                Reg_Val += [int(line.split()[1], 16)]

    print(Reg_Addr)
    print(Reg_Val)

    # set usb-iss iic master device
    iss = UsbIss()
    iss.open(COM_Port)
    iss.setup_i2c()

    regWritelen = 16

    for i in range(regWritelen):  # write data into i2c slave
        print(I2C_Addr, hex(Reg_Addr[i]), hex(Reg_Val[i]))
        iss.i2c.write(I2C_Addr, Reg_Addr[i], Reg_Val[i])
        time.sleep(0.02)

    regReadlen = 17
    read_data = []
    read_data = Reg_Val
    for i in range(regReadlen):  # read data from i2c slave
        read_data += [iss.i2c.read(I2C_Addr, Reg_Addr[i], 1)]
        time.sleep(0.02)

    # compare write in data with read back data
    print('Check write-in registers:')
    for i in range(regWritelen):
        if Reg_Val[i] != read_data[i]:
            print("Read-back didn't match with write-in: {} {} {}".format(
                hex(Reg_Addr[i]), hex(Reg_Val[i]), hex(read_data[i])))
    print('Write-in data check finisehd')

    # check read-only register data
    print('Read read-only registers:')
    for i in range(regWritelen, regReadlen):
        print(hex(Reg_Addr[i]), hex(read_data[i]))

    for i in range(
            3
    ):  # if read back data matched with write in data, speaker will make a sound three times
        winsound.Beep(freqency, duration)
        time.sleep(0.01)

    print("Ok!")
コード例 #2
0
def main():
    ## set usb-iss iic master device
    slave_addr = 0x23
    iss = UsbIss()
    iss.open("COM3")
    iss.setup_i2c()

    ## GBCR2 Register mapping 


    iss.i2c.write(slave_addr, 0, [0, 1, 2])

    data = iss.i2c.read(slave_addr, 0, 3)
    print(data)
    print("Ok!!!")
コード例 #3
0
def main():
    config_filename = "GBS20_I2C_Config.txt"  # need to change by users
    COM_Port = "COM3"

    I2C_Addr = 0x22
    Reg_Addr = []
    Reg_Val = []
    with open(config_filename, 'r') as infile:  # read configuration file
        for line in infile.readlines():
            if len(line.split()) == 1:  # read I2C address
                I2C_Addr = hex(int(line.split()[0], 16))
            else:  # read register address and value
                Reg_Addr += [int(line.split()[0], 16)]
                Reg_Val += [int(line.split()[1], 16)]

    # set usb-iss iic master device
    iss = UsbIss()
    iss.open(COM_Port)
    iss.setup_i2c()

    for i in range(len(Reg_Addr)):  # write data into i2c slave
        iss.i2c.write(I2C_Addr, Reg_Addr[i], Reg_Val[i])
        time.sleep(0.02)

    read_data = []
    for i in range(len(Reg_Addr)):  # read data from i2c slave
        read_data += [iss.i2c.read(I2C_Addr, Reg_Addr[i], 1)]
        time.sleep(0.02)

    ## compare write in data with read back data
    if Reg_Val == Reg_Val:
        print("Read back data matched with write in data")
        for i in range(
                3
        ):  # if read back data matched with write in data, speaker will make a sound three times
            winsound.Beep(freqency, duration)
            time.sleep(0.01)
    else:
        print("Read back data didn't match with write in data"
              )  #print reg_add, write data, read back data
        for i in range(len(Reg_Addr)):
            if Reg_Val[i] != read_data[i]:
                print(Reg_Addr[i], Reg_Val[i], read_data[i])

    print("Ok!")
コード例 #4
0
def main():
    rm = visa.ResourceManager()
    inst1 = rm.open_resource('USB0::0x2A8D::0x1102::MY58041595::0::INSTR')      # top power supply
    inst1.write("*RST")
    inst1.write("SOURce:VOLTage 1.2,(@1)")                                      # top channel 1
    inst1.write("SOURce:CURRent 0.2,(@1)")
    inst1.write("OUTPut:STATe ON,(@1)")                                         # enable bottom channel 1
    time.sleep(2)
    iss = UsbIss()
    iss.open("COM3")
    iss.setup_i2c(clock_khz=100, use_i2c_hardware=True, io1_type=None, io2_type=None)
    I2C_Addr = 0X23
    Chip_ID = int(sys.argv[1])
    print("Chip %d is being testing!!!"%Chip_ID)
    CH_ID = 4
    GBCR2_Reg1 = GBCR2_Reg()
    CH_Dis_Rx = 0
    CH_CML_AmplSel = 5
    CH_Dis_EQ_LF = 0
    CH_EQ_ATT = 3
    CH_CTLE_HFSR = 7
    CH_CTLE_MFSR = 10
    CH_Dis_DFF = 1
    CH_Dis_LPF = 0

    GBCR2_Reg1.set_CH4_CML_AmplSel(CH_CML_AmplSel)
    GBCR2_Reg1.set_CH4_CTLE_MFSR(CH_CTLE_MFSR)
    GBCR2_Reg1.set_CH4_CTLE_HFSR(CH_CTLE_HFSR)
    filename = "Chip=%1d_CH%1d_Dis_Rx=0_CML_AmplSel=%1d_Dis_EQ_LF=0_EQ_ATT=3_CTLE_HFSR=%02d_CTLE_MFSR=%02d_Dis_DFF=1_Dis_LPF=0"%(Chip_ID,CH_ID,CH_CML_AmplSel,CH_CTLE_HFSR,CH_CTLE_MFSR)
    print(filename)
    Reg_Write_val = GBCR2_Reg1.get_config_vector()
    print(Reg_Write_val)
    iss.i2c.write(I2C_Addr, 0, Reg_Write_val)
    Reg_Read_val = []
    Reg_Read_val = iss.i2c.read(I2C_Addr, 0, 0x20)
    print("GBCR2 I2C Read Back data:")
    print(Reg_Read_val)
    print("\n")
    Hist_Std_Dev = capture_screen_image(filename)
    time.sleep(1)
    # inst1.write("OUTPut:STATe OFF,(@1)")                                         # enable bottom channel 1
    winsound.Beep(freqency, duration)
コード例 #5
0
def button_read():
    COM_Port = Run_entry[0].get()
    I2C_Addr = int(Run_entry[1].get(), 0)

    # set usb-iss iic master device
    iss = UsbIss()
    iss.open(COM_Port)
    iss.setup_i2c(clock_khz=100)

    # check read-only register data
    print('Read read-only registers:')
    readonlyReg_Addr = [0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26]
    readonlyReg_Val = []
    for i in range(len(readonlyReg_Addr)):                              # read data from i2c slave
        readonlyReg_Val += iss.i2c.read(I2C_Addr, readonlyReg_Addr[i], 1)
        time.sleep(0.02)
    for i in range(len(readonlyReg_Addr)):
        print(hex(readonlyReg_Addr[i]), hex(readonlyReg_Val[i]))

    # 'AFCcalCap<5:0>', 'AFCbusy', 'INSTLOCK_PLL', 'PA0_testEdge<0>', 'PA1_testEdge<0>'
    global Readonly_var
    Readonly_var[0].set( str(readonlyReg_Val[0]) )
    Readonly_var[1].set( str(readonlyReg_Val[1]) )
    Readonly_var[2].set( str(readonlyReg_Val[2]) )
    Readonly_var[3].set( str(readonlyReg_Val[5]) )
    Readonly_var[4].set( str(readonlyReg_Val[6]) )

    PA0_binary = '{0:08b}'.format(readonlyReg_Val[3])
    global Readonly2_var
    for i in range(8):
        Readonly2_var[Readonly2_item[0]][i].set( PA0_binary[i] )

    PA1_binary = '{0:08b}'.format(readonlyReg_Val[4])
    global Readonly3_var
    for i in range(8):
        Readonly3_var[Readonly3_item[0]][i].set( PA1_binary[i] )

    return
コード例 #6
0
class I2C_ISS(object):
    """
        self.port : ex. "COM1"\n
        self.Slave_Addr : Input slave address(8-bit Address).\n
        self.print_debug : Print log = 1; Not to print log = 0; \n
        """
    def __init__(self, port, print_debug=0, Slave_Addr=0xA0, speed=400):
        self.port = port
        # 7bit Address
        self.Slave_Addr = (Slave_Addr >> 1)
        self.print_debug = print_debug
        self.speed = speed

        self.iss = UsbIss()
        self.iss.open(self.port)
        self.iss.setup_i2c(self.speed)
        #print ("[Interface] Open ") + self.port + "\n"

    def ISS_PORT_CLOSE(self):
        self.iss.close()

    # Basic Function
    def I2C_READ(self, address, number):
        """
        USB-ISS Read
        # byte must be in range(0, 256)
        """
        data = [0] * number
        start = 0
        end = 0
        while (number > 0):
            if number < 60:
                end += number
                #if self.print_debug == 1:
                #print "start = ", start, "end = ", end, "address = ", address, "number = ", number
                data[start:end] = self.iss.i2c.read(self.Slave_Addr, address,
                                                    number)
                break
            else:
                end += 60
                #if self.print_debug == 1:
                #print "start = ", start, "end = ", end, "address = ", address, "number = ", number
                data[start:end] = self.iss.i2c.read(self.Slave_Addr, address,
                                                    60)
                start += 60
                address += 60
                if ((number - 60) >= 0):
                    number -= 60
                if (address >= 256):
                    address -= 128

        if self.print_debug == 1:
            print("Read Value = " + str.join("", ("0x%02X, " % a
                                                  for a in data[0:end])))
        return data

    def I2C_CURRENT_READ(self, number):
        data = [0] * number
        start = 0
        end = 0
        while (number > 0):
            if number < 60:
                end += number
                #if self.print_debug == 1:
                #print "start = ", start, "end = ", end, "address = ", address, "number = ", number
                data[start:end] = self.iss.i2c.read_ad0(
                    self.Slave_Addr, number)
                break
            else:
                end += 60
                #if self.print_debug == 1:
                #print "start = ", start, "end = ", end, "address = ", address, "number = ", number
                data[start:end] = self.iss.i2c.read_ad0(self.Slave_Addr, 60)
                start += 60
                address += 60
                if ((number - 60) >= 0):
                    number -= 60
                if (address >= 256):
                    address -= 128
        return data

    def I2C_WRITE(self, byte, data):
        """
        USB-ISS Write
        """
        return_check = 0
        byte_shift = 60
        count = 0
        Start_address = byte
        number_of_byte = len(data)
        # Modify by Lance
        while (1):
            if number_of_byte > 60:
                return_check = self.iss.i2c.write(
                    self.Slave_Addr, Start_address,
                    data[(0 + byte_shift * count):(60 + byte_shift * count)])
                Start_address += 60
                number_of_byte -= 60
                count += 1
            else:
                return_check = self.iss.i2c.write(
                    self.Slave_Addr, Start_address,
                    data[(0 + byte_shift * count):(60 + number_of_byte)])
                break
        # Modify by Lance
        # return_check = self.iss.i2c.write(self.Slave_Addr, byte, data) # write > 60 bytes will error
        time.sleep(USB_ISS_Write_delay)
        if self.print_debug == 1:
            if byte == 0x7F:
                print("Page select = " + str.join("", ("0x%02X, " % a
                                                       for a in data)))
            else:
                print("Write Value = " + str.join("", ("0x%02X, " % a
                                                       for a in data)))
        return return_check

    # Addictional Function
    def I2C_PAGE_SELECT(self, page):
        data = [0xFF]
        self.I2C_WRITE(0x7F, page)
        time.sleep(USB_ISS_Write_delay)
        data = self.I2C_READ(0x7F, 1)
        if data != page:
            print("Change Page %s Fail") % hex(data[0])

    def MODULE_MODE_CONTROL(self, en):
        self.I2C_WRITE(0x7F, [0xE6])
        time.sleep(0.08)
        self.I2C_WRITE(0xF0, en)
        time.sleep(0.08)
        if self.print_debug == 1:
            print("Manual Mode = " + en)

    def I2C_READ_Vendor_Info(self):
        self.I2C_WRITE(0x7F, [0x00])
        time.sleep(USB_ISS_Write_delay)

        # Vendor PN
        TEMP_DATA_Vendor_Info = self.I2C_READ(0x94, 16)
        # Number to ASCII
        for x in range(len(TEMP_DATA_Vendor_Info)):
            TEMP_DATA_Vendor_Info[x] = chr(TEMP_DATA_Vendor_Info[x])
        print(TEMP_DATA_Vendor_Info)

        # Vendor SN
        TEMP_DATA_Vendor_Info = self.I2C_READ(0xA6, 16)
        # Number to ASCII
        for x in range(len(TEMP_DATA_Vendor_Info)):
            TEMP_DATA_Vendor_Info[x] = chr(TEMP_DATA_Vendor_Info[x])
        print(TEMP_DATA_Vendor_Info)

    # For 400G DR4 Only
    def TWI_DSP_Direct_Read(self, reg, reg_name):
        self.I2C_PAGE_SELECT(0xB3)
        self.I2C_WRITE(0xF4, reg)
        time.sleep(USB_ISS_Write_delay)
        self.I2C_WRITE(0xF3, [0x01])
        time.sleep(0.02)
        self.reg = reg_name
        self.data = self.I2C_READ(0xFA, 2)
        #print ("Read Data = "+ str.join("", ("%02X" % a for a in data)))
        print(self.reg + " (Read) = 0x" + str.join("", ("%02X" % a
                                                        for a in self.data)))

    def TWI_DSP_Direct_Wirte(self, reg, reg_name, Write_data):
        self.I2C_PAGE_SELECT(0xB3)
        self.I2C_WRITE(0xF4, reg)
        time.sleep(USB_ISS_Write_delay)
        self.I2C_WRITE(0xFA, Write_data)
        time.sleep(USB_ISS_Write_delay)
        self.I2C_WRITE(0xF3, [0x00])
        time.sleep(0.02)
        self.reg = reg_name
        self.data = self.I2C_READ(0xFA, 2)
        #print ("Write Data", str.join("",("%02x" % a for a in self.data)))
        print(self.reg + " (Write) = 0x" + str.join("", ("%02X" % a
                                                         for a in self.data)))

    def SW_RESET(self, delay):
        print('Software Reset!')
        self.I2C_WRITE(26, [0x08])
        print('wait ') + str(delay) + 's'
        time.sleep(delay)

    def Quick_HPMode(self, delay):
        print('Quick_HPMode!')
        self.I2C_WRITE(26, [0x00])
        print('wait ') + str(delay) + 's'
        time.sleep(delay)

    def Write_Password(self):
        print('Write_Password!\n')
        self.I2C_WRITE(0x7A, [0x43, 0x4A, 0x2D, 0x4C])
        time.sleep(0.02)
コード例 #7
0
def main():
    IDD_Max = 180  # Power Current max value
    IDD_Min = 45  # Power Current min value
    I2C_Read_Times = 10
    Jitter_Max = 100  # Jitter max values
    Rx_Amplitude_Min = 100  # Amplitude min value
    Tx_Amplitude_Min = 200  # Amplitude min value

    ## Input Parameters
    Test_Mode = sys.argv[1]  # Rx or Tx
    Tester_Name = sys.argv[2]  # Tester Name
    Chip_ID = sys.argv[3]  # Chip id

    ## Power Supply
    rm = visa.ResourceManager()
    print(rm.list_resources())
    Power_Inst = rm.open_resource(
        'USB0::0x2A8D::0x1002::MY59001324::INSTR')  # connect to SOC
    print(Power_Inst.query("*IDN?"))
    Power_Inst.write("OUTPut:STATe ON,(@1)")  # Turn On Power Channel One

    OSC_Inst = rm.open_resource('GPIB0::1::INSTR')  # connect to SOC
    print(OSC_Inst.query("*IDN?"))
    OSC_Inst.write("*RST")  # reset the OSC

    ## set usb-iss iic master device
    slave_addr = 0x23  # iic target address
    iss = UsbIss()  # usb-iss handle
    iss.open("COM8")  # usb com EXPort
    iss.setup_i2c(
        clock_khz=100
    )  # i2c SCL clock frequency = 100 KHz, if set to 400 KHz, at 1.08 V NACK

    ## Labjack instrument
    d = U3()
    # print(d.configU3())
    # print(d.configIO())
    d.setFIOState(5, state=1)  # default value 1
    d.setFIOState(6, state=1)  # default value 1
    d.setFIOState(7, state=1)  # default value 1

    GBCR2_Reg1 = GBCR2_Reg()
    GBCR2_Reg1.set_Tx1_Dis_DL_BIAS(0)
    GBCR2_Reg1.set_Tx2_Dis_DL_BIAS(0)

    with open(
            "C:/GBCR2_QC_Test/GBCR2_QC_Test_Results/GBCR2_QC_%s_Chip_ID=%s.txt"
            % (Test_Mode, Chip_ID), 'a+') as infile:
        time_stamp = time.strftime('%Y-%m-%d %H:%M:%S',
                                   time.localtime(time.time()))
        infile.write("\n")  # add a blank row
        infile.write("%s\n" % time_stamp)  # write timestamp to file
        infile.write("%s\n" % Tester_Name)  # Tester name

        Channel_One_Current = Power_Control(
            Power_Inst, 1.277)  # Set Power Voltage is about 1.2 V
        if Channel_One_Current < IDD_Min or Channel_One_Current > IDD_Max:
            print("IDD Failed!!!")
            IDD_Status = "IDD Failed!!!"
            infile.write("%s\n" % IDD_Status)  # Tester name
        else:
            IDD_Status = "IDD Passed"
        if IDD_Status == "IDD Passed":
            infile.write("VDD=%.3fV IDD=%.3fA\n" %
                         (1.2, Channel_One_Current))  # read power current
            time.sleep(1)
            ## I2C write and read 10 times. if yes,
            loop_num = 0
            I2C_Status = "Failed"
            while (loop_num < I2C_Read_Times and I2C_Status == "Failed"):
                # print(loop_num)
                I2C_Status1 = I2C_Write_Read(GBCR2_Reg1, iss, infile)
                I2C_Status = I2C_Status1[0]
                if I2C_Status == "Failed":
                    infile.write("I2C Test Failed  %d\n" % loop_num)
                    infile.write("Written values:\n")
                    infile.writelines("%d " % val for val in I2C_Status1[1])
                    infile.write("\n")
                    infile.write("Read values:\n")
                    infile.writelines("%d " % val for val in I2C_Status1[2])
                    infile.write("\n")
                    ## write iic write into data and read back data to file
                time.sleep(0.1)
                loop_num += 1
            if loop_num < I2C_Read_Times:
                infile.write("I2C Test Passed  %d\n" % loop_num)
            else:
                print("I2C NACK!!!")
                infile.write("I2C Test Failed  %d\n" % loop_num)
                infile.writelines("%d " % val for val in I2C_Status1[1])
                infile.write("\n")
                infile.writelines("%d " % val for val in I2C_Status1[2])
                infile.write("\n")
                ## write iic write into data and read back data to file
            if I2C_Status == "Passed":
                Power_Volt = [1.277, 1.145, 1.411]
                # Power_Volt = [1.411]
                Power_Volt_Board = [1.2, 1.08, 1.32]
                Power_Volt_Name = ["VDD=1V20", "VDD=1V08", "VDD=1V32"]
                Channel_One_Current = []
                I2C_Status = []
                Rx_Jitter_Performance = []
                Tx_Jitter_Performance = []
                Rx_Amplitude_Performance = []
                Tx_Amplitude_Performance = []
                Rx_Amplitude = 150
                Tx_Amplitude = 250
                Rx_Jitter = 80
                Tx_Jitter = 80
                print(
                    time.strftime('%Y-%m-%d %H:%M:%S',
                                  time.localtime(time.time())))
                for Volt in range(len(Power_Volt)):
                    # chaneg power voltage
                    print("\n%.2fV Voltage Test......" %
                          Power_Volt_Board[Volt])
                    Channel_One_Current += [
                        Power_Control(Power_Inst, Power_Volt[Volt])
                    ]
                    print("Power Current: %.3f" % Channel_One_Current[Volt])
                    time.sleep(1)
                    I2C_Status += [I2C_Write_Read(GBCR2_Reg1, iss, infile)[0]]
                    print("I2C Status: %s" % I2C_Status[Volt])
                    infile.write(
                        "%.2fV Voltage Test:==============================================\n"
                        % Power_Volt_Board[Volt])
                    infile.write("Power Current: %.3f\n" %
                                 Channel_One_Current[Volt])
                    infile.write("I2C Status: %s\n" % I2C_Status[Volt])
                    if Test_Mode == "Rx":  # test Rx channel
                        for Chan in range(7):
                            if (Rx_Amplitude > Rx_Amplitude_Min
                                    and Rx_Jitter < Jitter_Max) and (
                                        Tx_Amplitude > Tx_Amplitude_Min
                                        and Tx_Jitter < Jitter_Max):
                                print("Rx Channel %d is being tested!" %
                                      (Chan + 1))
                                d.setFIOState(5, state=Chan & 0x1)
                                d.setFIOState(6, state=(Chan & 0x2) >> 1)
                                d.setFIOState(7, state=(Chan & 0x4) >> 2)
                                time.sleep(0.1)
                                Measure_Value = Capture_Screen_Image(
                                    OSC_Inst, Test_Mode,
                                    "Chip_ID=%s_RX_CH%d_%s_Eye-diagram_Img" %
                                    (Chip_ID, Chan + 1, Power_Volt_Name[Volt]))
                                print(Measure_Value)
                                # print("\n")
                                infile.write(
                                    "Rx Channel %d:######################\n" %
                                    (Chan + 1))
                                infile.write(
                                    "RMS Jitter: %.3f ps\n" %
                                    float(eval(Measure_Value[0]) * 1e12))
                                infile.write(
                                    "Amplitude: %.3f mV\n" %
                                    float(eval(Measure_Value[1]) * 1e3))
                                infile.write(
                                    "Rise Time: %.3f ps\n" %
                                    float(eval(Measure_Value[2]) * 1e12))
                                infile.write(
                                    "Fall Time: %.3f ps\n" %
                                    float(eval(Measure_Value[3]) * 1e12))
                                Rx_Jitter_Performance += [
                                    eval(Measure_Value[0]) * 1e12
                                ]
                                Rx_Amplitude_Performance += [
                                    eval(Measure_Value[1]) * 1e3
                                ]
                                # Rx_Jitter_Performance += [float(Measure_Value[0].split("E")[0])]
                                # Rx_Amplitude_Performance += [float(Measure_Value[1].split("E")[0])]
                                Rx_Amplitude = min(Rx_Amplitude_Performance)
                                Rx_Jitter = max(Rx_Jitter_Performance)
                    else:  # test Tx channel
                        for Chan in range(2):
                            if (Rx_Amplitude > Rx_Amplitude_Min
                                    and Rx_Jitter < Jitter_Max) and (
                                        Tx_Amplitude > Tx_Amplitude_Min
                                        and Tx_Jitter < Jitter_Max):
                                print("Tx Channel %d is being tested!" %
                                      (Chan + 1))
                                d.setFIOState(5, state=Chan & 0x1)
                                d.setFIOState(6, state=(Chan & 0x2) >> 1)
                                d.setFIOState(7, state=(Chan & 0x4) >> 2)
                                time.sleep(0.1)
                                Measure_Value = Capture_Screen_Image(
                                    OSC_Inst, Test_Mode,
                                    "Chip_ID=%s_TX_CH%d_%s_Eye-diagram_Img" %
                                    (Chip_ID, Chan + 1, Power_Volt_Name[Volt]))
                                print(Measure_Value)
                                # print("\n")
                                infile.write(
                                    "Tx Channel %d:######################\n" %
                                    (Chan + 1))
                                infile.write(
                                    "RMS Jitter: %.3f ps\n" %
                                    float(eval(Measure_Value[0]) * 1e12))
                                infile.write(
                                    "Amplitude: %.3f mV\n" %
                                    float(eval(Measure_Value[1]) * 1e3))
                                infile.write(
                                    "Rise Time: %.3f ps\n" %
                                    float(eval(Measure_Value[2]) * 1e12))
                                infile.write(
                                    "Fall Time: %.3f ps\n" %
                                    float(eval(Measure_Value[3]) * 1e12))
                                Tx_Jitter_Performance += [
                                    eval(Measure_Value[0]) * 1e12
                                ]
                                Tx_Amplitude_Performance += [
                                    eval(Measure_Value[1]) * 1e3
                                ]
                                Tx_Amplitude = min(Tx_Amplitude_Performance)
                                Tx_Jitter = max(Tx_Jitter_Performance)
                # print(Channel_One_Current)
                # print(max(Channel_One_Current))
                # print(min(Channel_One_Current))
                # print(I2C_Status)
                # print(Rx_Jitter_Performance)
                # print(Rx_Amplitude_Performance)
                # print(max(Rx_Jitter_Performance))
                # print(min(Rx_Amplitude_Performance))
                if max(Channel_One_Current) < IDD_Max and min(
                        Channel_One_Current) > IDD_Min and (
                            "Fail" in I2C_Status) == False:
                    if Test_Mode == "Rx":
                        if max(Rx_Jitter_Performance) < Jitter_Max and min(
                                Rx_Amplitude_Performance) > Rx_Amplitude_Min:
                            print("Chip Test Passed")
                            infile.write("Chip Test Passed\n\n")
                        else:
                            print("Eye-Diagram didn't pass!!!")
                            infile.write("Eye-Diagram didn't pass!!!\n\n")
                    else:
                        if max(Tx_Jitter_Performance) < Jitter_Max and min(
                                Tx_Amplitude_Performance) > Tx_Amplitude_Min:
                            print("Chip Test Passed")
                            infile.write("Chip Test Passed\n\n")
                        else:
                            print("Eye-Diagram didn't pass!!!")
                            infile.write("Eye-Diagram didn't pass!!!\n\n")
                else:
                    print("IID Failed!!!")

            infile.write("\n")

    # ## Turn off Power
    time.sleep(2)
    Power_Inst.write("OUTPut:STATe OFF,(@1)")
    print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
    d.setFIOState(5, state=1)  # default value 1
    d.setFIOState(6, state=1)  # default value 1
    d.setFIOState(7, state=1)  # default value 1
コード例 #8
0
from usb_iss import UsbIss, defs
from bitstring import BitArray
import sys

# Configure I2C mode
iss = UsbIss()
iss.open("COMX")  #Enter your COM port number
iss.setup_i2c()

temp1 = iss.i2c.read(0xA0, 0x36, 1)
first_byte = '{:08b}'.format(temp1[0])
version = (BitArray(bin=(first_byte))).int
version = hex(version)
print('Current FW Version = ', version)
if version == "-1":
    print("Chip not programmed, try reading multiple times")

else:
    print("Verify the programmed version matching the current FW version")

temp1 = iss.i2c.read(0xA0, 0xA8, 4)
first_byte = '{:08b}'.format(temp1[3])
second_byte = '{:08b}'.format(temp1[2])
third_byte = '{:08b}'.format(temp1[1])
fourth_byte = '{:08b}'.format(temp1[0])
version = (BitArray(bin=(first_byte + second_byte + third_byte +
                         fourth_byte))).int
version = hex(version)
print('TEST_FEE_CRC 0xA8 = ', version)
#This command is used to provide the reference CRC calculated by the on-chip hardware.
# In a post-compile step, this value is inserted into the object file programmed into the flash memory to provide the
コード例 #9
0
def button_run():
    # get entry values from GUI
    Reg_Val = gui_form_reg()

    register_filename = "GBS20V1_gui_register_config.txt"   # need to change by users

    COM_Port = Run_entry[0].get()
    I2C_Addr = int(Run_entry[1].get(), 0)                             # need to change according I2C Addr
    print (COM_Port, I2C_Addr)

    # Write GUI value to txt
    write_user_config(Reg_Val, register_filename)    
    

    Reg_Addr = []
    Reg_Val = []

    with open(register_filename, 'r') as infile:                  # read configuration file
        for line in infile.readlines():
            Reg_Addr += [int(line.split()[0], 16)]              # read register address and value
            Reg_Val += [int(line.split()[1], 16)]

    regWritelen = len(Reg_Addr)
    print ('I2C Addr:',hex(I2C_Addr))
    #print (regWritelen)
    
    print ('Reg Addr:')
    print (Reg_Addr)
    print ('Write-in Reg values:')
    print (Reg_Val)

    # set usb-iss iic master device
    iss = UsbIss()
    iss.open(COM_Port)
    iss.setup_i2c(clock_khz=100)

    # write data into i2c slave
    iss.i2c.write(I2C_Addr, 0, Reg_Val)       
    time.sleep(0.02)

    read_data = []
    for i in range(regWritelen):                              # read data from i2c slave
        read_data += iss.i2c.read(I2C_Addr, Reg_Addr[i], 1)
        time.sleep(0.02)

    print ('Read-back Reg values:')   
    print (read_data)
     # compare write in data with read back data
    errFlag = 0
    print('Check write-in and Read-back data:')
    for i in range(regWritelen):
        if Reg_Val[i] != read_data[i]:
            print("ERROR! Read-back didn't match with write-in: {} {} {}".format(hex(Reg_Addr[i]), hex(Reg_Val[i]), hex(read_data[i])) )
            errFlag = 1

    # if write-in successful, sound once, else sound 3 times
    global I2C_writein
    if errFlag == 0:
        I2C_writein.set('Passed')
        for i in range(3): 
            winsound.Beep(freqency, duration)
            time.sleep(0.01)
    else: 
        I2C_writein.set('Error')
        for i in range(5): 
            winsound.Beep(freqency, duration)
            time.sleep(0.01)


    print("PASS!")
    print("**********************************************************************************")

    return 
コード例 #10
0
def main():
    user_config_filename = "QTIA_user_config.txt"  # need to change by users
    register_filename = "QTIA_register_config.txt"  # need to change by users

    COM_Port = "COM3"  # need to change according com port
    I2C_Addr = 0x21  # I2C Addr of QTIA on QTRx: 7’b0100001

    Reg_Addr = []
    Reg_Val = []

    write_user_config(
        user_config_filename, register_filename
    )  # comment out this line if you want to use register_filename directly

    with open(register_filename, 'r') as infile:  # read configuration file
        for line in infile.readlines():
            Reg_Addr += [int(line.split()[0],
                             16)]  # read register address and value
            Reg_Val += [int(line.split()[1], 16)]

    print(Reg_Addr)
    print(Reg_Val)

    # set usb-iss iic master device
    iss = UsbIss()
    iss.open(COM_Port)
    iss.setup_i2c(clock_khz=100)

    regWritelen = len(Reg_Addr)
    print(type(I2C_Addr))
    print(regWritelen)

    # write data into i2c slave
    iss.i2c.write(I2C_Addr, 0, Reg_Val)
    time.sleep(0.02)

    # for i in range(regWritelen):                              # write data into i2c slave
    #     print (I2C_Addr, hex(Reg_Addr[i]), hex(Reg_Val[i]))
    #     iss.i2c.write(I2C_Addr, Reg_Addr[i], Reg_Val[i])
    #     time.sleep(0.02)

    read_data = []
    for i in range(regWritelen):  # read data from i2c slave
        read_data += iss.i2c.read(I2C_Addr, Reg_Addr[i], 1)
        time.sleep(0.02)

    # compare write in data with read back data
    print('Check write-in registers:')
    for i in range(regWritelen):
        if Reg_Val[i] != read_data[i]:
            print("Read-back didn't match with write-in: {} {} {}".format(
                hex(Reg_Addr[i]), hex(Reg_Val[i]), hex(read_data[i])))
    print('Write-in data check finished')

    for i in range(
            3
    ):  # if read back data matched with write in data, speaker will make a sound three times
        winsound.Beep(freqency, duration)
        time.sleep(0.01)

    print("Ok!")
コード例 #11
0
class TestUSbIss(unittest.TestCase):
    def setUp(self):
        self.usb_iss = UsbIss()
        self.driver = Mock()
        self.usb_iss._drv = self.driver

    def test_open(self):
        self.usb_iss.open('PORTNAME')

        assert_that(self.driver.open, called_once_with('PORTNAME'))

    def test_close(self):
        self.usb_iss.open('PORTNAME')

        self.usb_iss.close()

        assert_that(self.driver.close, called_once())

    def test_setup_i2c(self):
        test_matrix = [
            (20, False, 0x20),
            (50, False, 0x30),
            (100, False, 0x40),
            (400, False, 0x50),
            (100, True, 0x60),
            (400, True, 0x70),
            (1000, True, 0x80),
        ]

        for (clk_khz, use_i2c_hardware, i2c_mode) in test_matrix:
            self.usb_iss.setup_i2c(
                clock_khz=clk_khz,
                use_i2c_hardware=use_i2c_hardware,
                io1_type=defs.IOType.OUTPUT_LOW,
                io2_type=defs.IOType.OUTPUT_HIGH)

            assert_that(self.driver.write_cmd,
                        called_with(0x5A, [0x02, i2c_mode, 0x04]))

    def test_setup_i2c_default_values(self):
        self.usb_iss.setup_i2c()

        assert_that(self.driver.write_cmd,
                    called_once_with(0x5A, [
                        0x02,
                        defs.Mode.I2C_H_400KHZ.value,
                        defs.IOType.DIGITAL_INPUT.value << 2 |
                        defs.IOType.DIGITAL_INPUT.value]))

    def test_setup_i2c_failure(self):
        self.driver.check_ack_error_code.side_effect = UsbIssError

        assert_that(calling(self.usb_iss.setup_i2c),
                    raises(UsbIssError))
        assert_that(self.driver.check_ack_error_code,
                    called_once_with(defs.ModeError))

    def test_setup_i2c_invalid_clock_rate(self):
        assert_that(calling(self.usb_iss.setup_i2c).
                    with_args(clock_khz=942),
                    raises(UsbIssError, "Invalid clk_khz value"))

    def test_setup_i2c_invalid_hw_clock_rate(self):
        assert_that(calling(self.usb_iss.setup_i2c).
                    with_args(clock_khz=50, use_i2c_hardware=True),
                    raises(AssertionError,
                           "I2C HW mode doesn't support 50kHz"))

    def test_setup_i2c_invalid_sw_clock_rate(self):
        assert_that(calling(self.usb_iss.setup_i2c).
                    with_args(clock_khz=1000, use_i2c_hardware=False),
                    raises(AssertionError,
                           "I2C SW mode doesn't support 1000kHz"))

    def test_setup_i2c_serial(self):
        test_matrix = [
            (20, False, 0x21),
            (50, False, 0x31),
            (100, False, 0x41),
            (400, False, 0x51),
            (100, True, 0x61),
            (400, True, 0x71),
            (1000, True, 0x81),
        ]

        for (clk_khz, use_i2c_hardware, i2c_mode) in test_matrix:
            self.usb_iss.setup_i2c_serial(
                clock_khz=clk_khz,
                use_i2c_hardware=use_i2c_hardware)

            assert_that(self.driver.write_cmd,
                        called_with(0x5A, [0x02, i2c_mode, 0x01, 0x37]))

    def test_setup_i2c_serial_baud_rates(self):
        test_matrix = [
            (300, [0x27, 0x0F]),
            (1200, [0x09, 0xC3]),
            (2400, [0x04, 0xE1]),
            (9600, [0x01, 0x37]),
            (19200, [0x00, 0x9B]),
            (38400, [0x00, 0x4D]),
            (57600, [0x00, 0x33]),
            (115200, [0x00, 0x19]),
        ]

        for (baud_rate, divisor) in test_matrix:
            self.usb_iss.setup_i2c_serial(baud_rate=baud_rate)

            assert_that(self.driver.write_cmd,
                        called_with(0x5A, [
                            0x02,
                            defs.Mode.I2C_H_400KHZ.value | 0x01] +
                            divisor))

    def test_setup_i2c_serial_default_values(self):
        self.usb_iss.setup_i2c_serial()

        assert_that(self.driver.write_cmd,
                    called_once_with(0x5A, [
                        0x02,
                        defs.Mode.I2C_H_400KHZ.value | 0x01,
                        0x01,
                        0x37]))

    def test_setup_i2c_serial_overflow(self):
        self.usb_iss.setup_i2c_serial(baud_rate=1)

        assert_that(self.driver.write_cmd,
                    called_once_with(0x5A, [
                        0x02,
                        defs.Mode.I2C_H_400KHZ.value | 0x01,
                        0xFF,
                        0xFF]))

    def test_setup_i2c_serial_failure(self):
        self.driver.check_ack_error_code.side_effect = UsbIssError

        assert_that(calling(self.usb_iss.setup_i2c_serial),
                    raises(UsbIssError))
        assert_that(self.driver.check_ack_error_code,
                    called_once_with(defs.ModeError))

    def test_setup_spi(self):
        test_matrix = [
            (3000, 1),
            (500, 11),
            (23, 255),
        ]

        for (clk_khz, divisor) in test_matrix:
            self.usb_iss.setup_spi(
                spi_mode=defs.SPIMode.TX_IDLE_TO_ACTIVE_IDLE_HIGH,
                clock_khz=clk_khz)

            assert_that(self.driver.write_cmd,
                        called_with(0x5A, [0x02, 0x93, divisor]))

    def test_setup_spi_default_values(self):
        self.usb_iss.setup_spi()

        assert_that(self.driver.write_cmd,
                    called_once_with(0x5A, [0x02, 0x90, 11]))

    def test_setup_spi_overflow(self):
        self.usb_iss.setup_spi(clock_khz=1)

        assert_that(self.driver.write_cmd,
                    called_once_with(0x5A, [0x02, 0x90, 0xFF]))

    def test_setup_spi_failure(self):
        self.driver.check_ack_error_code.side_effect = UsbIssError

        assert_that(calling(self.usb_iss.setup_spi),
                    raises(UsbIssError))
        assert_that(self.driver.check_ack_error_code,
                    called_once_with(defs.ModeError))

    def test_setup_io(self):
        self.usb_iss.setup_io(
            io1_type=defs.IOType.OUTPUT_LOW,
            io2_type=defs.IOType.OUTPUT_HIGH,
            io3_type=defs.IOType.ANALOGUE_INPUT,
            io4_type=defs.IOType.DIGITAL_INPUT)

        assert_that(self.driver.write_cmd,
                    called_once_with(0x5A, [0x02, 0x00, 0xB4]))

    def test_setup_io_default_values(self):
        self.usb_iss.setup_io()

        assert_that(self.driver.write_cmd,
                    called_once_with(0x5A, [
                        0x02,
                        0x00,
                        defs.IOType.DIGITAL_INPUT.value << 6 |
                        defs.IOType.DIGITAL_INPUT.value << 4 |
                        defs.IOType.DIGITAL_INPUT.value << 2 |
                        defs.IOType.DIGITAL_INPUT.value]))

    def test_setup_io_failure(self):
        self.driver.check_ack_error_code.side_effect = UsbIssError

        assert_that(calling(self.usb_iss.setup_io),
                    raises(UsbIssError))
        assert_that(self.driver.check_ack_error_code,
                    called_once_with(defs.ModeError))

    def test_change_io(self):
        self.usb_iss.change_io(
            io1_type=defs.IOType.OUTPUT_LOW,
            io2_type=defs.IOType.OUTPUT_HIGH,
            io3_type=defs.IOType.ANALOGUE_INPUT,
            io4_type=defs.IOType.DIGITAL_INPUT)

        assert_that(self.driver.write_cmd,
                    called_once_with(0x5A, [0x02, 0x10, 0xB4]))

    def test_change_io_default_values(self):
        self.usb_iss.change_io()

        assert_that(self.driver.write_cmd,
                    called_once_with(0x5A, [
                        0x02,
                        0x10,
                        defs.IOType.DIGITAL_INPUT.value << 6 |
                        defs.IOType.DIGITAL_INPUT.value << 4 |
                        defs.IOType.DIGITAL_INPUT.value << 2 |
                        defs.IOType.DIGITAL_INPUT.value]))

    def test_change_io_failure(self):
        self.driver.check_ack_error_code.side_effect = UsbIssError

        assert_that(calling(self.usb_iss.change_io),
                    raises(UsbIssError))
        assert_that(self.driver.check_ack_error_code,
                    called_once_with(defs.ModeError))

    def test_setup_serial_baud_rates(self):
        test_matrix = [
            (300, [0x27, 0x0F]),
            (1200, [0x09, 0xC3]),
            (2400, [0x04, 0xE1]),
            (9600, [0x01, 0x37]),
            (19200, [0x00, 0x9B]),
            (38400, [0x00, 0x4D]),
            (57600, [0x00, 0x33]),
            (115200, [0x00, 0x19]),
        ]

        for (baud_rate, divisor) in test_matrix:
            self.usb_iss.setup_serial(baud_rate=baud_rate,
                                      io3_type=defs.IOType.OUTPUT_LOW,
                                      io4_type=defs.IOType.OUTPUT_HIGH)

            assert_that(self.driver.write_cmd,
                        called_with(0x5A, [0x02, 0x01] + divisor + [0x40]))

    def test_setup_serial_default_values(self):
        self.usb_iss.setup_serial()

        assert_that(self.driver.write_cmd,
                    called_once_with(0x5A,
                                     [0x02, 0x01, 0x01, 0x37,
                                      defs.IOType.DIGITAL_INPUT.value << 6 |
                                      defs.IOType.DIGITAL_INPUT.value << 4]))

    def test_setup_serial_failure(self):
        self.driver.check_ack_error_code.side_effect = UsbIssError

        assert_that(calling(self.usb_iss.setup_serial),
                    raises(UsbIssError))
        assert_that(self.driver.check_ack_error_code,
                    called_once_with(defs.ModeError))

    def test_read_module_id(self):
        self.driver.read.return_value = [0x07, 0x02, 0x40]

        result = self.usb_iss.read_module_id()

        assert_that(result, is_(0x07))
        assert_that(self.driver.write_cmd, called_once_with(0x5A, [0x01]))
        assert_that(self.driver.read, called_once_with(3))

    def test_read_fw_version(self):
        self.driver.read.return_value = [0x07, 0x02, 0x40]

        result = self.usb_iss.read_fw_version()

        assert_that(result, is_(0x02))
        assert_that(self.driver.write_cmd, called_once_with(0x5A, [0x01]))
        assert_that(self.driver.read, called_once_with(3))

    def test_read_iss_mode(self):
        self.driver.read.return_value = [0x07, 0x02, 0x40]

        result = self.usb_iss.read_iss_mode()

        assert_that(result, is_(defs.Mode.I2C_S_100KHZ))
        assert_that(self.driver.write_cmd, called_once_with(0x5A, [0x01]))
        assert_that(self.driver.read, called_once_with(3))

    def test_read_iss_mode_with_serial(self):
        self.driver.read.return_value = [0x07, 0x02, 0x71]

        result = self.usb_iss.read_iss_mode()

        assert_that(result, is_(defs.Mode.SERIAL_I2C_H_400KHZ))
        assert_that(self.driver.write_cmd, called_once_with(0x5A, [0x01]))
        assert_that(self.driver.read, called_once_with(3))

    def test_read_serial_number(self):
        self.driver.read.return_value = [
            0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31]

        result = self.usb_iss.read_serial_number()

        assert_that(result, is_("00000001"))
        assert_that(self.driver.write_cmd, called_once_with(0x5A, [0x03]))
        assert_that(self.driver.read, called_once_with(8))

    def test_setup_io_then_change_io_defaults(self):
        self.usb_iss.setup_io(
            io1_type=defs.IOType.OUTPUT_LOW,
            io2_type=defs.IOType.OUTPUT_HIGH,
            io3_type=defs.IOType.ANALOGUE_INPUT,
            io4_type=defs.IOType.DIGITAL_INPUT)

        assert_that(self.driver.write_cmd,
                    called_with(0x5A, [0x02, 0x00, 0xB4]))

        self.usb_iss.change_io()

        assert_that(self.driver.write_cmd,
                    called_with(0x5A, [
                        0x02,
                        0x10,
                        defs.IOType.DIGITAL_INPUT.value << 6 |
                        defs.IOType.ANALOGUE_INPUT.value << 4 |
                        defs.IOType.OUTPUT_HIGH.value << 2 |
                        defs.IOType.OUTPUT_LOW.value]))

    def test_setup_io_then_change_io(self):
        self.usb_iss.setup_io(
            io1_type=defs.IOType.OUTPUT_LOW,
            io2_type=defs.IOType.OUTPUT_HIGH,
            io3_type=defs.IOType.ANALOGUE_INPUT,
            io4_type=defs.IOType.DIGITAL_INPUT)

        assert_that(self.driver.write_cmd,
                    called_with(0x5A, [0x02, 0x00, 0xB4]))

        self.usb_iss.change_io(
            io1_type=defs.IOType.DIGITAL_INPUT,
            io2_type=defs.IOType.ANALOGUE_INPUT,
            io3_type=defs.IOType.OUTPUT_HIGH,
            io4_type=defs.IOType.OUTPUT_LOW)

        assert_that(self.driver.write_cmd,
                    called_with(0x5A, [
                        0x02,
                        0x10,
                        defs.IOType.OUTPUT_LOW.value << 6 |
                        defs.IOType.OUTPUT_HIGH.value << 4 |
                        defs.IOType.ANALOGUE_INPUT.value << 2 |
                        defs.IOType.DIGITAL_INPUT.value]))

    def test_setup_io_then_change_io_partial(self):
        self.usb_iss.setup_io(
            io1_type=defs.IOType.OUTPUT_LOW,
            io2_type=defs.IOType.OUTPUT_HIGH,
            io3_type=defs.IOType.ANALOGUE_INPUT,
            io4_type=defs.IOType.DIGITAL_INPUT)

        assert_that(self.driver.write_cmd,
                    called_with(0x5A, [0x02, 0x00, 0xB4]))

        self.usb_iss.change_io(
            io1_type=defs.IOType.DIGITAL_INPUT,
            io3_type=defs.IOType.OUTPUT_HIGH)

        assert_that(self.driver.write_cmd,
                    called_with(0x5A, [
                        0x02,
                        0x10,
                        defs.IOType.DIGITAL_INPUT.value << 6 |
                        defs.IOType.OUTPUT_HIGH.value << 4 |
                        defs.IOType.OUTPUT_HIGH.value << 2 |
                        defs.IOType.DIGITAL_INPUT.value]))

    def test_setup_io_then_setup_i2c_override(self):
        self.usb_iss.setup_io(
            io1_type=defs.IOType.OUTPUT_LOW,
            io2_type=defs.IOType.OUTPUT_HIGH,
            io3_type=defs.IOType.ANALOGUE_INPUT,
            io4_type=defs.IOType.DIGITAL_INPUT)

        assert_that(self.driver.write_cmd,
                    called_with(0x5A, [
                        0x02,
                        0x00,
                        defs.IOType.DIGITAL_INPUT.value << 6 |
                        defs.IOType.ANALOGUE_INPUT.value << 4 |
                        defs.IOType.OUTPUT_HIGH.value << 2 |
                        defs.IOType.OUTPUT_LOW.value]))

        self.usb_iss.setup_i2c(
            io1_type=defs.IOType.DIGITAL_INPUT,
            io2_type=defs.IOType.ANALOGUE_INPUT)

        assert_that(self.driver.write_cmd,
                    called_with(0x5A, [
                        0x02,
                        defs.Mode.I2C_H_400KHZ.value,
                        defs.IOType.ANALOGUE_INPUT.value << 2 |
                        defs.IOType.DIGITAL_INPUT.value]))

    def test_setup_io_then_setup_i2c_defaults(self):
        self.usb_iss.setup_io(
            io1_type=defs.IOType.OUTPUT_LOW,
            io2_type=defs.IOType.OUTPUT_HIGH,
            io3_type=defs.IOType.ANALOGUE_INPUT,
            io4_type=defs.IOType.DIGITAL_INPUT)

        assert_that(self.driver.write_cmd,
                    called_with(0x5A, [
                        0x02,
                        0x00,
                        defs.IOType.DIGITAL_INPUT.value << 6 |
                        defs.IOType.ANALOGUE_INPUT.value << 4 |
                        defs.IOType.OUTPUT_HIGH.value << 2 |
                        defs.IOType.OUTPUT_LOW.value]))

        self.usb_iss.setup_i2c()

        assert_that(self.driver.write_cmd,
                    called_with(0x5A, [
                        0x02,
                        defs.Mode.I2C_H_400KHZ.value,
                        defs.IOType.OUTPUT_HIGH.value << 2 |
                        defs.IOType.OUTPUT_LOW.value]))

    def test_setup_i2c_defaults_then_change_io_partial(self):
        self.usb_iss.setup_i2c()

        assert_that(self.driver.write_cmd,
                    called_with(0x5A, [
                        0x02,
                        defs.Mode.I2C_H_400KHZ.value,
                        defs.IOType.DIGITAL_INPUT.value << 2 |
                        defs.IOType.DIGITAL_INPUT.value]))

        self.usb_iss.change_io(
            io1_type=defs.IOType.OUTPUT_LOW,
            io4_type=defs.IOType.OUTPUT_HIGH)

        assert_that(self.driver.write_cmd,
                    called_with(0x5A, [
                        0x02,
                        0x10,
                        defs.IOType.OUTPUT_HIGH.value << 6 |
                        defs.IOType.DIGITAL_INPUT.value << 4 |
                        defs.IOType.DIGITAL_INPUT.value << 2 |
                        defs.IOType.OUTPUT_LOW.value]))
コード例 #12
0
class I2C_Dongle_USBISS(I2C_Dongle):
    def __init__(self, port):
        try:
            self.port = int(port) if port else 0
        except ValueError:
            self.port = 0
        self.iss = None

    def get_port(self):
        if self.port != 0: return 'COM' + str(self.port)

        plist = list(serial.tools.list_ports.comports())
        for p in plist:
            if sys.platform.startswith('win32'):
                if p.vid == 0x04D8 and p.pid == 0xFFEE:
                    return p.device
            elif sys.platform.startswith('linux'):
                if 'USB VID:PID=04d8:ffee' in p[2]:
                    return p[0]
        raise UsbIssError("\nCan't find usb-iss device!\n")

    def open_device(self, bitrate=400):
        try:
            self.iss = UsbIss()
            self.iss.open(self.get_port())
            self.iss.setup_i2c(clock_khz=bitrate)
        except Exception as ex:
            print(ex)
            raise UsbIssError("\ninitial usb-iss device error!\n")

    def write(self, slave_addr, reg_addr, data, **kwargs):
        try:
            data_write = data[:]
            len_take = 15 if reg_addr is None else 14
            end = math.ceil(len(data_write) / len_take)
            for t in range(int(end)):
                data_out = data_write[t * len_take:(t + 1) * len_take]
                if t == 0:
                    if reg_addr is not None:
                        data_out.insert(0, reg_addr)  # reg_addr
                    data_out.insert(0, slave_addr)  # slave_addr
                    data_out.insert(0,
                                    0x30 + len(data_out) - 1)  # write length
                    data_out.insert(0, 0x01)  # i2c start
                else:
                    data_out.insert(0,
                                    0x30 + len(data_out) - 1)  # write length

                if t == end - 1:
                    data_out.append(0x03)  # i2c stop

                self.iss.i2c.direct(data_out)
        except:
            return -1
        return 0

    def read(self, slave_addr, reg_addr, num_bytes, **kwargs):
        data_in = []

        try:
            read_bytes_per_time = 16
            max_loop_num = math.ceil(num_bytes / read_bytes_per_time)
            num = 0
            while num < max_loop_num:
                if num_bytes - num * read_bytes_per_time < read_bytes_per_time:
                    read_bytes_per_time = num_bytes - num * read_bytes_per_time

                data_out = []
                if num == max_loop_num - 1:
                    data_out.insert(0, defs.I2CDirect.STOP)
                    data_out.insert(0, defs.I2CDirect.READ1)
                    data_out.insert(0, defs.I2CDirect.NACK)
                    if read_bytes_per_time > 1:
                        data_out.insert(0, 0x20 + read_bytes_per_time - 2)
                else:
                    data_out.insert(0, 0x20 + read_bytes_per_time - 1)
                if num == 0:
                    data_out.insert(0, slave_addr | 0x01)
                    data_out.insert(0, defs.I2CDirect.WRITE1)
                    if reg_addr is not None:
                        data_out.insert(0, defs.I2CDirect.RESTART)
                        data_out.insert(0, reg_addr)
                        data_out.insert(0, slave_addr)
                        data_out.insert(0, defs.I2CDirect.WRITE2)
                    data_out.insert(0, defs.I2CDirect.START)

                data_in += self.iss.i2c.direct(data_out)

                num += 1
        except:
            del data_in[:]

        return len(data_in), data_in

    def close_device(self):
        if self.iss: self.iss.close()