I/O通信库
ahio的Python项目详细描述
ahio
ahio是一个通信库,其目标是 是抽象与各种i/o硬件的接口,以便 只要修改最少的代码,硬件就成为可能。这是我想要的 已经与I/O硬件一起工作的应用程序只需要pin 重新映射并可能对初始设置进行更改以使用其他硬件,而不是 整个代码重写。
它与安装在ahio.drivers
包中的驱动程序一起工作。每
驱动程序必须实现ahio.abstract_driver
包中描述的api。
如果您计划使用此库或开发驱动程序,请阅读文档
在那里。
安装
最简单的方法是使用pip:pip3 install ahio
或者,您可以签出此存储库并运行
python3 setup.py install
基本用法
# Import the package:importahio# You can see what drivers are available in this platform by callingprint(ahio.list_available_drivers())# Instantiate the desired driverwithahio.new_driver('Arduino')asarduino:# The driver can have a driver-specific setup function. Call it as/if needed.arduino.setup('/dev/tty.usbmodem1421')# Map the pins. From now on, when you use 1 in the API, it will have effects# on pin D3 in the Arduino. If you change hardware in the future, just change# the mapping.arduino.map_pin(1,arduino.Pins.D3)arduino.map_pin(2,arduino.Pins.D13)arduino.map_pin(3,arduino.Pins.A1)# Change a pin direction (Input or Output)arduino.set_pin_direction([1,2],ahio.Direction.Output)arduino.set_pin_direction(3,ahio.Direction.Input)# Set the output of a pinarduino.write([1,2],ahio.LogicValue.High)arduino.write(1,0.4,pwm=True)# Read the input of a pinprint(arduino.read(3))
文档
文档位于GitHub