pyserial: failed to readlines() after many hours running.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zxo102

    #1

    pyserial: failed to readlines() after many hours running.

    Hello All,

    I have a system. An instrument attched to 'com1' is wireless connected
    to many sensors at different locations. The instrument can forward
    the "commands" (from pyserial's write()) to those sensors. Based on
    the "commands", the sensors keep sending corresponding data back to
    the instrument which wraps up those data and put into "com1" . The
    readlines() of pyserial pick up those data for processing.
    The data ’string' does not have "\n".

    With the following pythong script, if timeout = 0.1, ser.readlines()
    in thread1 failed to receive any data after approximate 20 hours. if
    timeout=0.5, ser.readlines() in thread1 failed to receive any data
    after approximate 60 hours. I am not sure the thread1 was dead or
    not. But the whole script did not throw out any error information and
    ser.write() in thread2 was ok and kept sending "commands" to com1.

    I am testing "timeout = 1" right now, it will probably take more days
    to fail to receive data.

    Anybody knows how long I should set for "timeout"? Since the data are
    from different sensors, I have no idea when they arrive at com1 via
    that instrument. If the timeout is set too long, com1 (com1 has
    buffer? Sorry, I don't know very much about hardwares) can not have
    enough buffer to hold those coming data before ser.readlines() . Or how
    does ser.readlines() work?

    Should I use readline() instead of readlines()?

    Thanks for your any help in advance.

    The below is the script:


    In thread 1:

    import serial, time

    ser=serial.Seri al('com1', baudrate=9600, bytesize=8, parity='N',
    stopbits=1, timeout=0.1,xon xoff=0, rtscts=0)

    while 1:
    reading = ser.readlines()
    for i in range(len(readi ng)):
    if len(reading[i]) 0:
    aa = map(ord, reading[i])
    bb = ["%02X"%aa[k] for k in range(len(aa))]
    # do something here
    else:
    pass
    time.sleep(Read ComSleepTime)
    ser.close()

    In thread 2:
    ....
    while 1:
    ...
    ser.write("some commands here")
    ...
    time.sleep(30)



    Best Regards

    ouyang
  • Grant Edwards

    #2
    Re: pyserial: failed to readlines() after many hours running.

    On 2008-10-11, zxo102 <zxo102@gmail.c omwrote:
    I have a system. An instrument attched to 'com1' is wireless connected
    to many sensors at different locations. The instrument can forward
    the "commands" (from pyserial's write()) to those sensors. Based on
    the "commands", the sensors keep sending corresponding data back to
    the instrument which wraps up those data and put into "com1" . The
    readlines() of pyserial pick up those data for processing.
    The data ?string' does not have "\n".
    If the data you're reading doesn't contain "\n", then you can't
    use readline() or readlines().

    --
    Grant Edwards grante Yow! I smell a RANCID
    at CORN DOG!
    visi.com

    Comment

    • Grant Edwards

      #3
      Re: pyserial: failed to readlines() after many hours running.

      On 2008-10-11, Grant Edwards <invalid@invali dwrote:
      On 2008-10-11, zxo102 <zxo102@gmail.c omwrote:
      >
      >I have a system. An instrument attched to 'com1' is wireless
      >connected to many sensors at different locations. The
      >instrument can forward the "commands" (from pyserial's
      >write()) to those sensors. Based on the "commands", the
      >sensors keep sending corresponding data back to the instrument
      >which wraps up those data and put into "com1" . The
      >readlines() of pyserial pick up those data for processing. The
      >data ?string' does not have "\n".
      >
      If the data you're reading doesn't contain "\n", then you can't
      use readline() or readlines().
      P.S.

      To the OP: I normally block postings from google groups (which
      is where almost all Usenet spam comes from), so I only saw your
      posting because I was experimenting with my spam filtering.
      I'll only see additional postings if you post from a real news
      server or if somebody who does so quotes one of your postings.

      Yes, that sort of sucks. But, until Google shuts off the spam
      spigot, you're going to get short shrift if you post from
      Google.

      There are plenty of free news servers for the text groups like
      c.l.p, or you can post to the mailing list via gmane.org.

      --
      Grant Edwards grante Yow! They collapsed
      at ... like nuns in the
      visi.com street ... they had no
      teen appeal!

      Comment

      • Terry Reedy

        #4
        Re: pyserial: failed to readlines() after many hours running.

        Unknown wrote:
        On 2008-10-11, zxo102 <zxo102@gmail.c omwrote:
        >
        >I have a system. An instrument attched to 'com1' is wireless connected
        >to many sensors at different locations. The instrument can forward
        >the "commands" (from pyserial's write()) to those sensors. Based on
        >the "commands", the sensors keep sending corresponding data back to
        >the instrument which wraps up those data and put into "com1" . The
        >readlines() of pyserial pick up those data for processing.
        >The data ?string' does not have "\n".
        Do you have the option of having the instrument insert them between
        readings?
        >
        If the data you're reading doesn't contain "\n", then you can't
        use readline() or readlines().
        Use .read() instead.

        Comment

        • zxo102

          #5
          Re: pyserial: failed to readlines() after many hours running.

          On 10ÔÂ11ÈÕ, ÏÂÎç11ʱ00·Ö, Grant Edwards <invalid@invali dwrote:
          On2008-10-11,zxo102<zxo.. .@gmail.comwrot e:
          >
          I have a system. An instrument attched to 'com1' is wireless connected
          to many sensors at different locations. The instrument can forward
          the "commands" (from pyserial's write()) to those sensors. Based on
          the "commands", the sensors keep sending corresponding data back to
          the instrument which wraps up those data and put into "com1" . The
          readlines() of pyserial pick up those data for processing.
          The data ?string' does not have "\n".
          >
          If the data you're reading doesn't contain "\n", then you can't
          use readline() or readlines().
          >
          --
          Grant Edwards grante Yow! I smell a RANCID
          at CORN DOG!
          visi.com
          But readlines() can read data out of 'com1' for many hours. Maybe I
          should try read().

          Ouyang

          Comment

          • zxo102

            #6
            Re: pyserial: failed to readlines() after many hours running.

            On 10ÔÂ12ÈÕ, ÉÏÎç1ʱ13·Ö, Terry Reedy <tjre...@udel.. eduwrote:
            Unknown wrote:
            On2008-10-11,zxo102<zxo.. .@gmail.comwrot e:
            >
            I have a system. An instrument attched to 'com1' is wireless connected
            to many sensors at different locations. The instrument can forward
            the "commands" (from pyserial's write()) to those sensors. Based on
            the "commands", the sensors keep sending corresponding data back to
            the instrument which wraps up those data and put into "com1" . The
            readlines() of pyserial pick up those data for processing.
            The data ?string' does not have "\n".
            >
            Do you have the option of having the instrument insert them between
            readings?
            >
            >
            >
            If the data you're reading doesn't contain "\n", then you can't
            use readline() or readlines().
            >
            Use .read() instead.
            I can not have the instrument insert "\n" between readings. That is
            out of my control. I can try read(). Thanks.

            Ouyang

            Comment

            Working...