pyvisa如果没有就在终端中安装pip3 install pyvisa
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import time
import os
import pyvisa
def test():
rm = pyvisa.ResourceManager()
print(rm.list_resources())
# 打开串口
my_ins = rm.open_resource('ASRL20::INSTR')
# 设置波特率
my_ins.baud_rate = 115200
print(my_ins)
# 发送命令
my_ins.write('press')
time.sleep(0.5)
# 成功
result = my_ins.read()
print(result)
该博客展示了如何使用Python库Pyvisa来管理资源并进行串口通信。通过实例代码,作者演示了如何打开串口、设置波特率、发送命令以及接收响应,从而实现设备间的通讯。
1337

被折叠的 条评论
为什么被折叠?



