Example #1
0
    def build_packet(self, message):
        """ Creates a ready to send modbus packet

        :param message: The populated request/response to send
        """
        data = message.encode()
        packet = struct.pack('>BB', message.unit_id,
                             message.function_code) + data
        packet += struct.pack('>H', compute_crc(packet))
        return packet
Example #2
0
    def build_packet(self, message):
        """ Creates a ready to send modbus packet

        :param message: The request/response to send
        :returns: The encoded packet
        """
        data = self._preflight(message.encode())
        packet = struct.pack('>BB', message.unit_id,
                             message.function_code) + data
        packet += struct.pack(">H", compute_crc(packet))
        packet = self.__start + packet + self.__end
        return packet
Example #3
0
    def build_packet(self, message):
        """ Creates a ready to send modbus packet

        :param message: The populated request/response to send
        """
        data = message.encode()
        packet = struct.pack(
            '>BB',
            message.unit_id,
            message.function_code
        ) + data
        packet += struct.pack('>H', compute_crc(packet))
        return packet
Example #4
0
    def build_packet(self, message):
        """ Creates a ready to send modbus packet

        :param message: The request/response to send
        :returns: The encoded packet
        """
        data = self._preflight(message.encode())
        packet = struct.pack(
            '>BB',
            message.unit_id,
            message.function_code
        ) + data
        packet += struct.pack(">H", compute_crc(packet))
        packet = self.__start + packet + self.__end
        return packet