Biblioteca simulada para rpi.gpio python biblioteca
Mock.gpio es una biblioteca de Python que admite el desarrollo del software/programa y para depurarlos fuera de RPI (por ejemplo: Ubuntu). Se puede intergramar junto con cualquier aplicación/programa/software genérico.
Ayuda a hacer que su programa/aplicación se ejecute sin problemas, tanto afuera como dentro de RPI por
La forma más fácil de usar este paquete es instalar usando PIP3 para Python3
$ sudo pip3 install Mock.GPIOPara importar la biblioteca simulada al comienzo de su script, use
import Mock . GPIO as GPIOPara habilitar el cambio sin costuras entre la biblioteca simulada cuando está fuera de RPI y la biblioteca RPI.GPIO real cuando esté dentro de RPI, use
try :
# checks if you have access to RPi.GPIO, which is available inside RPi
import RPi . GPIO as GPIO
except :
# In case of exception, you are executing your script outside of RPi, so import Mock.GPIO
import Mock . GPIO as GPIO Esta biblioteca simula las siguientes funciones que se utilizan en la biblioteca RPI.GPIO.
import Mock . GPIO as GPIO El siguiente ejemplo de Python/test.py
try :
import RPi . GPIO as GPIO
except :
import Mock . GPIO as GPIO
import time
print ( "set mode" )
GPIO . setmode ( GPIO . BCM )
print ( "set warning false" )
GPIO . setwarnings ( False )
GPIO . setup ( 15 , GPIO . OUT )
GPIO . output ( 15 , GPIO . HIGH )
time . sleep ( 1 )
GPIO . output ( 15 , GPIO . LOW )genera la siguiente salida
$ export LOG_LEVEL=Info
$ python examples/test.py
set mode
set warning false
2020-05-07 17:49:23,031:INFO: Set warnings as False
2020-05-07 17:49:23,031:INFO: Setup channel : 15 as 0 with initial :0 and pull_up_down 20
2020-05-07 17:49:23,032:INFO: Output channel : 15 with value : 1
2020-05-07 17:49:24,033:INFO: Output channel : 15 with value : 0Realice los cambios adecuados y desde el directorio raíz de este repositorio, instale el paquete Mock.GPIO Python usando el script Install.sh
$ sudo ./scripts/install.sh¡Empieza a contribuir!