LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-16-2019, 04:42 PM   #1
RonHof
LQ Newbie
 
Registered: Aug 2006
Posts: 23

Rep: Reputation: 1
read serial port and display data in tkinter gui


This is related to a couple of my previous questions but different enough to use a new thread. I'm trying to read the serial out put of a legacy piece of hardware and display it in a tkinter GUI. I've made a lot of progress with all your help but this current problem has me baffled. The hardware is basically a timer. I've opened the serial port as ttyUSB0)
Code:
ser = serial.Serial(
        port='/dev/ttyUSB0',
        baudrate = 4800,
        parity = serial.PARITY_NONE,
        stopbits = serial.STOPBITS_TWO,
        bytesize = serial.EIGHTBITS,
        timeout=1
        )
I'm reading the data stream with
Code:
Str = ser.readline(8)
    print (Str)#debug statement
    Str = Str.decode('cp1250','strict').replace("60","GO").strip()
    print ("decoded string =", Str)#debug statement
    print ("")#debug statement
the number is 7 characters long and the number of leading spaces changes depending on the value. The debug print looks like this
Quote:
b' 0.30\r'
decoded string = 0.30

b' 0.30\r'
decoded string = 0.30

b' 0.30\r'
decoded string = 0.30
The GUI is happy and displays the text.
Now the problem:

When the GO button is pressed an integer 60 is passed but the number of spaces before and after changes with each word. This was done to cause the integer 60 to move down a digital display board. The problem is that this causes the 60 to jump around on the GUI display and when the number wraps around the EOL marker the GUI splits the number into two lines. Then somehow the read gets out of sync with the word spacing and even the floating point seconds nomber is moved or line wraped. The debug print looks like this:
Code:
b'    60\r '
decoded string = GO

b'   60\r  '
decoded string = GO

b'  60\r   '
decoded string = GO

b' 60\r    '
decoded string = GO

b'60\r    6'
decoded string = GO
    6

b'0\r    60'
decoded string = 0
    GO
I tried stripping the spaces out and that helped but it still wraps the integer 60 and the decimal seconds when the EOL is not the 8th character read. What am I missing in reading this serial data? Any thoughts? Thanks
 
Old 10-17-2019, 02:41 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,871
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Don't read fix number of bytes, read lines. In some other topic you have already found ser.eol= '\r' (or similar), now use that.

Last edited by NevemTeve; 10-17-2019 at 02:44 AM.
 
Old 10-17-2019, 03:28 PM   #3
RonHof
LQ Newbie
 
Registered: Aug 2006
Posts: 23

Original Poster
Rep: Reputation: 1
Thanks!
I also found that readline.replace(b"\r",b"\r\n") works
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Four-port KVM switch that sends keyboard data to PS2 port and mouse data to USB port Ulysses_ Linux - Hardware 5 06-20-2015 11:16 AM
the get data from serial port function read() blocks when data not available DEF. Programming 3 11-17-2014 07:11 AM
[SOLVED] Serial port : Read data problem, not reading complete data anujmehta Linux - Networking 5 09-06-2010 06:10 AM
Tkinter-GUI: how to make btuttons the same size? raskol Programming 1 04-06-2008 11:04 AM
is there any shell command to read and write data from parallel and serial port? baosheng Linux - Hardware 2 01-13-2007 08:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration