Pyserial never read

luca72 lucaberto at libero.it
Wed Feb 22 04:18:21 EST 2006


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
        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()



Pls.Note i hove also try with read(number of byte ) with inWaiting(),
flush  etc........


But no result.

Thanks Luca




More information about the Python-list mailing list