def _connect(self):
        """
        connect to the modbus slave (server)
        """
        framer = None
        if self._framer == 0:  # Socket Framer
            framer = ModbusSocketFramer
        elif self._framer == 1:  # RTU Framer
            framer = ModbusRtuFramer
        elif self._framer == 2:  # ASCII Framer
            framer = ModbusAsciiFramer
        elif self._framer == 3:  # Binary Framer
            framer = ModbusBinaryFramer

        if self._protocol == 0:  # TCP
            if self._framer is None:  # No Framer
                self.slave = ModbusTcpClient(self._address, int(self._port))
            else:
                self.slave = ModbusTcpClient(self._address, int(self._port), framer=framer)
        elif self._protocol == 1:  # UDP
            if self._framer is None:  # No Framer
                self.slave = ModbusUdpClient(self._address, int(self._port))
            else:
                self.slave = ModbusUdpClient(self._address, int(self._port), framer=framer)
        elif self._protocol in (2, 3, 4):  # serial
            method_list = {2: 'ascii', 3: 'rtu', 4: 'binary'}
            self.slave = ModbusSerialClient(
                method=method_list[self._protocol],
                port=self._port,
                stopbits=self._stopbits,
                bytesize=self._bytesize,
                parity=self._parity,
                baudrate=self._baudrate,
                timeout=self._timeout)
        else:
            raise NotImplementedError("Protocol not supported")
        status = self.slave.connect()
        return status
def _connect ( self ) : framer = None if self . _framer == 0 : framer = ModbusSocketFramer elif self . _framer == 1 : framer = ModbusRtuFramer elif self . _framer == 2 : framer = ModbusAsciiFramer elif self . _framer == 3 : framer = ModbusBinaryFramer if self . _protocol == 0 : if self . _framer is None : self . slave = ModbusTcpClient ( self . _address , int ( self . _port ) ) else : self . slave = ModbusTcpClient ( self . _address , int ( self . _port ) , framer = framer ) elif self . _protocol == 1 : if self . _framer is None : self . slave = ModbusUdpClient ( self . _address , int ( self . _port ) ) else : self . slave = ModbusUdpClient ( self . _address , int ( self . _port ) , framer = framer ) elif self . _protocol in ( 2 , 3 , 4 ) : method_list = { 2 : 'ascii' , 3 : 'rtu' , 4 : 'binary' } self . slave = ModbusSerialClient ( method = method_list [ self . _protocol ] , port = self . _port , stopbits = self . _stopbits , bytesize = self . _bytesize , parity = self . _parity , baudrate = self . _baudrate , timeout = self . _timeout ) else : raise NotImplementedError ( "Protocol not supported" ) status = self . slave . connect ( ) return status
connect to the modbus slave (server)