Pyserial never read

sam samschul at pacbell.net
Wed Feb 22 12:36:49 EST 2006


luca72 wrote:
> Thanks to all for the help,
>
> here you find the code, pls note if i use handshaking = 1 the
> application don't start.
> in the delphi configuratio of com port if i use or not handshaking the
> application work.
> Best Regards at all
>
> Luca
>
> import serial
>         import win32file
>         port = 2

Is port = 2 correct?
I thought that com ports under windows are designated as a string
"com1","com2",..etc.

>         baudrate = 38400
>         bytesize =serial.EIGHTBITS
>         parity =serial.PARITY_ODD
>         stopbits =serial.STOPBITS_TWO
>         timeout = 1
>         ser = serial.Serial(2, baudrate=38400, bytesize=8,
> parity=serial.PARITY_ODD, stopbits=2, timeout=3)
>         ct = ''
>         ch = ''
>         a = self.textCtrl1.GetValue()
>         ind = 0
>         ind1 = 2
>         lunghezza = len(a)
>         while ind < lunghezza :
>             b = a[ind:ind1]
>             b = int(b,16)
>             b = ~b
>             c = ''.join([str((b >> Digit) & 1) for Digit in range(7,
> -1, -1)])
>             c1 = c[0:4]
>             c2 = c[4:]
>             c1 = c1[3:] + c1[2:3] + c1[1:2] + c1[0:1]
>             c2 = c2[3:] + c2[2:3] + c2[1:2] + c2[0:1]
>             c1 = hex(int(c1,2))
>             c2 = hex(int(c2,2))
>             c1 = c1[2:]
>             c2 = c2[2:]
>             c = c2+c1
>             ct = ct + c
>             ind = ind + 2
>             ind1 = ind1 + 2
>             c = int(c,16)
>             c = chr(c)
>             ch = ch + c
>
>
>         ser.write(ch)
>
>         elf.textCtrl2.SetValue(ct)
>         ser.readline()
 You might want to try using ser.read() instead of ser.readline() as
you may not be getting  linefeed carrage return characters . I usually
setup a buffer to scan for the characters I expect.

>
>
>
> Pls.Note i hove also try with read(number of byte ) with inWaiting(),
> flush  etc........
> 
> 
> But no result.
> 
> Thanks Luca

Hope this helps
Sam Schulenburg




More information about the Python-list mailing list