<small id='kcZgG'></small><noframes id='kcZgG'>

  1. <legend id='kcZgG'><style id='kcZgG'><dir id='kcZgG'><q id='kcZgG'></q></dir></style></legend>
    <tfoot id='kcZgG'></tfoot>

      <i id='kcZgG'><tr id='kcZgG'><dt id='kcZgG'><q id='kcZgG'><span id='kcZgG'><b id='kcZgG'><form id='kcZgG'><ins id='kcZgG'></ins><ul id='kcZgG'></ul><sub id='kcZgG'></sub></form><legend id='kcZgG'></legend><bdo id='kcZgG'><pre id='kcZgG'><center id='kcZgG'></center></pre></bdo></b><th id='kcZgG'></th></span></q></dt></tr></i><div id='kcZgG'><tfoot id='kcZgG'></tfoot><dl id='kcZgG'><fieldset id='kcZgG'></fieldset></dl></div>

        <bdo id='kcZgG'></bdo><ul id='kcZgG'></ul>

      Pyserial 不能很好地使用虚拟端口

      Pyserial does not play well with virtual port(Pyserial 不能很好地使用虚拟端口)

        <i id='ukfMp'><tr id='ukfMp'><dt id='ukfMp'><q id='ukfMp'><span id='ukfMp'><b id='ukfMp'><form id='ukfMp'><ins id='ukfMp'></ins><ul id='ukfMp'></ul><sub id='ukfMp'></sub></form><legend id='ukfMp'></legend><bdo id='ukfMp'><pre id='ukfMp'><center id='ukfMp'></center></pre></bdo></b><th id='ukfMp'></th></span></q></dt></tr></i><div id='ukfMp'><tfoot id='ukfMp'></tfoot><dl id='ukfMp'><fieldset id='ukfMp'></fieldset></dl></div>
          • <bdo id='ukfMp'></bdo><ul id='ukfMp'></ul>
          • <tfoot id='ukfMp'></tfoot>
              <tbody id='ukfMp'></tbody>

            <small id='ukfMp'></small><noframes id='ukfMp'>

              • <legend id='ukfMp'><style id='ukfMp'><dir id='ukfMp'><q id='ukfMp'></q></dir></style></legend>
                本文介绍了Pyserial 不能很好地使用虚拟端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                动机

                我想开始学习如何使用 python 库 Pyserial.这似乎是一个非常好的图书馆,适用于很多人.我想在即将进行的项目中使用它,在该项目中我必须自动化串行通信.

                I want to start leraning how to use the python library Pyserial. It seems like a really nice library that works for a lot of people. I want to use it for an upcoming project in which I have to automate serial communications.

                环境

                我正在运行 Ubuntu 15.04.我正在使用 Python 2.7.

                I'm running Ubuntu 15.04. I'm using Python 2.7.

                设置虚拟端口

                我目前没有可以通过串行端口与之通信的设备.我正在使用 socat 应用程序创建两个虚拟端口,它们通过波特率9600.

                I don't currently have a device that I can communicate with over a serial port. I'm using the socat application to create two virtual ports that are connected to each other with a baudrate of 9600.

                $ socat -d -d pty,raw,echo=0,b9600 pty,raw,echo=0,b9600
                2016/01/16 12:57:51 socat[18255] N PTY is /dev/pts/2
                2016/01/16 12:57:51 socat[18255] N PTY is /dev/pts/4
                2016/01/16 12:57:51 socat[18255] N starting data transfer loop with FDs [5,5] and [7,7]
                $ echo "hello" > /dev/pts/2
                $ cat /dev/pts/4
                hello
                

                太棒了!似乎端口可以工作!

                Great! It seems like the ports work!

                一个简单的pyserial脚本

                我使用 pip 安装 pyserial

                I install pyserial using pip

                $ sudo pip install pyserial
                

                然后我写了一点serialtest.py

                Then I wrote a little serialtest.py

                #!/usr/bin/env python
                import serial
                
                ser = serial.Serial('/dev/pts/2', 9600)
                

                这就是整个serialtest.py

                That is the entirety of serialtest.py

                运行脚本并遇到错误

                $ python serialtest.py 
                Traceback (most recent call last):
                  File "serialtest.py", line 4, in <module>
                    ser = serial.Serial('/dev/pts/2')
                  File "/home/sbl/.local/lib/python2.7/site-packages/serial/serialutil.py", line 180, in __init__
                    self.open()
                  File "/home/sbl/.local/lib/python2.7/site-packages/serial/serialposix.py", line 311, in open
                    self._update_dtr_state()
                  File "/home/sbl/.local/lib/python2.7/site-packages/serial/serialposix.py", line 605, in _update_dtr_state
                    fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_DTR_str)
                IOError: [Errno 22] Invalid argument
                

                这是怎么回事?

                调试尝试失败

                这家伙说他用python 2.6成功了.我无法让 Pyserial 与 2.6 一起使用.

                This guy said he had success when using python 2.6. I couldn't get Pyserial to work with 2.6.

                这家伙遇到了波特率问题.我使用命令 $stty -F/dev/pts/2 仔细检查了我的波特率,并确认它实际上是 9600 的波特率.

                This guy was having trouble with is baudrate. I double check my baudrate with the command $stty -F /dev/pts/2 and confirmed that it was, in fact, at a baudrate of 9600.

                这家伙还声称波特率有问题并将其归因于他的内核.那是在 2012 年,所以我认为它不再相关了.

                This guy also claims to have problems with baudrate and attributes it to his kernel. That was back in 2012, so I don't think it's relevant anymore.

                我的问题

                如何让我的 serialtest.py 脚本正常运行?

                How can I get my serialtest.py script to run without error?

                推荐答案

                为了完成这个问答,这是一个解决方案(在 Austin Philips 的链接中找到):

                To make this Q&A complete, this is a solution (as found in the link by Austin Philips):

                #!/usr/bin/env python
                import serial
                
                ser = serial.Serial('/dev/pts/2', 9600, rtscts=True,dsrdtr=True)
                

                有关详细说明,请参阅此 PySerial Github 问题.

                See this PySerial Github issue for more explanation.

                这篇关于Pyserial 不能很好地使用虚拟端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)

                      • <bdo id='GjW1J'></bdo><ul id='GjW1J'></ul>
                        <i id='GjW1J'><tr id='GjW1J'><dt id='GjW1J'><q id='GjW1J'><span id='GjW1J'><b id='GjW1J'><form id='GjW1J'><ins id='GjW1J'></ins><ul id='GjW1J'></ul><sub id='GjW1J'></sub></form><legend id='GjW1J'></legend><bdo id='GjW1J'><pre id='GjW1J'><center id='GjW1J'></center></pre></bdo></b><th id='GjW1J'></th></span></q></dt></tr></i><div id='GjW1J'><tfoot id='GjW1J'></tfoot><dl id='GjW1J'><fieldset id='GjW1J'></fieldset></dl></div>

                          <tbody id='GjW1J'></tbody>
                      • <small id='GjW1J'></small><noframes id='GjW1J'>

                        <legend id='GjW1J'><style id='GjW1J'><dir id='GjW1J'><q id='GjW1J'></q></dir></style></legend>
                        <tfoot id='GjW1J'></tfoot>