Micropython学习笔记--Python语言实现串口读写
前文提到,HaaS Python轻应用是对Micropython的深度定制和扩展,本节开始,将详细介绍基于HaaS Python轻应用如何完成串口数据读写
运行的硬件环境: HaaS100开发板,HaaS EDK K1等
# coding=utf-8
# This is a sample Python script.
import utime
from driver import UART
print("-------------------uart test--------------------")
print("-----How to test: connect PIN10 and PIN12-------")
uart = UART();
uart.open("serial2")
utime.sleep_ms(1000)
writeBuf = bytearray([0x41, 0x42, 0x43, 0x44]);
for i in range(10):
uart.write(writeBuf)
utime.sleep_ms(1000)
readBuf = bytearray(4)
recvSize = uart.read(readBuf)
utime.sleep_ms(100)
print(recvSize)
print(readBuf)
uart.close()
钉钉扫码入群,获取更多python轻应用相关的知识,有软件专家事实解答您的问题。