Target.write() does not write in lab 1-Connecting to Hardware

Why doesn’t the function target.write() write when I try to run the Function?
Changing the code the following did not help either:

    target.write('p' + '00'*16 + '\n')

When I use target.simpleserial.write(p,msg) it works fine.

    msg = bytearray([0]*16) #simpleserial uses bytearrays
    target.simpleserial_write('p', msg)

target.write() doesn’t return anything; that’s why print(target.write(...)) gives you None.

(aside: in Jupyter, you can get a function’s definition by using “??”: target.write?? will show you the code for the target.write() function)

target.simpleserial_write() is simply a wrapper for target.write().

target.simpleserial_write('p', bytearray[0]*16)

is equivalent to:
target.write('p' + '00'*16 + '\n')

(you should see that both result in the same recv_msg).

Finally, the target will not respond to target.write('p' + '00'*32 + '\n') because the ‘p’ command is expected to have a 16-byte payload; the target firmware is such that it only responds to properly formatted commands. It ignores commands with an incorrect payload size.

1 Like