pyserial
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 pyserial library. anyone can help me ? this is a part of my code: self.ser = serial.Serial() self.ser.baudrate = 9600 self.ser.port = 3 self.ser.timeout= 10 self.ser.bytesize = serial.EIGHTBITS self.ser.stopbits = serial.STOPBITS_ONE self.ser.xonxoff = 0 nbHisto = 144 for i in range(0,nbHisto): while 1: print self.ser.flushInput() print self.ser.flushOutput() cmd = "%xs\r" %(i+1) self.ser.write("%s" %cmd) #print cmd histo = self.ser.readlines() #print histo if histo: if histo=="\r\n": pass else: histoAdresse = int(histo[0].strip('\r\n')) print histoAdresse try: dateHisto_cur = listeFenetreNonNul["%s" %(histoAdresse)] print dateHisto_cur self.ecrireHistoDansFic(histo,histoAdresse,dateHisto_cur,histoAdresse,i) break except: print "Adresse pas trouvee dans le systeme %s" %(histoAdresse) break # End if sleep(10) # End while #End for self.ser.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: pyserial
Thanks Peter, because you have understood my need: a little understanding of readlines() function. # Following snippets of code is running in infinitive loop, but it is not necessary too be worried about processor utilization because the readline waits for the data on the serial port and the code continues to run when data occurs or when timeout passes. # my python script tries to read a lot of data (the histograms) and that can take many times (3 min) to download one file. and data do not arrived in the same time you can wait few seconds between data ( data response for the same command). do you think that readlines() function will wait until all data are arrived or when the timeout expired ? if the data take more time, the readlines() will wait or will break on the timeout ? with hyperterminal the data are echoed when they arrived and you can see that they do not arrived all the same time. the timeout is reset when the first data arrived or it is only ignored ? -- http://mail.python.org/mailman/listinfo/python-list
Re: pyserial
thanks philippe, Hi will take care for the that. -- http://mail.python.org/mailman/listinfo/python-list