ITADN

Error when running Glasgow device as I2C controller

#1003Openmayjack0312 创建于 2025-08-10
question
M
mayjack0312commented
Implementation method: Use i2c-initiator firmware for host computer communication Connect the Glasgow hardware to the USB port. Connect the I2C signal lines to the module's SCL and SDA lines. `Glasgow flash i2c-initiator --scl A0 --sda A1` Run the GUI program. Program error message. `LIBUSB ERROR NOT FOUND [-5]` This seems to be a problem of insufficient permissions or port occupation. I can't solve the former error by running the command as an administrator. This is the hardware connection part. I don't know if there is any problem with writing it this way. I also want to help. After running the flash command, the applet is permanently loaded into the hardware. How can I return it to its original state? (The applet is not loaded when power is turned on) ```python import tkinter.ttk as ttk import tkinter as tk from tkinter import messagebox import ttkbootstrap as ttk from ttkbootstrap.constants import * from ttkbootstrap.tooltip import ToolTip from ttkbootstrap.scrolled import ScrolledText from datetime import datetime import json import os import usb1 import logging import asyncio import threading from glasgow.applet.interface.i2c_initiator import I2CInitiatorInterface class I2CInitiatorInterface: def __init__(self, device, logger): self.device = device self._logger = logger async def write(self, addr, data, stop=False): packet = bytes(data) self._logger.debug(f"I2C write to addr {addr:#02x}: {packet.hex()} stop={stop}") endpoint = 0x04 await self.device.bulk_write(endpoint, packet) async def read(self, addr, length, stop=False): self._logger.debug(f"I2C read from addr {addr:#02x}, length={length} stop={stop}") endpoint = 0x88 data = await self.device.bulk_read(endpoint, length) self._logger.debug(f"I2C read data: {data.hex()}") return data async def reset(self): self._logger.debug("I2C reset (no operation)") class PMBusInterface: def __init__(self, device, device_address): self.device = device self.device_address = device_address self.i2c_iface = None self.logger = logging.getLogger("PMBusInterface") async def _open_i2c_interface(self): i2c_interface = I2CInitiatorInterface(self.device, self.logger) return i2c_interface async def connect(self): self.i2c_iface = await self._open_i2c_interface() async def read_byte(self, command): await self.i2c_iface.write(self.device_address, [command], stop=False) result = await self.i2c_iface.read(self.device_address, 1, stop=True) return result[0] async def write_byte(self, command, value): await self.i2c_iface.write(self.device_address, [command, value], stop=True) async def read_word(self, command): await self.i2c_iface.write(self.device_address, [command], stop=False) result = await self.i2c_iface.read(self.device_address, 2, stop=True) return result[0], result[1] async def write_word(self, command, value): data = [command, value & 0xFF, (value >> 8) & 0xFF] await self.i2c_iface.write(self.device_address, data, stop=True) async def read_block(self, command, length): await self.i2c_iface.write(self.device_address, [command], stop=False) result = await self.i2c_iface.read(self.device_address, length, stop=True) return result async def get_vout_exponent(self): PMBUS_COMMANDS = { "VOUT_MODE": 0x20, } mode = await self.read_byte(PMBUS_COMMANDS["VOUT_MODE"]) n_exp = mode & 0x1F if n_exp & 0x10: n_exp = -(0x20 - n_exp) return n_exp class ConfigDialog(ttk.Toplevel): def __init__(self, parent, callback): super().__init__(parent) self.title("Connecting Glasgow devices") self.callback = callback self.transient(parent) self.grab_set() self.resizable(False, False) self.geometry("350x120") ttk.Label(self, text="Finding Glasgow equipment...", font=("Microsoft Yahei", 12)).pack(pady=20) self.after(100, self.try_connect) def try_connect(self): def worker(): try: serials = GlasgowDevice.enumerate_serials() if not serials: self.after(0, lambda: self.callback(None, None)) return serial = serials[0] device = GlasgowDevice(serial) addr = 0x5B self.after(0, lambda: self.callback(device, addr)) except Exception as e: print("Connection abnormality:", e) self.after(0, lambda: self.callback(None, None)) finally: self.after(0, self.destroy) threading.Thread(target=worker, daemon=True).start() ```
5 条评论