Esempio n. 1
0
    def validate(self, fx, address, count=1):
        """ Validates the request to make sure it is in range

        :param fx: The function we are working with
        :param address: The starting address
        :param count: The number of values to test
        :returns: True if the request in within range, False otherwise
        """
        raise NotImplementedException("validate context values")
Esempio n. 2
0
    def getValues(self, fx, address, count=1):
        """ Get `count` values from datastore

        :param fx: The function we are working with
        :param address: The starting address
        :param count: The number of values to retrieve
        :returns: The requested values from a:a+c
        """
        raise NotImplementedException("get context values")
Esempio n. 3
0
    def build(self):
        ''' Return the payload buffer as a list

        This list is two bytes per element and can
        thus be treated as a list of registers.

        :returns: The payload buffer as a list
        '''
        raise NotImplementedException("set context values")
Esempio n. 4
0
    def getValues(self, fx, address, count=1):
        ''' Validates the request to make sure it is in range

        :param fx: The function we are working with
        :param address: The starting address
        :param count: The number of values to retrieve
        :returns: The requested values from a:a+c
        '''
        raise NotImplementedException("get context values")
Esempio n. 5
0
    def is_socket_open(self):
        """
        Check whether the underlying socket/serial is open or not.

        :returns: True if socket/serial is open, False otherwise
        """
        raise NotImplementedException(
            "is_socket_open() not implemented by {}".format(self.__str__())
        )
Esempio n. 6
0
    def addTransaction(self, request, tid=None):
        """ Adds a transaction to the handler

        This holds the requets in case it needs to be resent.
        After being sent, the request is removed.

        :param request: The request to hold on to
        :param tid: The overloaded transaction id to use
        """
        raise NotImplementedException("addTransaction")
Esempio n. 7
0
    def isFrameReady(self):
        """ Check if we should continue decode logic

        This is meant to be used in a while loop in the decoding phase to let
        the decoder know that there is still data in the buffer.

        :returns: True if ready, False otherwise
        """
        raise NotImplementedException(
            "Method not implemented by derived class")
Esempio n. 8
0
    def populateResult(self, result):
        """ Populates the modbus result with current frame header

        We basically copy the data back over from the current header
        to the result header. This may not be needed for serial messages.

        :param result: The response packet
        """
        raise NotImplementedException(
            "Method not implemented by derived class")
Esempio n. 9
0
    def addToFrame(self, message):
        """ Add the next message to the frame buffer

        This should be used before the decoding while loop to add the received
        data to the buffer handle.

        :param message: The most recent packet
        """
        raise NotImplementedException(
            "Method not implemented by derived class")
Esempio n. 10
0
    def buildPacket(self, message):
        """ Creates a ready to send modbus packet

        The raw packet is built off of a fully populated modbus
        request / response message.

        :param message: The request/response to send
        :returns: The built packet
        """
        raise NotImplementedException(
            "Method not implemented by derived class")
Esempio n. 11
0
    def calculateRtuFrameSize(cls, buffer):
        ''' Calculates the size of a PDU.

        :param buffer: A buffer containing the data that have been received.
        :returns: The number of bytes in the PDU.
        '''
        if hasattr(cls, '_rtu_frame_size'):
            return cls._rtu_frame_size
        elif hasattr(cls, '_rtu_byte_count_pos'):
            return rtuFrameSize(buffer, cls._rtu_byte_count_pos)
        else: raise NotImplementedException(
            "Cannot determine RTU frame size for %s" % cls.__name__)
Esempio n. 12
0
    def processIncomingPacket(self, data, callback):
        """ The new packet processing pattern

        This takes in a new request packet, adds it to the current
        packet stream, and performs framing on it. That is, checks
        for complete messages, and once found, will process all that
        exist.  This handles the case when we read N + 1 or 1 / N
        messages at a time instead of 1.

        The processed and decoded messages are pushed to the callback
        function to process and send.

        :param data: The new packet data
        :param callback: The function to send results to
        """
        raise NotImplementedException(
            "Method not implemented by derived class")
Esempio n. 13
0
    def encode(self):
        ''' Encodes the status bits to an event message

        :returns: The encoded event message
        '''
        raise NotImplementedException()
Esempio n. 14
0
    def encode(self):
        """ Encodes the message

        :raises: A not implemented exception
        """
        raise NotImplementedException()
Esempio n. 15
0
    def decode(self, event):
        ''' Decodes the event message to its status bits

        :param event: The event to decode
        '''
        raise NotImplementedException()
Esempio n. 16
0
    def delTransaction(self, tid):
        """ Removes a transaction matching the referenced tid

        :param tid: The transaction to remove
        """
        raise NotImplementedException("delTransaction")
