Pyserial again

Discussion in 'Python' started by luca72, Mar 6, 2006.

  1. luca72

    luca72 Guest

    Hello

    I have solve the problem of configuration with pyserial but i have
    another question.
    The serial port close every time i make the read and re-open when i do
    i new write.
    In my script there is not write close , why it close ?

    Thaks Luca
     
    luca72, Mar 6, 2006
    #1
    1. Advertising

  2. On 2006-03-06, luca72 <> wrote:

    > I have solve the problem of configuration with pyserial but i
    > have another question. The serial port close every time i make
    > the read and re-open when i do i new write.


    I doubt it.

    > In my script there is not write close, why it close ?


    How on earth would we know what's wrong unless you post a small
    example program that exhibits the problem?

    If you want a WAG, here's one: the serial port object going
    out-of-scope and getting garbage collected.

    Please read this:

    http://www.catb.org/~esr/faqs/smart-questions.html

    --
    Grant Edwards grante Yow! Uh-oh!! I forgot
    at to submit to COMPULSORY
    visi.com URINALYSIS!
     
    Grant Edwards, Mar 6, 2006
    #2
    1. Advertising

  3. luca72

    Peter Hansen Guest

    luca72 wrote:
    > I have solve the problem of configuration with pyserial but i have
    > another question.
    > The serial port close every time i make the read and re-open when i do
    > i new write.


    Please describe what you are observing that makes you say that the port
    is closing.

    > In my script there is not write close , why it close ?


    Shall we guess again?

    -Peter
     
    Peter Hansen, Mar 6, 2006
    #3
  4. luca72

    luca72 Guest

    Hello here is a part of code, the values for settings comes from combo
    box:

    here i take the ATR of the smartcard inserted in the reader, and than i
    store the read data in a textctrl.
    Sniffing the data with serial port monitor i see that the answer is ok
    but after the answer the port close, why?
    Another point is the textctrl: it store only the first byte and not the
    other why?, the byte are like 22 and all are readed

    Thaks

    ser = serial.Serial(porta)
    ser.baudrate = (atr)
    ser.parity = (parity)
    ser.stopbits = (stop)
    ser.bytesize = (size)
    ser.setRTS(level = 0)
    ser.setDTR(level = 0)
    ser.timeout = (time)
    a = ser.readline()
    a = self.textCtrl3.SetValue(a + ' ')
    self.lettura()
    ser.setBaudrate(baud)
     
    luca72, Mar 6, 2006
    #4
  5. On 2006-03-06, luca72 <> wrote:

    > Hello here is a part of code,


    No.

    Wrong.

    The "part of code" you posted tells us nothing. We can not
    help you if you keep posting vague descriptions of what you
    imagine is wrong and small, out-of-context chunks of irrelevant
    code.

    ************************************************************
    * *
    * READ THIS: *
    * *
    * http://www.catb.org/~esr/faqs/smart-questions.html *
    * *
    ************************************************************

    You must post a small program that we can run. The whole
    program. Not just random chunks that have nothing to do with
    the problem.

    You must tell us what you want that program to do.

    You must tell us what you observe the program doing that you
    think is wrong.

    > the values for settings comes from combo box:
    >
    > here i take the ATR of the smartcard inserted in the reader,


    I don't know what "ATR" is. I probably don't care.

    > and than i store the read data in a textctrl.


    That's got nothing to do with pyserial.

    > Sniffing the data with serial port monitor i see that the
    > answer is ok but after the answer the port close, why?


    What makes you think the port closed?

    > Another point is the textctrl: it store only the first byte
    > and not the other why?, the byte are like 22 and all are
    > readed


    No clue. I don't know what "textctrl" is or what it's supposed
    to do.

    Your descriptions are useless. The code you post is irrelevant.

    We're trying to help you. If you refuse to cooperate, there
    isn't much we can do.

    If you keep this up, the people who could help you will give up
    and stop reading your posts.

    ************************************************************
    * *
    * READ THIS: *
    * *
    * http://www.catb.org/~esr/faqs/smart-questions.html *
    * *
    ************************************************************

    --
    Grant Edwards grante Yow! I'm having a MID-WEEK
    at CRISIS!
    visi.com
     
    Grant Edwards, Mar 6, 2006
    #5
  6. luca72

    Luca Guest

    > and than i store the read data in a textctrl.

    That's got nothing to do with pyserial.

    Ok i know but for this reason i put :

    Another point is the textctrl: it store only the first byte and not
    the
    other why?, the byte are like 22 and all are readed
    -------------------------------------------------------------------------------------------------------------------------------
    No clue. I don't know what "textctrl" is or what it's supposed
    to do.

    a = ser.readline()
    a = self.textCtrl3.SetValue(a + ' ')

    For my bad understanding is clear

    -------------------------------------------------------------------------------------------------------------------------------
    What makes you think the port closed?

    Sniffing the data with serial port monitor i see that the
    > answer is ok but after the answer the port close, why?


    The serial port monitor write com port close.

    ----------------------------------------------------------------------------------------------------------


    Dear Grant

    As you know i'm not a programmer, but i try to do this in my free time.
    Probably you have reason to write:

    The code you post is irrelevant.

    But i try to do my best as in my possibility.

    I think that in any case you can't run my code if you haven't the same
    device that i have.

    So i don't want that you loose time with my stupid question, i'm sure
    you have a lot of better things to do that help a beginner like me.

    In any case thanks for your help, and you cordility.

    Best Regards

    Luca
     
    Luca, Mar 6, 2006
    #6
  7. luca72

    Steve Holden Guest

    Luca wrote:
    >>and than i store the read data in a textctrl.

    >
    >
    > That's got nothing to do with pyserial.
    >
    > Ok i know but for this reason i put :
    >
    > Another point is the textctrl: it store only the first byte and not
    > the
    > other why?, the byte are like 22 and all are readed
    > -------------------------------------------------------------------------------------------------------------------------------
    > No clue. I don't know what "textctrl" is or what it's supposed
    > to do.
    >
    > a = ser.readline()
    > a = self.textCtrl3.SetValue(a + ' ')
    >
    > For my bad understanding is clear
    >
    > -------------------------------------------------------------------------------------------------------------------------------
    > What makes you think the port closed?
    >
    > Sniffing the data with serial port monitor i see that the
    >
    >>answer is ok but after the answer the port close, why?

    >
    >
    > The serial port monitor write com port close.
    >
    > ----------------------------------------------------------------------------------------------------------
    >
    >
    > Dear Grant
    >
    > As you know i'm not a programmer, but i try to do this in my free time.
    > Probably you have reason to write:
    >
    > The code you post is irrelevant.
    >
    > But i try to do my best as in my possibility.
    >
    > I think that in any case you can't run my code if you haven't the same
    > device that i have.
    >
    > So i don't want that you loose time with my stupid question, i'm sure
    > you have a lot of better things to do that help a beginner like me.
    >
    > In any case thanks for your help, and you cordility.
    >
    > Best Regards
    >
    > Luca
    >

    Luca:

    Grant was just pointing out that we can't tell you what's wrong with
    your code if we can't see it.

    Nobody expects you to be an experienced programmer. We just aren't
    understanding you at the moment. You say "the port closes", but this
    doesn't really have any standard meaning - can you not send data any more?

    Please be patient and answer our questions. We *are* trying to help!

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC/Ltd www.holdenweb.com
    Love me, love my blog holdenweb.blogspot.com
     
    Steve Holden, Mar 6, 2006
    #7
  8. On 2006-03-06, Luca <> wrote:

    >>> Another point is the textctrl: it store only the first byte
    >>> and not the other why?, the byte are like 22 and all are
    >>> readed

    >>
    >> No clue. I don't know what "textctrl" is or what it's
    >> supposed to do.

    >
    > a = ser.readline()
    > a = self.textCtrl3.SetValue(a + ' ')
    >
    > For my bad understanding is clear


    Please, please, quote articles so that we can tell who said
    what. I've attempted to re-quote things to make it clear.

    If textctrl isn't doing what you think it should, you need to

    1) Create a _small_ program that demonstrates the problem.

    2) POST THAT PROGRAM in a thread with a the subject line that
    is likely to attract the attention of somebody who knows
    something about "textctrl".

    >>> Sniffing the data with serial port monitor i see that the
    >>> answer is ok but after the answer the port close, why?

    >>
    >> What makes you think the port closed?
    >>

    >
    > The serial port monitor write com port close.


    OK. Good. That's useful information. I'm assuming that by
    "serial port monitor" you mean something like the tool from
    sysinternals? It's important that you include details like that.

    In the previous post, I thought you meant you were watching the
    serial data stream on the cable with a protocol analyzer or
    with another PC. I didn't understand how you would know the
    port had been closed by watching the data on the cable. You
    said you were sniffing the _data_, and you can't tell by
    looking at _data_ that the port has been closed -- so I had to
    ask how you knew the port had been closed.

    Now, if you'll just post the Python code we can probably tell
    you what's wrong.

    Since you haven't shown us the code, all we can do is guess.

    I've already made my guess: the serial port object is going
    out-of-scope and getting garbage collected. If you don't know
    what that means, let us know, and we'll explain it in more
    detail.

    > As you know i'm not a programmer, but i try to do this in my
    > free time.


    That's fine. We're all willing to help, but you have to work
    with us. The best/fastest way to solve your problem is to
    write a small program that demonstrates the problem and post
    it. Then we can look at it and tell you what's wrong.

    You could post your entire program, but the more code you post,
    less likely it is that people are going to sort through it to
    figure out what's wrong.

    If you can post a 15-20 line program that doesn't do what you
    think it should, I guarantee you'll get a quick answer
    explaining what you've done wrong.

    If you post a 1500 line program, nobody is going to read it.

    It's theoretically possible to post a precise enough natural
    language (e.g. English) description of the problem such that
    somebody might be able to figure out what's wrong. But,
    writing a description that is precise enough is very difficult
    even for somebody who is good at Python and a native English
    speaker.

    Its much easier to write a small program that demonstrates the
    problem.

    > Probably you have reason to write:
    >
    > The code you post is irrelevant.
    >
    > But i try to do my best as in my possibility.


    If you want us to tell you what's wrong with your code, you
    _have_to_show_it_to_us_. It's usually pointless for us to try
    to guess.

    There is a big problem with just posting a few lines of code
    out of a larger program: unless you know what's wrong, you
    don't know which lines of code to post. If you don't know what
    the problem is, you're probably posting the wrong chunk of
    code.

    > I think that in any case you can't run my code if you haven't
    > the same device that i have.


    Even if we can't run the code, we can still look at it.

    Ideally, you should create a small program that demonstrates
    your problem. Make it as small as you can. Leave out anything
    that isn't related to the problem you're trying to solve.

    If you refuse to post code that demonstrates your problem,
    there's very little chance we'll correctly guess what you've
    written.

    > So i don't want that you loose time with my stupid question,
    > i'm sure you have a lot of better things to do that help a
    > beginner like me.


    We were all beginners at one time. Teaching people is rarely a
    waste of time unless they don't want to be taught. But you
    have to help us solve your problem.

    --
    Grant Edwards grante Yow! While I'm in
    at LEVITTOWN I thought I'd
    visi.com like to see the NUCLEAR
    FAMILY!!
     
    Grant Edwards, Mar 6, 2006
    #8
  9. luca72

    Petr Jakes Guest

    Grant and Steve,
    I am wowed and amazed how supportive and helpful you (and other people
    in this group as well of course) are.
    Thanks.
    (sorry for OT)
    Petr Jakes
     
    Petr Jakes, Mar 6, 2006
    #9
  10. luca72

    luca72 Guest

    Here is my code ; why after the readline the port close?

    ser = serial.Serial(0)
    ser.baudrate = 9600
    ser.parity = serial.PARITY_ODD
    ser.stopbits = serial.STOPBITS_TWO
    ser.bytesize =serial.EIGHTBITS
    ser.setRTS(level = 0)
    ser.setDTR(level = 0)
    ser.timeout = 1

    ser.readline()

    Why after this the port close.

    Regards Luca
     
    luca72, Mar 7, 2006
    #10
  11. luca72

    Peter Hansen Guest

    luca72 wrote:
    > Here is my code ; why after the readline the port close?
    >


    What is the line of code before the first one shown here?

    > ser = serial.Serial(0)
    > ser.baudrate = 9600
    > ser.parity = serial.PARITY_ODD
    > ser.stopbits = serial.STOPBITS_TWO
    > ser.bytesize =serial.EIGHTBITS
    > ser.setRTS(level = 0)
    > ser.setDTR(level = 0)
    > ser.timeout = 1
    >
    > ser.readline()
    >
    > Why after this the port close.


    What's the next line of code after ser.readline()?

    -Peter
     
    Peter Hansen, Mar 7, 2006
    #11
  12. luca72

    luca72 Guest

    def OnButton1Button(self, event):

    ser = serial.Serial(0)
    > ser.baudrate = 9600
    > ser.parity = serial.PARITY_ODD
    > ser.stopbits = serial.STOPBITS_TWO
    > ser.bytesize =serial.EIGHTBITS
    > ser.setRTS(level = 0)
    > ser.setDTR(level = 0)
    > ser.timeout = 1


    > ser.readline()


    no code before

    Regards

    Luca
     
    luca72, Mar 7, 2006
    #12
  13. On 2006-03-07, luca72 <> wrote:

    > Here is my code; why after the readline the port close?
    >
    > ser = serial.Serial(0)
    > ser.baudrate = 9600
    > ser.parity = serial.PARITY_ODD
    > ser.stopbits = serial.STOPBITS_TWO
    > ser.bytesize =serial.EIGHTBITS
    > ser.setRTS(level = 0)
    > ser.setDTR(level = 0)
    > ser.timeout = 1
    >
    > ser.readline()
    >
    > Why after this the port close.


    Because the "ser" object is never used after that point, so it
    get's garbage collected and deleted.

    --
    Grant Edwards grante Yow! for ARTIFICIAL
    at FLAVORING!!
    visi.com
     
    Grant Edwards, Mar 7, 2006
    #13
  14. luca72

    Steve Holden Guest

    Grant Edwards wrote:
    > On 2006-03-07, luca72 <> wrote:
    >
    >
    >>Here is my code; why after the readline the port close?
    >>
    >> ser = serial.Serial(0)
    >> ser.baudrate = 9600
    >> ser.parity = serial.PARITY_ODD
    >> ser.stopbits = serial.STOPBITS_TWO
    >> ser.bytesize =serial.EIGHTBITS
    >> ser.setRTS(level = 0)
    >> ser.setDTR(level = 0)
    >> ser.timeout = 1
    >>
    >> ser.readline()
    >>
    >> Why after this the port close.

    >
    >
    > Because the "ser" object is never used after that point, so it
    > get's garbage collected and deleted.
    >

    ????

    The "ser" name is still bound to the serial object, surely?

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC/Ltd www.holdenweb.com
    Love me, love my blog holdenweb.blogspot.com
     
    Steve Holden, Mar 7, 2006
    #14
  15. On 2006-03-07, Steve Holden <> wrote:

    >>>Here is my code; why after the readline the port close?
    >>>
    >>> ser = serial.Serial(0)
    >>> ser.baudrate = 9600
    >>> ser.parity = serial.PARITY_ODD
    >>> ser.stopbits = serial.STOPBITS_TWO
    >>> ser.bytesize =serial.EIGHTBITS
    >>> ser.setRTS(level = 0)
    >>> ser.setDTR(level = 0)
    >>> ser.timeout = 1
    >>>
    >>> ser.readline()
    >>>
    >>> Why after this the port close.

    >>
    >> Because the "ser" object is never used after that point, so it
    >> get's garbage collected and deleted.

    >
    > ????
    >
    > The "ser" name is still bound to the serial object, surely?


    I don't see any references to ser after the call to ser.readline().

    Do you? ;)

    I was trying to make the point [again] that it's impossible to
    to tell what's going on because the OP refuses to post enough
    of his code to allow meaningful analysis.

    He's been told at least three times in as many postings that he
    needs to post a complete example that demonstrates the problem
    he's trying to solve, but he refuses. I've explained multiple
    times that the "excerpts" he's posting aren't sufficient. He
    persists in posting small snippets of mostly-irrelevant code
    with no context.

    I give up.

    I have a feeling I'm just annoying the mule at this point.

    --
    Grant Edwards grante Yow! It don't mean a
    at THING if you ain't got
    visi.com that SWING!!
     
    Grant Edwards, Mar 7, 2006
    #15
  16. luca72

    luca72 Guest

    Hello Grant and Hello Steve.

    Pls. don't kill me, but if you try the code above written you see that
    after the read the port close.
    My question is only: why it close without the close command?
     
    luca72, Mar 7, 2006
    #16
  17. luca72

    Petr Jakes Guest

    1)
    Peter Hansen was asking you for the code AFTER the "ser.readline()" not
    BEFORE!! the code you have originally posted here

    2)
    the best way how to examine if your code works is to try to write some
    simplest code as possible first (not buttons, not GUI etc..., just a
    simple code)
    (all this suggestions were already mentioned in one of your previous
    postings, see http://tinyurl.com/zz3s5)

    Regarding to your questions in this posting I think you can try
    something like:

    import serial
    ser=serial.Serial(0, 9600, 8, "E", stopbits=2, timeout=1)
    while 1:
    print s.readline()

    In your original code you have posted here, you read one line from the
    serial port only. It means the code reads byte by byte from the serial
    port till the "end of line" byte ('\n') is recognized. Than the reading
    stops and after that the whole code is finished because no
    other code lines after the ser.readline(). If no data present on the
    serial port for longer than "timeout" defined, it will stop reading
    serial port and the code finishes as well.

    3) please note, you can define serial port as following as well which
    is ,IMHO, more readable:

    ser=serial.Serial(0, 9600, 8, "E", stopbits=2, timeout=1)

    (it was recommended to you in above mentioned posting as well)

    You can find plenty of examples on http://pyserial.sourceforge.net/ in
    the "Examples" paragraph. Try to study and search before you ask.

    HTH

    Petr Jakes
     
    Petr Jakes, Mar 7, 2006
    #17
  18. luca72

    luca72 Guest

    Ok you write that it close :Because the "ser" object is never used
    after that point, so it
    get's garbage collected and deleted.

    But for example if i make one button with the same caracteristic of the
    previous com port:

    def OnButton1Button(self, event):

    ser = serial.Serial(0)

    > ser.baudrate = 9600
    > ser.parity = serial.PARITY_ODD
    > ser.stopbits = serial.STOPBITS_TWO
    > ser.bytesize =serial.EIGHTBITS
    > ser.setRTS(level = 0)
    > ser.setDTR(level = 0)
    > ser.timeout = 1

    But with
    a = textCtrl1GetValue() # i put here some different string
    to send
    ser.write (a)
    b = ser.readline()
    textCtrl2SetValue(b)

    why at any read the serial close, is possible to prevent the closure of
    the port?
     
    luca72, Mar 7, 2006
    #18
  19. luca72

    luca72 Guest

    Peter Hansen was asking you for the code AFTER the "ser.readline()"
    not
    BEFORE!! the code you have originally posted here

    OK IS MY MISTAKE; EXCUSE.
    I have read the example but if i ask is bucause i don't or maybe i
    don't understand the example

    Regaards

    Luca
     
    luca72, Mar 7, 2006
    #19
  20. On 2006-03-07, luca72 <> wrote:
    > Hello Grant and Hello Steve.
    >
    > Pls. don't kill me, but if you try the code above written you see that
    > after the read the port close.
    > My question is only: why it close without the close command?


    I've answered that question TWICE.

    The ser object is getting garbage collected. That closes the
    port.

    --
    Grant Edwards grante Yow! Yow! Are we laid
    at back yet?
    visi.com
     
    Grant Edwards, Mar 7, 2006
    #20
    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. amit
    Replies:
    0
    Views:
    398
  2. che
    Replies:
    2
    Views:
    509
  3. Peter Hansen

    Re: Pyserial again

    Peter Hansen, Mar 7, 2006, in forum: Python
    Replies:
    4
    Views:
    331
    Grant Edwards
    Mar 8, 2006
  4. abcd

    Importing again and again

    abcd, Jun 8, 2006, in forum: Python
    Replies:
    9
    Views:
    334
    Maric Michaud
    Jun 9, 2006
  5. Replies:
    4
    Views:
    412
Loading...

Share This Page