Pyserial again

Grant Edwards grante at
Tue Mar 7 18:11:33 CET 2006

On 2006-03-07, luca72 <lucaberto at> 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.


> 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,
                                 and a FROZEN DAQUIRI!!

More information about the Python-list mailing list