python绑定到d2xx和libftdi,以使用与pyserial相同的接口访问ft232芯片。使用这种方法可以方便地访问芯片上的附加功能,如cbus gpio。
pyft232的Python项目详细描述
PYFT232
这个模块提供了一个简单的串行接口到ft232芯片,而仍然 允许访问用于控制简单信号的cbus管脚。
cTypes用于与FTDI的D2xx库(如果可用)进行接口 或者libftdi。以这种方式,这个软件包在windows和linux(以及其他 libftdi支持操作系统),而不需要在windows上干扰ftdi驱动程序。
相比之下,pyftdi功能更丰富,而且跨平台,但需要 Windows上的特殊驱动程序,因此您不能将FTDI芯片用作纯 COM端口。
用法
importft232serial_number="FT1234"try:sp=ft232.Ft232(serial_number,baudrate=115200)exceptft232.Ft232Exception:print("Unable to open the ftdi device: %s"%serial_number)sys.exit(1)#You may use sp as you would a Serial objectsp.write(b"Hello World!\n")resp=sp.read(100)#If you want to use the CBUS pins, you enable them with cbus_setup# 'mask' is a bitmask which specifies which pins to enable# 'init' is a bitmask for the initial value for each pinsp.cbus_setup(mask=3,init=3)#Change the current value of all setup pinssp.cbus_write(2)#Print the current value of all setup pinsprint("CBUS: %s"%sp.cbus_read())