def __init__(self, device, c1218_settings={}, serial_settings=None, toggle_control=True, **kwargs):
self.logger = logging.getLogger('<STR_LIT>')<EOL>self.loggerio = logging.getLogger('<STR_LIT>')<EOL>self.toggle_control = toggle_control<EOL>self._toggle_bit = False<EOL>if hasattr(serial, '<STR_LIT>'):<EOL><INDENT>self.serial_h = serial.serial_for_url(device)<EOL><DEDENT>else:<EOL><INDENT>self.logger.warning('<STR_LIT>')<EOL>self.serial_h = serial.Serial(device)<EOL><DEDENT>self.logger.debug('<STR_LIT>' + device)<EOL>self.device = device<EOL>self.c1218_pktsize = (c1218_settings.get('<STR_LIT>') or <NUM_LIT>)<EOL>self.c1218_nbrpkts = (c1218_settings.get('<STR_LIT>') or <NUM_LIT:2>)<EOL>if serial_settings:<EOL><INDENT>self.logger.debug('<STR_LIT>')<EOL>self.serial_h.parity = serial_settings['<STR_LIT>']<EOL>self.serial_h.baudrate = serial_settings['<STR_LIT>']<EOL>self.serial_h.bytesize = serial_settings['<STR_LIT>']<EOL>self.serial_h.xonxoff = serial_settings['<STR_LIT>']<EOL>self.serial_h.interCharTimeout = serial_settings['<STR_LIT>']<EOL>self.serial_h.rtscts = serial_settings['<STR_LIT>']<EOL>self.serial_h.timeout = serial_settings['<STR_LIT>']<EOL>self.serial_h.stopbits = serial_settings['<STR_LIT>']<EOL>self.serial_h.dsrdtr = serial_settings['<STR_LIT>']<EOL>self.serial_h.writeTimeout = serial_settings['<STR_LIT>']<EOL><DEDENT>try:<EOL><INDENT>self.serial_h.setRTS(True)<EOL><DEDENT>except IOError:<EOL><INDENT>self.logger.warning('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>self.logger.debug('<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>self.serial_h.setDTR(False)<EOL><DEDENT>except IOError:<EOL><INDENT>self.logger.warning('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>self.logger.debug('<STR_LIT>')<EOL><DEDENT>self.logged_in = False<EOL>self._initialized = False<EOL>self.c1219_endian = '<STR_LIT:<>'<EOL>
This is a C12.18 driver for serial connections.  It relies on PySerial
to communicate with an ANSI Type-2 Optical probe to communicate
with a device (presumably a smart meter).

:param str device: A connection string to be passed to the PySerial
  library.  If PySerial is new enough, the serial_for_url function
  will be used to allow the user to use a rfc2217 bridge.
:param dict c1218_settings: A settings dictionary to configure the C1218
  parameters of 'nbrpkts' and 'pktsize'  If not provided the default
  settings of 2 (nbrpkts) and 512 (pktsize) will be used.
:param dict serial_settings: A PySerial settings dictionary to be applied to
  the serial connection instance.
:param bool toggle_control: Enables or diables automatically settings
  the toggle bit in C12.18 frames.