Python与Mbed的串行通信

2024-04-23 16:33:31 发布

您现在位置:Python中文网/ 问答频道 /正文

import serial
while True:
device = serial.Serial('/dev/ttyACM0')
data = device.readline()
print(data + '\n')

我有一个设备,它使用USB端口和pyserial在python中与raspberry pi通信。当用户在命令行输入“reset”时,我该怎么做才能重置设备?在


Tags: 端口devimporttruedatareadlinedeviceserial
2条回答

延迟答复,但您需要在设备上创建一些处理程序代码,该设备只要看到reset通过串行端口传入,NVIC_SystemReset()。在

你还没有指定“设备”是什么意思。假设设备是连接到Raspberry pi的Mbed设备,并且Python代码在Raspberry pi上运行。在

大多数Mbed设备可以通过在串行接口上发送中断条件来重置。请检查pySerial API以查看https://pyserial.readthedocs.io/en/latest/pyserial_api.html#serial.Serial.send_break

另外,检查这个工具在python2.7和3.xhttps://github.com/ARMmbed/htrun/blob/master/mbed_host_tests/host_tests_plugins/module_reset_mbed.py#L60中是如何完成的

相关问题 更多 >