Re: Async serial communication/threads sharing data

Discussion in 'Python' started by Jean-Paul Calderone, Mar 22, 2009.

  1. On Sat, 21 Mar 2009 13:52:21 -0700 (PDT), Nick Timkovich <> wrote:
    >I've been working on a program that will talk to an embedded device
    >over the serial port, using some basic binary communications with
    >messages 4-10 bytes long or so. Most of the nuts and bolts problems
    >I've been able to solve, and have learned a little about the threading
    >library to avoid blocking all action while waiting for responses
    >(which can take 50 ms to 10 s). Ultimately, this program will test
    >the device on the COM port by sending it messages and collecting
    >responses for 10k-100k cycles; a cycle being:
    > 1. tell it to switch a relay,
    > 2. get it's response from the event,
    > 3. ask it for some measurements,
    > 4. get measurements,
    > 5. repeat.
    >Later I would like to develop a GUI as well, but not a big issue now
    >(another reason to use threads? not sure).


    Twisted includes serial port support and will let you integrate with a
    GUI toolkit. Since Twisted encourages you to write programs which deal
    with things asynchronously in a single thread, if you use it, your
    concerns about data exchange, locking, and timing should be addressed
    as a simple consequence of your overall program structure.

    Jean-Paul
    Jean-Paul Calderone, Mar 22, 2009
    #1
    1. Advertising

  2. On Mar 21, 9:19 pm, Jean-Paul Calderone <> wrote:
    > On Sat, 21 Mar 2009 13:52:21 -0700 (PDT), Nick Timkovich <> wrote:
    > >I've been working on a program that will talk to an embedded device
    > >over the serial port, using some basic binary communications with
    > >messages 4-10 bytes long or so.  Most of the nuts and bolts problems
    > >I've been able to solve, and have learned a little about the threading
    > >library to avoid blocking all action while waiting for responses
    > >(which can take 50 ms to 10 s).  Ultimately, this program will test
    > >the device on the COM port by sending it messages and collecting
    > >responses for 10k-100k cycles; a cycle being:
    > > 1. tell it to switch a relay,
    > > 2. get it's response from the event,
    > > 3. ask it for some measurements,
    > > 4. get measurements,
    > > 5. repeat.
    > >Later I would like to develop a GUI as well, but not a big issue now
    > >(another reason to use threads? not sure).

    >
    > Twisted includes serial port support and will let you integrate with a
    > GUI toolkit.  Since Twisted encourages you to write programs which deal
    > with things asynchronously in a single thread, if you use it, your
    > concerns about data exchange, locking, and timing should be addressed
    > as a simple consequence of your overall program structure.
    >
    > Jean-Paul


    I've looked at Twisted a little bit because of some searches on serial
    port comm turning up advice for it. However, there seems to be no/
    minimal documentation for the serial portions, like they are some old
    relic that nobody uses from this seemingly massive package. Do you
    have any examples or somewhere in particular you could point me?

    Thanks for the responses,
    Nick
    Nick Timkovich, Mar 22, 2009
    #2
    1. Advertising

  3. "Nick Craig-Wood" <ni...g-wood.com> wrote:

    >
    > I wrote a serial port to TCP proxy (with logging) with twisted. The
    > problem I had was that twisted serial ports didn't seem to have any
    > back pressure. By that I mean I could pump data into a 9600 baud
    > serial port at 10 Mbit/s. Twisted would then buffer the data for me
    > using 10s or 100s or Megabytes of RAM. No data would be lost, but
    > there would be hours of latency and my program would use up all my RAM
    > and explode.
    >
    > What I wanted to happen was for twisted to stop taking the data when
    > the serial port buffer was full and to only take the data at 9600
    > baud.
    >
    > I never did solve that problem :-(
    >


    Not sure if this is Twisted's fault -
    do python sockets have
    automatic back pressure?
    Do Linux sockets have back pressure?

    - Hendrik
    Hendrik van Rooyen, Mar 23, 2009
    #3
  4. Jean-Paul Calderone

    John Nagle Guest

    Hendrik van Rooyen wrote:
    > "Nick Craig-Wood" <ni...g-wood.com> wrote:
    >
    >> I wrote a serial port to TCP proxy (with logging) with twisted. The
    >> problem I had was that twisted serial ports didn't seem to have any
    >> back pressure.

    >
    > Not sure if this is Twisted's fault -
    > do python sockets have
    > automatic back pressure?
    > Do Linux sockets have back pressure?


    Yes, and yes.

    John Nagle
    John Nagle, Mar 24, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sundar

    sync/async serial comm..

    Sundar, Nov 21, 2006, in forum: C Programming
    Replies:
    3
    Views:
    489
    osmium
    Nov 21, 2006
  2. Nick Timkovich
    Replies:
    2
    Views:
    333
    Hendrik van Rooyen
    Mar 22, 2009
  3. Jean-Paul Calderone

    Re: Async serial communication/threads sharing data

    Jean-Paul Calderone, Mar 22, 2009, in forum: Python
    Replies:
    1
    Views:
    525
  4. Jean-Michel Pichavant
    Replies:
    2
    Views:
    412
    Dennis Lee Bieber
    Apr 14, 2011
  5. Steven
    Replies:
    0
    Views:
    347
    Steven
    Nov 30, 2005
Loading...

Share This Page