-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Void methods: Wait for response? #40
Comments
A What kind of errors are you experiencing and can you share a minimal example so I can reproduce these errors? |
Thank you for your quick response. I was a bit unconcrete: The Arduino function is called fine, however, the python function returns before the arduino function is done: Arduino (ESP32) void longDelay(){
delay(5000);
}
boolean longDelayWithReturn(){
delay(5000);
return true;
}
void loop(void)
{
interface(
Serial,
longDelay, "longDelay: ",
longDelayWithReturn, "longDelayWithReturn: @return ret:"
);
} Python: with Interface("/dev/ttyUSB0", baudrate=50000) as mcu:
start = time.time()
mcu.longDelayWithReturn()
print(time.time()-start) # 5.002 => As expected, we wait for the result
start = time.time()
mcu.longDelay()
print(time.time()-start) # 0.0002 => We return almost immediatly. This is unexpected
# At this point, the arduino function is still running, but the python function has returned.
start = time.time()
mcu.longDelayWithReturn()
print(time.time()-start) #10.004 => 2*5 seconds, as we have to wait for the previous delay to be finished This is most likely caused by https://github.com/jfjlaros/arduino-simple-rpc/blob/2a78a493031dfa06e826f42d3ec419686676eede/simple_rpc/simple_rpc.py#L186-L188 , void methods dont wait |
Indeed, the client has no way of knowing whether a I guess we could let a On the device: bool wait() {
return true;
}
void loop() {
interface(
Serial,
wait, "wait: Wait for the previous command to finish. @return: True."",
// ...
);
} and client side: mcu.longDelay()
mcu.wait() I am not sure if this is a feature or a bug. |
The wait function is an interesting idea :) I would leave it as-is, as it could be an useful feature, but there should be a warning somewhere. |
I will give it some more thought. I will leave this issue open as a reminder. |
Is your feature request related to a problem? Please describe.
I've just noticed that calling void methods / methods without a return value does not block, they seem to return immediately. This caused errors, as I was expecting that the arduino method was done when the method returned.
Describe the solution you'd like
It would be nice to document that void method dont block. Alternatively, void methods could block, to behave similar to all other functions (this would be a breaking change).
The text was updated successfully, but these errors were encountered: