Documentation states that it is ok to omit settings from the settings dictionary
sent to applySettingsDict(), but if some settings are left out, it throws an error.
My solution to this problem was to change the 'for' loop in the function from
for key in self._SETTINGS:
to
for key in d: #modified line
and that seems to fix the problem.
The following program with its output demonstrates the problem.
~~~~~~~~~~~~
import serial
a = serial.Serial()
b = a.getSettingsDict()
print '\n original settings dictionary from getSettingsDict() '
for x in b:
print x,b[x]
a.applySettingsDict(b)
b.pop('bytesize')
print '\n settings dictionary with bytesize parameter removed '
for x in b:
print x,b[x]
print '\n'
a.applySettingsDict(b)
~~~~~~~~~~~
** original settings dictionary from getSettingsDict() **
parity N
baudrate 9600
bytesize 8
xonxoff False
interCharTimeout None
rtscts False
timeout None
stopbits 1
dsrdtr False
writeTimeout None
** settings dictionary with bytesize parameter removed **
parity N
baudrate 9600
xonxoff False
interCharTimeout None
rtscts False
timeout None
stopbits 1
dsrdtr False
writeTimeout None
Traceback (most recent call last):
File "/Users/analog/Desktop/bug.py", line 15, in <module>
a.applySettingsDict(b)
File "/Library/Python/2.7/site-packages/serial/serialutil.py", line 501, in applySettingsDict
if d[key] != getattr(self, ''+key): # check against internal "" value
KeyError: 'bytesize'</module>
yeah, all keys were checked, updated the code to only check existing keys.
comitted to https://github.com/pyserial/pyserial