From eff11b83feecf083104eae87281979a7eaad4107 Mon Sep 17 00:00:00 2001 From: Sam Bristow Date: Tue, 9 Oct 2018 23:31:35 +1300 Subject: [PATCH 1/2] Use print() function in all code and docs Low-hanging fruit of Python3 compatibility work. I've left fix_py_compile.py as it is only ever going to be run under Python 2. --- Adafruit_BBIO/sysfs.py | 2 +- README.md | 4 ++-- source/examples/python/i2ctmp101.py | 2 +- test/notes/spi_loopback_test.md | 2 +- test/start_all_pwm.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Adafruit_BBIO/sysfs.py b/Adafruit_BBIO/sysfs.py index 43fd078..f2273a1 100644 --- a/Adafruit_BBIO/sysfs.py +++ b/Adafruit_BBIO/sysfs.py @@ -41,7 +41,7 @@ # Print all block devices in /sys, with their sizes for block_dev in sys.block: - print block_dev, str(int(block_dev.size) / 1048576) + ' M' + print(block_dev, str(int(block_dev.size) / 1048576) + ' M') >>> import sysfs >>> # Read/write Beaglebone Black's eQEP module attributes diff --git a/README.md b/README.md index d3ddf1a..656881b 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ Detecting events: #your amazing code here #detect wherever: if GPIO.event_detected("P9_12"): - print "event detected!" + print("event detected!") ### PWM **The PWM Duty Cycle range was reversed in 0.0.15 from 100(off)-0(on) to 0(off)-100(on). Please update your code accordingly.** @@ -202,7 +202,7 @@ ser = serial.Serial(port = "/dev/ttyO1", baudrate=9600) ser.close() ser.open() if ser.isOpen(): - print "Serial is open!" + print("Serial is open!") ser.write("Hello World!") ser.close() ``` diff --git a/source/examples/python/i2ctmp101.py b/source/examples/python/i2ctmp101.py index 923c0f9..ab916c0 100755 --- a/source/examples/python/i2ctmp101.py +++ b/source/examples/python/i2ctmp101.py @@ -8,5 +8,5 @@ while True: temp = bus.read_byte_data(address, 0) - print (temp, end="\r") + print(temp, end="\r") time.sleep(0.25) diff --git a/test/notes/spi_loopback_test.md b/test/notes/spi_loopback_test.md index 0f93d0c..7041852 100644 --- a/test/notes/spi_loopback_test.md +++ b/test/notes/spi_loopback_test.md @@ -46,7 +46,7 @@ from Adafruit_BBIO.SPI import SPI #spi = SPI(1,1) #/dev/spidev2.1 spi = SPI(0,0) -print spi.xfer2([32, 11, 110, 22, 220]) +print(spi.xfer2([32, 11, 110, 22, 220])) spi.close() ``` diff --git a/test/start_all_pwm.py b/test/start_all_pwm.py index 58d02f5..f19ef97 100644 --- a/test/start_all_pwm.py +++ b/test/start_all_pwm.py @@ -20,7 +20,7 @@ # /sys/devices/platform/ocp/48304000.epwmss/48304100.ecap/pwm/pwmchip5/pwm-5:0/duty_cycle for pin in pins: - print pin + print(pin) PWM.start(pin, 50, 2000, 1) PWM.stop(pin) PWM.cleanup() From 783bfacee8fa013adf60c3f98b334d5f57fe52b3 Mon Sep 17 00:00:00 2001 From: Sam Bristow Date: Tue, 9 Oct 2018 23:39:43 +1300 Subject: [PATCH 2/2] Use new python-serial API Version 3.0 of python-serial introduced an updated API, we may as well use it. This change also uses context-managers for dealing with UARTs as they are less error-prone and the code is much cleaner/shorter. --- README.md | 9 +++------ docs/UART.rst | 10 +++------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 656881b..cc179c2 100644 --- a/README.md +++ b/README.md @@ -198,13 +198,10 @@ import serial UART.setup("UART1") -ser = serial.Serial(port = "/dev/ttyO1", baudrate=9600) -ser.close() -ser.open() -if ser.isOpen(): +with serial.Serial(port = "/dev/ttyO1", baudrate=9600) as ser: print("Serial is open!") - ser.write("Hello World!") -ser.close() + ser.write(b"Hello World!") + ``` * Available UART names on BeagleBone * `UART1`: /dev/ttyO1, Rx: P9_26, Tx: P9_24 diff --git a/docs/UART.rst b/docs/UART.rst index 3566803..c3d238d 100644 --- a/docs/UART.rst +++ b/docs/UART.rst @@ -14,13 +14,9 @@ Example:: UART.setup("UART1") - ser = serial.Serial(port = "/dev/ttyO1", baudrate=9600) - ser.close() - ser.open() - if ser.isOpen(): - print "Serial is open!" - ser.write("Hello World!") - ser.close() + with serial.Serial(port = "/dev/ttyO1", baudrate=9600) as ser: + print("Serial is open!") + ser.write(b"Hello World!") .. module:: Adafruit_BBIO.UART pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy