Get inline data from serial

不羁岁月 提交于 2019-12-25 08:43:39

问题


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)

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

Whereas in my TerminalPanel I get the following:

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

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


回答1:


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.

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



来源:https://stackoverflow.com/questions/27134603/get-inline-data-from-serial

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!