Errors with large number of remote procedure calls

Do I understand the error correctly?
If so how would implement my solution or is there a better one?
Alternatively is there a better alternative library suited to my needs?

Hardware
My project consists of multiple adruino controlled cartesian robots. All of these robots are connected via the USB serial connections to a computer.

Software
I am using simpleRPC but have encountered a problem. If there are too many commands sent at one time it does not send all the commands. I have taken an excerpt of my code to highlight the problem.

Server code:

#include <simpleRPC.h>
#include <Servo.h>

Servo Servo1; 

void setup() {
Serial.begin(9600);
Servo1.attach(4);
}

void loop() {
    interface(
    Serial,
    delay,
       "delay: How to cause a delay in ms. @ms: Milliseconds of delay",
    pack(&Servo1, &Servo::write),
        "servoMove: Angle to move servo ");
}

Client code:

from simple_rpc import SerialInterface
interface = SerialInterface("COM5", baudrate=9600)

if __name__ == '__main__':
    for x in range(10):
        interface.servoMove(0)
        interface.delay(1000)
        interface.servoMove(90)
        interface.delay(1000)

With this code I am trying to move a servo back and forth from 0 to 90 degrees and repeat this 10 times. It completes the first 3 loops of movement but then just stops.

This is also true with other commands involving movement of stepper motors and I find it will only do a small number of moves before it either stops or does something erroneous.

I don't fully understand how the simpleRPC package works but I'm guessing that it tries to send all the remote procedure calls at once and there is a limit which I am exceeding?

Is the solution to only send one remote procedure call at time and if so how would i do that?

Is there a better way to do this?

I'm not familiar with simpleRPC, but I suspect that you may be having trouble with the Serial input buffer. It's only 64 bytes and I'll guess that the client sends forty interface commands in rapid succession, most of which are thrown away during the first delay(1000) on the Arduino side.

I wondered too if the glacial baud rate you're using is problematic, but I now don't think so. As an experiment, have the client implement a delay of its own on each iteration of the for loop and see whether it behaves better.

Unfortunately when I implement the delay on the client end the servo doesn't move at all.

I have tried increasing the baudrate to 115200 but I run into a similar problem of it only doing 4 loops.

Post the new client code please.

Wow I'm stupid. Accidently forgot that in python sleep is in seconds but delay was in micro seconds.

You were right the below code fixes it :slight_smile:

from simple_rpc import SerialInterface
interface = SerialInterface("COM5", baudrate=9600)
from time import sleep

if __name__ == '__main__':
    for x in range(10):
        interface.servoMove(0)
        sleep(1)
        interface.servoMove(90)
        sleep(1)