Hello. There is some kind of mystique in python 3, there is a program that receives data from the com port), the data format is: b'#1F002EF414C\r' . It is necessary to put this data into the array, so that each number would be in its position. It should be like this [#] [1] [F], etc. But instead of this data, I get this:
[35] [35, 49] [35, 49, 70] [35, 49, 70, 48] [35, 49, 70, 48, 48] [35, 49, 70, 48, 48, 50] [35, 49, 70, 48, 48, 50, 69] [35, 49, 70, 48, 48, 50, 69, 70] [35, 49, 70, 48, 48, 50, 69, 70, 52] [35, 49, 70, 48, 48, 50, 69, 70, 52, 49] [35, 49, 70, 48, 48, 50, 69, 70, 52, 49, 52] [35, 49, 70, 48, 48, 50, 69, 70, 52, 49, 52, 67] [35, 49, 70, 48, 48, 50, 69, 70, 52, 49, 52, 67, 13] in python 2.7, everything works perfectly) but in python 3, something mystical. I realized that for some reason this is ASCII code and if you add unchar then the data will be as needed. But what about the array, why does it look that way and why is the ASCII code entered. help fix the array (list) and figure it out)). Program Code:
# coding: utf8 -*- import serial class ComPort: def Comport(self): global idnumbercard global ID forchar = 0 idcom = [] idcomstr = "" try: ser = serial.Serial( port = 'COM8',\ baudrate=2400,\ parity=serial.PARITY_NONE,\ stopbits=serial.STOPBITS_ONE,\ bytesize=serial.EIGHTBITS,\ timeout=None) except serial.SerialException: print('неверный com port') print("connected to: " + ser.portstr) count=1 for line in ser.read(13): #forchar = forchar + 1 idcom.append(line) print(idcom)
idcom.append(list(unichr(line)))loop - Diq