From f325c035a74d7cc1ecf2b5390b4d568000deca45 Mon Sep 17 00:00:00 2001 From: cliechti Date: Fri, 25 Dec 2009 16:09:49 +0000 Subject: applying rfc2217IACIAC-2.patch, fixing issues with IAC. Thanks to Grant Edwards for the patch. --- pyserial/serial/rfc2217.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pyserial/serial/rfc2217.py b/pyserial/serial/rfc2217.py index 4163e19..605276c 100644 --- a/pyserial/serial/rfc2217.py +++ b/pyserial/serial/rfc2217.py @@ -689,7 +689,10 @@ class RFC2217Serial(SerialBase): if byte == IAC: # interpret as command doubled -> insert character # itself - self._read_buffer.put(IAC) + if suboption is not None: + suboption.append(IAC) + else: + self._read_buffer.put(IAC) mode = M_NORMAL elif byte == SB: # sub option start @@ -788,8 +791,9 @@ class RFC2217Serial(SerialBase): """Send DO, DONT, WILL, WONT.""" self._internal_raw_write(to_bytes([IAC, action, option])) - def rfc2217SendSubnegotiation(self, option, value=[]): + def rfc2217SendSubnegotiation(self, option, value=''): """Subnegotiation of RFC2217 parameters.""" + value = value.replace(IAC, IAC_DOUBLED) self._internal_raw_write(to_bytes([IAC, SB, COM_PORT_OPTION, option] + list(value) + [IAC, SE])) def rfc2217SendPurge(self, value): @@ -927,8 +931,9 @@ class PortManager(object): """Send DO, DONT, WILL, WONT.""" self.connection.write(to_bytes([IAC, action, option])) - def rfc2217SendSubnegotiation(self, option, value=[]): + def rfc2217SendSubnegotiation(self, option, value=''): """Subnegotiation of RFC 2217 parameters.""" + value = value.replace(IAC, IAC_DOUBLED) self.connection.write(to_bytes([IAC, SB, COM_PORT_OPTION, option] + list(value) + [IAC, SE])) # - check modem lines, needs to be called periodically from user to @@ -1014,7 +1019,10 @@ class PortManager(object): if byte == IAC: # interpret as command doubled -> insert character # itself - yield IAC + if self.suboption is not None: + self.suboption.append(byte) + else: + yield byte self.mode = M_NORMAL elif byte == SB: # sub option start @@ -1220,11 +1228,11 @@ class PortManager(object): elif suboption[1:2] == SET_LINESTATE_MASK: self.linstate_mask = ord(suboption[2:3]) # ensure it is a number if self.logger: - self.logger.info("line state mask: 0x%02" % (self.linstate_mask,)) + self.logger.info("line state mask: 0x%02x" % (self.linstate_mask,)) elif suboption[1:2] == SET_MODEMSTATE_MASK: self.modemstate_mask = ord(suboption[2:3]) # ensure it is a number if self.logger: - self.logger.info("modem state mask: 0x%02" % (self.modemstate_mask,)) + self.logger.info("modem state mask: 0x%02x" % (self.modemstate_mask,)) elif suboption[1:2] == PURGE_DATA: if suboption[2:3] == PURGE_RECEIVE_BUFFER: self.serial.flushInput() -- cgit v1.2.1