pyftdi
pyftdi copied to clipboard
Multiple 232H
I have a setup with two 232H for two different I2C busses.
I can get only one to work at a time; if both are plugged in, the PY library stops working until I do a driver reinstall. This seems to be a new issue with Windows.
Code:
`
from pyftdi import FtdiLogger from pyftdi.i2c import I2cController, I2cIOError from time import sleep from array import array as Array from binascii import hexlify import time from pyftdi.ftdi import Ftdi DeviceAddress = 0x50 AddressSpace = 16
DeviceA = 'ftdi://::FT7T9DYH/1' DeviceB = 'ftdi://::FT7T9C0N/1'
GPIO_WIDTH = 1 # use 2 GPIOs for output, 2 GPIOs for input (loopback) GPIO_OUT_OFFSET = 5 # GPIO output are b3..b4 GPIO_IN_OFFSET = 4 # GPIO input are b8..b9
class EEPROM():
def __init__(self,Device):
Ftdi.show_devices()
dev = Ftdi.list_devices()
print(dev)
self._i2c = I2cController()
self._i2c.configure(Device)
self.gpio = self._i2c.get_gpio()
mask = (1 << GPIO_WIDTH) - 1
self.gpio.set_direction(mask << GPIO_OUT_OFFSET | mask << GPIO_IN_OFFSET, mask << GPIO_OUT_OFFSET)
self.DA = DeviceAddress
self.Bit = AddressSpace
self.port = self._i2c.get_port(self.DA)
def SetPower(self,State):
if(State):
pins = self.gpio.read()
# clearing out I2C bits (SCL, SDAo, SDAi)
pins &= 0x07
# set AD4
pins |= 1 << 4
# update GPIO output
self.gpio.write(pins)
else:
pins = self.gpio.read()
# clearing out I2C bits (SCL, SDAo, SDAi)
pins &= 0x07
# Clear AD4
pins |= 0 << 4
# update GPIO output
self.gpio.write(pins)
def SetActive(self,State):
if(State):
pins = self.gpio.read()
# clearing out I2C bits (SCL, SDAo, SDAi)
pins &= 0x07
# set AD4
pins |= 1 << 5
# update GPIO output
self.gpio.write(pins)
else:
pins = self.gpio.read()
# clearing out I2C bits (SCL, SDAo, SDAi)
pins &= 0x07
# Clear AD4
pins |= 0 << 5
# update GPIO output
self.gpio.write(pins)
def ReadName(self,Pos,Lenth):
try:
if(self.Bit == 16):
#print("16bit")
device_id = self.port.exchange([0,Pos], Lenth)
#print(device_id)
if(self.Bit == 8):
#print("8bit")
device_id = self.port.exchange([Pos], Lenth)
#print(device_id)
except:
print("An exception occurred")
return 0
def DeviceAddress(self,Address):
self.DA = Address;
self.port = self._i2c.get_port(self.DA)
return 0
def DeviceBit(self,Bit):
self.Bit = Bit;
return 0
def WriteName(self,Pos,Name):
new_string = bytes(Name,"ascii")
if(self.Bit == 16):
#print("16bit")
Init = [0,Pos]
if(self.Bit == 8):
#print("8bit")
Init = [Pos]
Init += bytearray(new_string)
self.port.write(Init)
return 0
def ReadByte(self,Pos):
try:
if(self.Bit == 16):
#print("16bit")
device_Pkt = self.port.exchange([0,Pos], 1)
return device_Pkt
if(self.Bit == 8):
#print("8bit")
device_Pkt = self.port.exchange([Pos], 1)
return device_Pkt
except:
print("An exception occurred")
return 0
def WriteByte(self,Pos,Byte):
try:
self.port.write_to(Pos, Byte)
except Exception as A: #(Where A is a temporary variable)
print(A)
return 0
def ReadPage(self,Pos): ## 8 Bytes at a time?
try:
if(self.Bit == 16):
#print("16bit")
List = self.port.exchange([0,Pos], 8)
return List
if(self.Bit == 8):
#print("8bit")
List = self.port.exchange([Pos], 8)
return List
except:
print("An exception occurred")
return 0
def WritePage(self,Pos,ByteArray): ## 16 bytes at a time
try:
#print("First List:")
#print(ByteArray)
if(self.Bit == 16):
#print("16bit")
Init = [0,Pos]
if(self.Bit == 8):
#print("8bit")
Init = [Pos]
Init += bytearray(ByteArray)
self.port.write(Init)
except Exception as A: #(Where A is a temporary variable)
print(A)
return 0
Device = EEPROM(DeviceB) Device.WriteName(0,"RickIsCool") Device.ReadName(0,10) ##for i in range(9):
print(i, end=" ")
Device.SetCurrent(i)
time.sleep(3)
`
Any ideas on what I could try differently?
Sorry, I have no idea on how the Windows USB stack works (except that is a gigantic pile of sh*t).
The best place to ask the question would be the Zadig driver or any other Windows USB to libUSB wrapper you are using, I'm afraid :(
I always try to keep away from Windows as much as I can (and I've been successful for the last 22 years :))