More than one simpleserial put/read from the microcontroller

Hello!
I am working with CWNano. I am having trouble to figure out how to receive two messages from the microcontroller into Python.
A simple example code snippet I am trying to implement is the following:

 uint8_t mytest[4];
 mytest[0]=1;
 mytest[1]=2;
 mytest[2]=3;
 mytest[3]=4;
          
 simpleserial_put('q', 4, (uint8_t*)mytest);
 mytest[0]=4;
 mytest[1]=5;
 mytest[2]=6;
 mytest[3]=7;
 simpleserial_put('x', 4, (uint8_t*)mytest);

It goes without saying that this is just a snippet of C code from the microcontroller.
I would expect to receive “q 1 2 3 4” on the client side (jupyter) and then through a second read_with_errors “x 4 5 6 7”.

val = target.simpleserial_read_witherrors('q', 4, glitch_timeout=20)
print(val)

val2 = target.simpleserial_read_witherrors('x', 4, glitch_timeout=20)#For loop check
print(val2)

However, what actually happens is that I do receive the following:


I have tried adding a delay on the microcontroller side, but it did not fix the issue.
I would really appreciate any possible suggestion in order to fix this.
Thank you in advance for your help -and I apologize if this something very easy that I should have figured out through reading the documentation.

Hi,

Try calling simpleserial_read_witherrors(..., ack=False). By default, that method looks for the ack/error code that gets sent back from the device at the end of a simpleserial command (the return 0xXX at the end of the function in C is the error code), which is probably eating the start of your next command.

Alex

1 Like

Thank you. It works now! :slight_smile: