不一致的串行失败 [英] Inconsistent serial fails

查看:41
本文介绍了不一致的串行失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个基于 python tkinter 的应用程序,它可以从我的 arduino 传感器平台读取数据.

I am trying to develop a python tkinter based app that would read the data from my arduino sensor platform.

我收到不一致的错误,我不明白为什么会发生这种情况.

I am getting inconsistent errors that i can't understand why this happens.

首先,这应该归咎于代码:

First of all, this is the code that is to blame:

def readSerial():
   print("1")
   global after_id
   print("2")
   ser_bytes = ser.readline()
   print("3")
   ser_bytes = ser_bytes.decode("utf-8")
   print("4")
   text.insert("end", ser_bytes)
   print("5")
   after_id = root.after(50, readSerial)

  1. 有时这行得通.数据出现在我的 tkinter 框架上,因为字符 1、2、3、4、5 在终端中不断向下滚动.这是最罕见的情况.

  1. 其他时候终端打印继续下降,但我的 tkinter 文本框中没有任何内容.当我再次按下读取按钮时,终端中的数字停止打印,但序列中的文本出现在我的 tkinter 框架上.这怎么可能,我无法理解.

  1. Other times the terminal printing keeps on going down, but nothing appears on my tkinter text frame. When i press the read button again, the numbers stop printing in the terminal, but the text from the serial appear on my tkinter frame. How is this possible i cannot understand.

有时终端打印继续下降,但我的 tkinter 文本框架上没有任何显示.如果我再次按下开始阅读"按钮,程序将卡住,按钮将保持灰色,终端中的打印将停止.

Some times the terminal printing keeps on going down, but nothing appears on my tkinter text frame. If i press the 'start reading' button again, the program will get stuck, the button will remain gray, the print in the terminal will stop.

  1. 有时我会因为某种原因冻结.使程序冻结,否则停止按钮将使其冻结.

我不仅不明白为什么除了 (1) 之外的行为 - 正常情况发生,我不明白为什么会触发什么行为没有一致性.行为 2、3 或 4 何时会发生,为什么?是什么触发了每个特定的行为?

Not only i cannot understand why the behaviors except (1) - the normal case occur, i don't understand why there is no consistency in what behavior will be triggered. When behavior 2, or 3 or 4 will happen and why? What triggers each specific behavior?

有人能理解发生了什么吗?

Can someone understand what is going on?

推荐答案

我会问自己关于你的设置(我不知道电路是什么):

I would ask myself about your setup (which I don't know what the circuit is):

  1. 您是否使用独立于 Arduino 链接的测试数据测试了您的代码.
  2. 您是否检查过来自 Arduino 的数据的有效性.
  3. 您采取了哪些措施来避免输入数据时引入噪音.

这篇关于不一致的串行失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