Problems with serial port interface

lionelgreenstreet at gmail.com lionelgreenstreet at gmail.com
Fri Jun 7 06:17:25 EDT 2013


Sorry for my quote,
but do you have any suggestion?

Il giorno martedì 4 giugno 2013 23:25:21 UTC+2, lionelgr... at gmail.com ha scritto:
> Hi,
> 
> i'm programming in python for the first time: i want to create a serial port reader. I'm using python3.3 and pyQT4; i'm using also pyserial.
> 
> Below a snippet of the code:
> 
> 
> 
> class CReader(QThread):
> 
>     def start(self, ser, priority = QThread.InheritPriority):
> 
>         self.ser = ser
> 
>         QThread.start(self, priority)
> 
>         self._isRunning = True
> 
>         self.numData=0;
> 
>       
> 
>     def run(self):
> 
>         print("Enter Creader")
> 
>         while True:
> 
>             if self._isRunning:
> 
>                 try:
> 
>                     data = self.ser.read(self.numData)
> 
>                     n = self.ser.inWaiting()
> 
>                     if n:
> 
>                         data = self.ser.read(n)
> 
>                         self.emit(SIGNAL("newData(QString)"), data.decode('cp1252', 'ignore'))
> 
>                         self.ser.flushInput()
> 
>                 except:
> 
>                     pass
> 
>             else:
> 
>                 return
> 
>             
> 
>     def stop(self):
> 
>         self._isRunning = False
> 
>         self.wait()
> 
>  
> 
> This code seems work well, but i have problems in this test case:
> 
> 
> 
> +baud rate:19200
> 
> +8/n/1
> 
> +data transmitted: 1 byte every 5ms
> 
> 
> 
> After 30seconds (more or less) the program crashes: seems a buffer problem, but i'm not really sure. 
> 
> What's wrong?
> 
> Thanks




More information about the Python-list mailing list