Esempio n. 17
0
 def execute(self, *args):
     ''' Base function to raise if not implemented '''
     raise NotImplementedException(
         "Diagnostic Message Has No Execute Method")
Esempio n. 18
0
    def encode(self):
        ''' Encodes the message

        :raises: A not implemented exception
        '''
        raise NotImplementedException()
Esempio n. 19
0
            def buildPacket(self, message):
                ''' Creates a *corrupted* ready to send modbus packet.  Truncates from 1
                to all of the bytes, before returning response.

                :param message: The populated request/response to send

                WARNING: pymodbus seems to swallow any exceptions thrown by these
                methods.  This seems like a defect; it should log them, at least.
                '''
                try:
                    log.info("Encoding package")
                    message.encode()

                    if self.what == "transaction":
                        message.transaction_id ^= 0xFFFF
                        packet = super(EvilFramerCorruptResponse,
                                       self).buildPacket(message)
                        message.transaction_id ^= 0xFFFF
                    elif self.what == "registers":
                        if isinstance(message, ReadRegistersResponseBase):
                            # These have '.registers' attribute, which is a list.
                            # Add/remove some
                            saveregs = message.registers
                            if len(message.registers) == 0 or random.randint(
                                    0, 1):
                                message.registers += [999]
                            else:
                                message.registers = message.registers[:-1]
                            packet = super(EvilFramerCorruptResponse,
                                           self).buildPacket(message)
                            message.registers = saveregs
                        elif isinstance(message, WriteSingleRegisterResponse):
                            # Flip the responses address bits and then flip them back.
                            message.address ^= 0xFFFF
                            packet = super(EvilFramerCorruptResponse,
                                           self).buildPacket(message)
                            message.address ^= 0xFFFF
                        elif isinstance(message,
                                        WriteMultipleRegistersResponse):
                            # Flip the responses address bits and then flip them back.
                            message.address ^= 0xFFFF
                            packet = super(EvilFramerCorruptResponse,
                                           self).buildPacket(message)
                            message.address ^= 0xFFFF
                        else:
                            raise NotImplementedException(
                                "Unhandled class for register corruption; not implemented"
                            )
                    elif self.what == "protocol":
                        message.protocol_id ^= 0xFFFF
                        packet = super(EvilFramerCorruptResponse,
                                       self).buildPacket(message)
                        message.protocol_id ^= 0xFFFF
                    elif self.what == "unit":
                        message.unit_id ^= 0xFF
                        packet = super(EvilFramerCorruptResponse,
                                       self).buildPacket(message)
                        message.unit_id ^= 0xFF
                    elif self.what == "function":
                        message.function_code ^= 0xFF
                        packet = super(EvilFramerCorruptResponse,
                                       self).buildPacket(message)
                        message.function_code ^= 0xFF
                    else:
                        raise NotImplementedException(
                            "Unknown corruption specified; not implemented")
                except Exception:
                    log.info("Could not build corrupt packet: %s",
                             traceback.format_exc())
                return packet
Esempio n. 20
0
    def getResponseSize(self):
        ''' Returns expected packet size of response for this request

        :raises: A not implemented exception
        '''
        raise NotImplementedException()
Esempio n. 21
0
 def reset(self):
     """ Resets all the datastores to their default values
     """
     raise NotImplementedException("Context Reset")
Esempio n. 22
0
 def handle(self):
     ''' Callback when we receive any data
     '''
     raise NotImplementedException(
         "Method not implemented by derived class")
Esempio n. 23
0
    def connect(self):
        """ Connect to the modbus remote host

        :returns: True if connection succeeded, False otherwise
        """
        raise NotImplementedException("Method not implemented by derived class")
Esempio n. 24
0
 def handle(self):
     """ Callback when we receive any data
     """
     raise NotImplementedException("Method not implemented"
                                   " by derived class")
Esempio n. 25
0
    def send(self, message):
        ''' Send a request (string) to the network

        :param message: The unencoded modbus response
        '''
        raise NotImplementedException("Method not implemented by derived class")
Esempio n. 26
0
 def reset(self):
     ''' Resets all the datastores to their default values '''
     self._metadata.drop_all()
     self.__db_create(self.table, self.database)
     raise NotImplementedException()  # TODO drop table?
Esempio n. 27
0
 def reset(self):
     ''' Resets all the datastores to their default values '''
     raise NotImplementedException()
Esempio n. 28
0
    def __delitem__(self, slave):
        """ Wrapper used to access the slave context

        :param slave: The slave context to remove
        """
        raise NotImplementedException()  # doesn't make sense here