Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError
#26
decode_bin() was told to unpack buffer b'\x00\x00\x00\x00\x00\x00\x01\x00' into 4 values of types ASCIIZ, ASCIIZ, ASCIIZ, ASCIIZ, Uint4, Unit4.

According to this code, ASCIIZ is a null terminated string and it will pull of all the bytes up to the null character (\x00).
            if type_ == 'ASCIIZ':
                # special handling: nul-terminated string
                nul = buff.index(b'\0', offset)
                # find first '\0' after offset
                if nul == -1:
                    value = buff[offset:]
                else:
                    value = buff[offset:nul]
                # return string without trailing '\0'
                size = len(value) + 1
Since your buffer starts with a bunch of null characters, unpacking the 4 ASCIIZ values essentially removes the 4 leading null characters (actually it increments an offset. Now your remaing buffer is b'x\00x\00x\00x\01x\00'.

The next type is Uint4. According to the DATATYPE dictionary in the PakBus class, this code grabs the next 4 bytes and interprets them as an unsigned int using format >L.
    DATATYPE = {
        'Byte': {'code': 1, 'fmt': 'B', 'size': 1},
        'UInt2': {'code': 2, 'fmt': '>H', 'size': 2},
        'UInt4': {'code': 3, 'fmt': '>L', 'size': 4},
This will grab b'x\00x\00x\00x\01' and convert it to 1.

The only thing remaining in the buffer is 0x00 (offset = 7). The next type is another Unit4 which requires 4 bytes. Buffer only has 1 byte left, not 4. The code fails.

decode_bin() is not your error, the buffer being passed to decode_bin is the problem. You can trace this back to device.table_def() calling device.getfile() and asking pakbus.parse_table to parse the data.
    @cached_property
    def table_def(self):
        '''Return table definition.'''
        data = self.getfile('.TDF')
        # List tables
        tabledef = self.pakbus.parse_tabledef(data)
        return tabledef
So there could be a problem with device.getfile(). Maybe the command it sends is wrong. I would print the cmd after doing this:
            cmd = self.pakbus.get_fileupload_cmd(filename,
                                                 offset=offset,
                                                 closeflag=0x00,
                                                 transac_id=transac_id)
Does the filename make sense? What about the offset?

The command is sent to your device and a response read back.
hdr, msg, send_time = self.send_wait(cmd)
The parsing "msg" is where your program eventually crashes. Is the command sent incorrectly? Is the response read incorrectly?

This is device.send_wait()
def send_wait(self, cmd):
        '''Send command and wait for response packet.'''
        packet, transac_id = cmd
        begin = time.time()
        self.pakbus.write(packet)
        # wait response packet
        response = self.pakbus.wait_packet(transac_id)
        end = time.time()
        send_time = timedelta(seconds=int((end - begin) / 2))
        return response[0], response[1], send_time
Pretty simple. Write the packet and read response. Looks like we are headed back to pakbus again. pakbus.write(), pakbus.read() and pakbus.wait_packet(). This is where I would set my breakpoints. What is the buffer I am going to write? What is the buffer I just read? What is the link?
Reply


Messages In This Thread
AttributeError - by Makada - Nov-17-2019, 03:18 PM
RE: AttributeError - by Larz60+ - Nov-17-2019, 04:12 PM
RE: AttributeError - by Makada - Nov-17-2019, 04:32 PM
RE: AttributeError - by Makada - Nov-17-2019, 07:51 PM
RE: AttributeError - by Larz60+ - Nov-17-2019, 11:16 PM
RE: AttributeError - by Makada - Nov-18-2019, 07:07 AM
RE: AttributeError - by baquerik - Nov-18-2019, 03:12 PM
RE: AttributeError - by Makada - Nov-18-2019, 06:29 PM
RE: AttributeError - by ThomasL - Nov-18-2019, 06:37 PM
RE: AttributeError - by Makada - Nov-18-2019, 07:19 PM
RE: AttributeError - by ThomasL - Nov-18-2019, 07:40 PM
RE: AttributeError - by Makada - Nov-18-2019, 08:37 PM
RE: AttributeError - by ThomasL - Nov-18-2019, 08:49 PM
RE: AttributeError - by Makada - Nov-19-2019, 06:15 PM
RE: AttributeError - by baquerik - Nov-19-2019, 06:27 PM
RE: AttributeError - by Makada - Nov-19-2019, 08:46 PM
RE: AttributeError - by Makada - Nov-23-2019, 10:36 AM
RE: AttributeError - by Makada - Apr-26-2020, 03:11 PM
RE: AttributeError - by buran - Apr-26-2020, 03:19 PM
RE: AttributeError - by Makada - Apr-26-2020, 03:28 PM
RE: AttributeError - by Makada - Apr-27-2020, 12:08 PM
RE: AttributeError - by Makada - Nov-07-2020, 07:49 PM
RE: AttributeError - by Makada - Nov-11-2020, 06:04 PM
RE: AttributeError - by bowlofred - Nov-11-2020, 06:43 PM
RE: AttributeError - by Makada - Feb-05-2022, 07:22 PM
RE: AttributeError - by deanhystad - Feb-05-2022, 11:00 PM
RE: AttributeError - by Makada - Feb-06-2022, 05:14 AM
RE: AttributeError - by deanhystad - Feb-06-2022, 11:40 PM
RE: AttributeError - by Makada - Feb-07-2022, 05:25 AM
RE: AttributeError - by Makada - Feb-07-2022, 12:57 PM
RE: AttributeError - by deanhystad - Feb-07-2022, 02:46 PM
RE: AttributeError - by Makada - Feb-07-2022, 02:51 PM
RE: AttributeError - by Makada - Feb-10-2022, 09:27 AM
RE: AttributeError - by deanhystad - Feb-10-2022, 07:43 PM
RE: AttributeError - by Makada - Feb-19-2023, 07:50 PM
RE: AttributeError - by deanhystad - Feb-19-2023, 08:47 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020