Python使用pyserial进行串口通信
2018-02-06 18:23
603 查看
安装pyserial
查看可用的端口
2
3
4
5
6
7
8
9
10
11
12
13
所发十六进制需转换为以下格式
2
串口通信
Windows下端口为
pip install pyserial1
查看可用的端口
# coding:utf-8 import serial.tools.list_ports plist = list(serial.tools.list_ports.comports()) if len(plist) <= 0: print("没有发现端口!") else: plist_0 = list(plist[0]) serialName = plist_0[0] serialFd = serial.Serial(serialName, 9600, timeout=60) print("可用端口名>>>", serialFd.name)1
2
3
4
5
6
7
8
9
10
11
12
13
所发十六进制需转换为以下格式
# 所发十六进制字符串010591F50000F104 cmd = [0x01, 0x05, 0x91, 0xF5, 0x00, 0x00, 0xF1, 0x04]1
2
串口通信
Windows下端口为
COM*, Ubuntu下为
/dev/ttyS0
import serial class Ser(object): def __init__(self): # 打开端口 self.port = serial.Serial(port='COM4', baudrate=9600, bytesize=8, parity='E', stopbits=1, timeout=2) # 发送指令的完整流程 def send_cmd(self, cmd): self.port.write(cmd) response = self.port.readall() response = self.convert_hex(response) return response # 转成16进制的函数 def convert_hex(self, string): res = [] result = [] for item in string: res.append(item) for i in res: result.append(hex(i)) return result
相关文章推荐
- Python使用pyserial进行串口通信
- Raspberry pi 使用python+pySerial实现串口通信
- Python使用pyserial进行串口通信
- Raspberry pi 使用python+pySerial实现串口通信(转)
- 使用 Python 进行线程编程(转)
- 使用SWIG对Python进行扩展
- 使用 Python 进行线程编程
- 使用python+cron对php状态进行定时监控
- 使用 Google API 进行翻译的 Python 小工具
- 使用NetBeans IDE进行python编程: ImportError: No module named pygtk
- 使用python进行下载地址转换
- 使用rope进行Python代码补全
- 使用python进行桌面程序开发(一)
- 使用python进行桌面程序开发(二)
- 使用Python进行二进制文件读写
- 使用ropemacs对python代码进行补全
- 使用 Python 进行线程编程
- Solaris下使用tip进行串口通信
- 由于Python本身自带的界面库功能并不强大,我们使用Python+wxPython作为界面开发平台,在公司新的项目中进行界面开发。开发过程使用Eclipse+PyDev 作为集成开发环境。产品发布时使用Py2exe进行打包。如今,在我的团队中,Pytho
- windows下配置eclipse + Python + PyDev + tornado,并使用pylint进行静态检测