从串行获取内联数据 [英] Get inline data from serial

查看:26
本文介绍了从串行获取内联数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接收串行读取时,我的 TerminalPanel 类中有一个方法:

I have a method in my TerminalPanel class when receiving a serial read:

def OnSerialRead(self, event):
    """Handle input from the serial port."""
    text = event.data
    self.text_ctrl_output.AppendText(text)
    self.GetParent().graphics_panel.get_data(text)

现在,在 TerminalPanel 类中,文本完美地显示出来,但是在我的 GraphicsPanel 类中(在其他地方用 graphics_panel 实例化)我有这个方法:

Now, inside the TerminalPanel class the text comes out perfectly, but in my GraphicsPanel class (instantiated with graphics_panel somewhere else) I have this method:

def get_data(self, text):
    self.mario = text
    print self.mario

结果是我在我的终端上得到了这个:

The result is that I get this on my terminal:

20

14-1

1-25

20:

19:5

7 0

2 2

393

而在我的 TerminalPanel 中,我得到以下信息:

Whereas in my TerminalPanel I get the following:

2014-11-25 20:19:57 0 2 2 393

2014-11-25 20:19:57 0 2 2 393

你能帮我整理一下我的数据吗?

Could you please help me to get my data in order?

推荐答案

似乎 self.GetParent().graphics_panel.get_data(text) 被多次调用,每次 print self.mario 正在打印自然打印在新行上的文本.您可以将其更改为 sys.stdout.write(self.mario) 这将打印到同一行.您必须执行导入 sys",最好是在文件顶部,以使其正常工作.

Seems self.GetParent().graphics_panel.get_data(text) gets called multiple times and each time the print self.mario is printing the text which naturally prints on a new line. You can change it to sys.stdout.write(self.mario) which will print to the same line. You have to do an 'import sys', preferably at the top of the file, for this to work.

或者你可以做print self.mario,.注意末尾的逗号.

Alternatively you can do print self.mario,. Note the comma at the end.

这篇关于从串行获取内联数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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