本文介绍了如何用pyserial打开串口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 python 打开一个串口.这是在 Ubuntu 上.我导入 openinterface.py 并输入这个

I am trying to open a serial port with python. This is on Ubuntu. I import the openinterface.py and enter in this

ser = openinterface.CreateBot(com_port = "/dev/ttyUSB1", mode="full")

我收到一条错误消息,提示- 的操作数类型不受支持:‘str’和‘int’"我尝试使用单引号而不是双引号进行相同的调用,并且根本没有引号.

I get an error saying "unsupported operand types for -: 'str' and 'int'" I tried the same call with single quotes instead of double, and with no quotes at all.

我该如何解决这个问题?或者是否有其他功能可以使用?我只知道 Python 的基础知识,所以也许我没有注意到它的一些小语​​法?任何帮助将不胜感激,谢谢.

How can I fix this? Or is there an alternative function to use? I only know the basics of Python so maybe its some small syntax thing I am not noticing? Any help would be appreciated, thanks.

推荐答案

根据 俄语页面openinterface.py 文件存在一个错误,试图从端口参数中减去一个.它建议使用 sed 进行此更改(删除第 803 行的 -1):

According to this page in Russian, there's a bug with the openinterface.py file that tries to subtract one from the port argument. It suggests making this change (removing the - 1 on line 803) with sed:

sed -ie "803s/ - 1//" openinterface.py

要么尝试一下,要么看看是否有 openinterface.py 的更新版本.

Either try that, or see if there's an updated version of openinterface.py.

这篇关于如何用pyserial打开串口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-13 14:53