Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Serial connections and threads in a GUI

Reply
Thread Tools

Serial connections and threads in a GUI

 
 
Aaron Hoover
Guest
Posts: n/a
 
      09-29-2009
I have a wx-based GUI application that I'd like to have read
"streaming" data from a serial port and plot that data using
matplotlib and a figure canvas. It's a robotic application where the
workflow goes something like this:

1) Connect to robot
2) Configure robot settings
3) Command robot to do something for time, t
- While robot does something, read sensor data and plot
4) End of t seconds, resume at (2)

I have the application reading from the serial port in a separate
thread, but my problem is this - I'd like the user to be able to write
to the serial port by interacting with the GUI between runs. However,
the infinite loop running inside the thread responsible for receiving
data has exclusive access to the serial connection object.

Because of how the application works, I know that I won't need to
write to the serial port when I'm in the middle of receiving data, so
that simplifies things somewhat. But, how can I allow the thread
access to the connection for reading, but then have it give up control
over the connection when it's done so the main GUI thread can access
the connection again for writing?

Currently, I have the thread's run() method exit when it's done
receiving data. But, that means that I can only receive data again
using the same thread by calling run(), blocking the main GUI thread
from updating the plot until it completes.

This is my first go at using threads in Python, so I'm sure there's a
straightforward way to do this that I'm just missing. At any rate,
thanks in advance for your patience and assistance.


Thanks,
Aaron
 
Reply With Quote
 
 
 
 
sturlamolden
Guest
Posts: n/a
 
      09-30-2009
On 29 Sep, 23:56, Aaron Hoover <(E-Mail Removed)> wrote:
> how can I allow the thread *
> access to the connection for reading, but then have it give up control *
> over the connection when it's done so the main GUI thread can access *
> the connection again for writing?


Protect read/write access to the serial port with a lock.

Or use Candygram to pass Erlang-style messages to and from the thread
owning the serial port.
http://candygram.sourceforge.net/



 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fcntl, serial ports and serial signals on RS232. Max Kotasek Python 4 04-09-2010 06:32 PM
Lingering Idle Oracle Connections? Persistent connections? jobs ASP .Net 2 11-16-2007 03:37 AM
Which of my serial connections T1's h as failed? just bob Cisco 2 04-11-2007 05:17 PM
Does Ruby have support for serial connections - RS232?? Chris Finch Ruby 3 09-01-2006 01:13 AM
2 serial connections to the same router ? jh3ang Cisco 2 04-12-2006 12:22 AM



Advertisments