我正在尝试从此处获取 pySIMreader http://ladyada.net/make/simreader/download.html使用 python 2.7 我不断收到此错误:
Traceback (most recent call last):
File "pySimReader.py", line 267, in buttonConnectReader
self.SIM.connectReader()
File "/home/john/Plocha/pySimReader-Serial-src-v2/pySIMserial.py", line 113, in connectReader
res = self.openSession(self.getReaderName())
File "/home/john/Plocha/pySimReader-Serial-src-v2/pySIMserial.py", line 145, in openSession
baudrate=9600)
File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 260, in __init__
self.open()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 276, in open
raise SerialException("could not open port %s: %s" % (self._port, msg))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 13: ordinal not in range(128)
我知道有很多 UnicodeDecodeError 帖子,我确实试图弄清楚,但我一定遗漏了一些东西。
以下是相关代码:
try:
if (os.name == "posix"):
s = "/dev/ttyUSB0\t"
#s = "/dev/cu.PL2303-3B1\t"
if (os.name == "nt"):
for i in range(1,10):
s += "COM"+str(i)+"\t"
except:
print_exc()
for i in s.split("\t"):
if i:
self.listbox.Append(i)
...
def getReaderName(self):
return self.readerName
def connectReader(self):
if not self.getReaderName():
self.selectNewReader()
if self.getReaderName():
res = self.openSession(self.getReaderName())
if res == 0:
self.state = SIM_STATE_CONNECTED
self.gatherInfo()
...
def openSession(self, portname):
self.serialport = serial.Serial(port=portname,
parity=serial.PARITY_EVEN,
bytesize=serial.EIGHTBITS,
stopbits=serial.STOPBITS_TWO,
timeout=1,
xonxoff=0,
rtscts=0,
baudrate=9600)
...
def selectNewReaderOK(self, *args):
self.readerName = self.listbox.GetStringSelection()
self.closeDialog()