473,321 Members | 1,916 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,321 software developers and data experts.

Pyserial again

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

Mar 6 '06 #1
20 2850
On 2006-03-06, luca72 <lu*******@libero.it> 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!
Mar 6 '06 #2
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

Mar 6 '06 #3
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)

Mar 6 '06 #4
On 2006-03-06, luca72 <lu*******@libero.it> 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
Mar 6 '06 #5
> 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

Mar 6 '06 #6
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

Mar 6 '06 #7
On 2006-03-06, Luca <su**********@hotmail.it> 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!!
Mar 6 '06 #8
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

Mar 6 '06 #9
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

Mar 7 '06 #10
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

Mar 7 '06 #11
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

Mar 7 '06 #12
On 2006-03-07, luca72 <lu*******@libero.it> 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
Mar 7 '06 #13
Grant Edwards wrote:
On 2006-03-07, luca72 <lu*******@libero.it> 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

Mar 7 '06 #14
On 2006-03-07, Steve Holden <st***@holdenweb.com> 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!!
Mar 7 '06 #15
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?

Mar 7 '06 #16
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

Mar 7 '06 #17
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?

Mar 7 '06 #18
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

Mar 7 '06 #19
On 2006-03-07, luca72 <lu*******@libero.it> 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
Mar 7 '06 #20
On 2006-03-07, luca72 <lu*******@libero.it> wrote:
Ok you write that it close :Because the "ser" object is never
used after that point, so it get's garbage collected and
deleted.
Yes.
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)


I have no idea what you mean by that. POST THE CODE. With
both button handlers.

I'm GUESSING (since you won't post enough code for me to
actually figure it otu) that "ser" is local to your button
handlers and it's going out of scope and getting deleted when
the button handler returns.

Do you understand what I wrote above?
why at any read the serial close, is possible to prevent the
closure of the port?


Yes. Make sure the "ser" object doesn't get deleted.

--
Grant Edwards grante Yow! A can of ASPARAGUS,
at 73 pigeons, some LIVE ammo,
visi.com and a FROZEN DAQUIRI!!
Mar 7 '06 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: engsol | last post by:
Has anyone done a script that will rspond to the serial com port(s) receive buffer interrupt, as opposed to polling and timeouts? Win2000 is the main interest right now. Thanks Norm B
13
by: Bob Greschke | last post by:
We have some equipment that communicates at 57600 baud RS232. The path from the PC is USB to a Phillips USB hub, then off of that a TUSB3410 USB/Serial converter. The driver for the 3410 chip...
4
by: Zarathustra | last post by:
Hi, where I can find the pyserial handbook?? THanks
5
by: Mimi | last post by:
Hi, I use the pyserial to read data from a serial port. My code is in window Xp and python 2.4. when I use Hyperteminal I can read data without try and try again that it is not the case with...
2
by: Jon | last post by:
Hi, I wrote some code to read in info from a port using pyserial. the code reads info sent by a box that is connected to my computer by an rs232-to usb adapter. When I was writing the code and...
3
by: Ron Jackson | last post by:
I am using Python 2.5 on Windows XP. I have installed Pyserial and win32all extensions. When I try to run the example program scan.py (included below), or any other program using pyserial, as...
0
by: pauland80 | last post by:
<snip> <snip> Late thanks for your both answers! (Please excuse me for that) The problem was a bug in the device firmware. But before finding this, I dugg lightly in the pyserial source...
0
by: [david] | last post by:
http://pyserial.sourceforge.net/ "port numbering starts at zero, no need to know the port name in the user program" But the implementation in SerialWin32 is just (Portnum +1)
2
by: bryanleo | last post by:
We are trying to read data from a microcontroller and interface it through serial port. The output is then displayed in Python using Pyserial or the hyperterminal, the former is more important ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.