I am developing a software interface to control a 3-axis stage using python and qt (pyqt5) and arduino Mega to communicate with the drivers of the motors.
I want to be able to send messages through the serial port (i.e "X+1000") to move 1000 steps in the positive direction, and as well a message through the serial port to stop the motor ("ABORT") for safety reasons in the middle of a movement.
I achieved the first part, but I can't manage to make that the "ABORT" message stops the motor immediately. I was thinking about Interruptions, but there is no way to manage them from the Serial port (correct me please if I am wrong).
What I though then is to create global variables and check every loop if there is an "ABORT" message, but now nothing is working.
Please any advice or help would be super appreciated
What actually happens when you send "ABORT" to the present program?
While it may not be directly related to your question you should be aware that it is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
However, I am concerned at your requirement "make that the "ABORT" message stops the motor immediately". If there is any sense in which the purpose of that is to prevent damage or injury then it should NOT be done with software. There should be a BIG RED SWITCH that just cuts power to the motor driver.