473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

How to display variable serial data on Tkinter window.

Expand|Select|Wrap|Line Numbers
  1. import serial
  2. import threading
  3. import Queue
  4. import Tkinter as tk
  5.  
  6.  
  7. class SerialThread(threading.Thread):
  8.     def __init__(self, queue):
  9.         threading.Thread.__init__(self)
  10.         self.queue = queue
  11.     def run(self):
  12.         s = serial.Serial('COM10',9600)
  13.         while True:
  14.             if s.inWaiting():
  15.                 text = s.readline(s.inWaiting())
  16.                 self.queue.put(text)
  17.  
  18. class App(tk.Tk):
  19.     def __init__(self):
  20.         tk.Tk.__init__(self)
  21.         self.geometry("1360x750")
  22.         frameLabel = tk.Frame(self, padx=40, pady =40)
  23.         self.text = tk.Text(frameLabel, wrap='word', font='TimesNewRoman 37',
  24.                             bg=self.cget('bg'), relief='flat')
  25.         frameLabel.pack()
  26.         self.text.pack()
  27.         self.queue = Queue.Queue()
  28.         thread = SerialThread(self.queue)
  29.         thread.start()
  30.         self.process_serial()
  31.  
  32.     def process_serial(self):
  33.         while self.queue.qsize():
  34.             try:
  35.                 self.text.delete(1.0, 'end')
  36.                 self.text.insert('end', self.queue.get())
  37.             except Queue.Empty:
  38.                 pass
  39.         self.after(1500, self.process_serial)
  40.  
  41. app = App()
  42. app.mainloop()  
  43.  

This code is to receive serial data and to print on the Tkinter window until it receives other serial data. When it receives other serial data, the first received serial data which is displaying on window should wipe out and the new arrived serial data had to display on the Tkinter window. This process will happen for every received serial data.
I had 2 issues here:

1.In the code
[self.root.after(1500, self.process_serial)]
Here the first text will display and wait for 1500ms, then second text will display and wait for 1500ms, it will keep on doing this.
but in my code i don't know when i receive the serial data,if i receive serial data, this data should display until i receive other serial data to print on the window.The time is variable(changing) in between the data which is received.

In brief:Here transmitter will send data, my code is just to receive data and print on the window. The transmitter might send data in 10 seconds or in 4 minutes or in 10 minutes. The receiver don't know when the transmitter sends the data.
so when transmitter sends the data, i want to receive data and display it until it receives other serial data again. In my code if i use 1500ms, the serial received data is just displaying for 1500ms. I dont want to just display for 1500ms, the data should be on the screen until it receives other serial data.

2. If i receive just a single line of ASCII data, that should print in the middle of the window. Transmitter will send variable data, and this data should display on the window. When we receive 3 or 4 lines of ASCII data, this data should print at the middle of the window by leaving some space at the top and bottom of the window. Irrespective of the size of the received data, it automatically adjust the data to print on the window.

In breif:The font i choose is 37 in my code.with this font size i can print 9 lines on the window. if i receive 1 line of data,this data should print on 5th line, by leaving equal amount of space at top and bottom of the window.Again i may receive 3 line of serial data, this data should print from 4th to 6th line of the window by leaving equal space on top and bottom.Again if i receive 6 lines of serial data, this should print from 2nd line to 7th line on the window. Irrespective of data size, data should print on window,by leaving equal amount of spaces at top and bottom of the window. This display will make a good impression to see on the window.
So what i have to do in my code to achieve this kind of display.
please help me out.
thank you..
Jun 22 '13 #1
0 1969

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sonoman | last post by:
Hello everyone: I am new to Visual Basic and I have a problem that I cannot put my finger on. I am working on a school project and I am getting some serial data from a microprocessor. I have...
0
by: Dave | last post by:
Hi, I am using an active x control that display an image on it window, i want to get the image data into a byte buffer but the active x control dont expose any function that fill a buffer with its...
6
by: Tom Allison | last post by:
Can I use the serial data type in lieu of an 'auto_number' field? I asked something like this some months ago and it seems that auto_number fields were addressed through a combination of triggers...
1
by: dbuchanan | last post by:
Hello, A section in Data Sources window is mystifying to me. In the case of my code the Data Sources window shows my references to the data access layer. First here is what I see in my Data...
36
by: Chuck Faranda | last post by:
I'm trying to debug my first C program (firmware for PIC MCU). The problem is getting serial data back from my device. My get commands have to be sent twice for the PIC to respond properly with...
10
by: David Lee Conley | last post by:
When I open the Data Sources window and create a new data source, everything works fine. But if I have a form showing in the IDE, the Data Sources window becomes disabled and doesn't display any...
2
by: Ed | last post by:
Please help! I have a string of data as the result of serial to parallel hardware conversion. I need to decode this string into correct bytes. The start of a byte position is unknown. In this...
1
by: marsha | last post by:
i have problem with my script. i have input from several sensor then i send to serial port. the serial data received with vb. data appear not in a single data, but in some packet. so, how to...
2
by: vagaisuresh | last post by:
Dear Friends, Dealers details retreived from database and display in a asp file. I want to display the serial number. I don't know, how to display the serial number. anybody help me Thanks...
1
by: npm | last post by:
I'm trying to find out why the android browser won't load and/or display my XML data. This javascript works fine on computer browsers (FF, IE, Safari, Chrome, Opera) and even in iPhone's Safari, but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.