Controlling KMotionCNC from KFLOP/Kogna
User KFLOP/Kogna C Programs can request actions to be performed by the KMotionCNC Application running on the PC by setting various command codes into special persist.UserData variables. The special UserData variables are being continuously uploaded with the Bulk Status record that KMotionCNC requests at approximately 10 times per second to update the DROs and so forth. If a command code is uploaded, KMotionCNC attempts to perform the requested action, then changes the UserData Command Value to a result code. Zero indicates success and a negative value indicates an error code (all commands are positive). So the typical process involves:
- KFLOP/Kogna stores command into a Persist Var to request an action
- The command is uploaded to KMotionCNC with the next status request
- KMotionCNC performs the action
- KMotionCNC clears the Persist Var to indicate completion
- KFLOP/Kogna detects the command Var has been cleared to know the action was successful and complete
The Status uploads several Persist Vars which permits additional parameters to be uploaded with the command to KMotionCNC if required by the action to be performed. If extra parameters or data is required, then one of the uploaded parameters will specify where that data is located.
The number of UserData variables has now been expanded from 100 to 200 Variables and Variables 100-107 are the special vars constantly uploaded with bulk status. This is defined in the PC-DSP.h file as:
Currently supported actions include:
- EStop
- Halt
- Execute
- Single Step
- Set FRO
- Inc/dec FRO
- Set X,Y,Z,A,B,C DROs
- Push a User Defined Action Button
- Execute an M Code
- Display a Message Box
- Get/Set GCode #Vars
- Execute a MDI line of GCode
A new example called KFLOPtoPCCmdExamples.c is included which demonstrates how to invoke these actions from a KFLOP User C Program. The following helper functions are included in the example that simplify invoking the actions by setting the proper persist variables. They are:
The Example code to make use of the helper functions is in the example as: