31
Mach4 General Discussion / Script with a short pause in the middle (non-blocking)
« on: March 14, 2019, 11:48:21 AM »
Interesting question here...
I am writing a communications script (serial) to some servo drives. I want to abstract the communications so I can use a call like this anywhere in mach.
CurrentPosition = DriveCommunications (Position), where position is a parameter code to be read from the drive.
When DriveCommunications() is called, it assembles an ASCII string complete with a checksum and writes it over the serial port. It then analyzes the response, checks for errors, and returns the result. The whole thing is a bit more complicated, but that's the just of it.
Once a transmission is sent to the drive, a brief delay (a couple milliseconds) must be enacted to allow the drive to respond before reading the serial buffer. I successfully added a delay using wxTimer for a different script, but that calls a new function which makes returning a value from DriveCommunications() impossible AFAIK. I could also just use a plain old delay, but I don't want to block other functions from executing during this time. I am hoping to get this to the point where I can stream data from the drives and not interfere with other Mach functions.
My question is, is there a way to break out of the middle of a function, but return to execute the remaining code after a short while?
I am writing a communications script (serial) to some servo drives. I want to abstract the communications so I can use a call like this anywhere in mach.
CurrentPosition = DriveCommunications (Position), where position is a parameter code to be read from the drive.
When DriveCommunications() is called, it assembles an ASCII string complete with a checksum and writes it over the serial port. It then analyzes the response, checks for errors, and returns the result. The whole thing is a bit more complicated, but that's the just of it.
Once a transmission is sent to the drive, a brief delay (a couple milliseconds) must be enacted to allow the drive to respond before reading the serial buffer. I successfully added a delay using wxTimer for a different script, but that calls a new function which makes returning a value from DriveCommunications() impossible AFAIK. I could also just use a plain old delay, but I don't want to block other functions from executing during this time. I am hoping to get this to the point where I can stream data from the drives and not interfere with other Mach functions.
My question is, is there a way to break out of the middle of a function, but return to execute the remaining code after a short while?