Search code examples
pythonwxpython

Get inline data from serial


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?


Solution

  • 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.