MicroBlaze rpc error : error: byte format requires -128 <= number <= 127

Hi there,

I’m trying to pass a 16-bit address through microblaze api from Python to the SPI devices via spi_transfer (e.g. device.transfer(temp_addr_str, read_buf, 4)) .

If the address = 0x4880 , after changing it to bytes via address.to_bytes and decode it into a string, it can be sent without error. However, when address = 0x4888, it prompts error as below:

I am a bit confused here.

  1. shouldn’t the range be 0-255? From rpc.py, line 305 to 309, I do see why it is packed with format ‘b’.PYNQ/rpc.py at master · Xilinx/PYNQ · GitHub . However, to work with ord() , shouldn’t it always be positive?
  2. in this case, what is the correct method to pre-process the hex number , for example 0x4880, so that it will not throw this error. presumably, 0x4880, is what I need to send out.

Regards,
Colin

That looks like it’s just a bug on our part caused by a mismatch between C/Python semantics. We should be treating char as unsigned by default rather than signed. In C it’s undefined but Python treats it as unsigned.

We also should not be doing the conversion for non-str objects.

We’ll fix this in 2.7. In the meantime, the easiest workaround is change the type to 'B' in __init__ of ConstCharPointerWrapper.

Peter

That works. Hopefully 2.7 will be released soon. Thanks.