Created
June 12, 2019 04:58
-
-
Save dramamine/c7e02ac24ece61ab135b7a946fec2254 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aioserial | |
import asyncio | |
# find port name by printing them all out | |
import serial.tools.list_ports | |
print([comport.device for comport in serial.tools.list_ports.comports()]) | |
# callback for values. try setting this to a useful function | |
listener = None | |
async def get_values(aioserial_instance: aioserial.AioSerial): | |
while True: | |
text = (await aioserial_instance.readline_async()).decode(errors='ignore') | |
try: | |
val = int(text) | |
except: | |
val = 0 | |
print('my val:', val) | |
if val > 0: | |
# do something | |
if listener: | |
listener(val) | |
def run(): | |
asyncio.run(get_values(aioserial.AioSerial(port='COM3'))) | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment