Hi Tom,
Long time no talk, hope all is well.
I'm trying to make custom buttons that will pass a parameter to my tool changer routine. While milling , the g-code command "M6 T1" will pass the "1" to my program without issue.
Now using the custom button , I was under the impression that the "param" box would be the value of the VAR but it doesn't seem to work.
I set the parameters to the Action function like on the picture, but when calling the tool changer, the value isn't passed properly and instead of "3" as in the example ,it seems to use an uninitiated value of -10000000. What am I doing wrong? Anyway I can pass a value (from 1 to 16) to the function using the action call?
Thanks for the help!
Passing persist variable using "Script-> action-> Program"
Moderators: TomKerekes, dynomotion
Passing persist variable using "Script-> action-> Program"
- Attachments
-
- toolparam.png (7.61 KiB) Viewed 3422 times
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Passing persist variable using "Script-> action-> Program"
Hi,
The value is passed as a 32-bit float value and can be accessed with
Is that how you are accessing it ?
The value is passed as a 32-bit float value and can be accessed with
Code: Select all
int Button = *(float *)&persist.UserData[PERSIST_VAR]; // button code pushed
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Passing persist variable using "Script-> action-> Program"
#define TOOL_VAR 9
int *Tool = &persist.UserData[TOOL_VAR];
printf("Tool : %d\n", *Tool); // Displays value of the tool to change to (From M06 TXX g-code)
// Logic to calculate rotation count and direction from Last_Tool and Tool.
if (*Last_Tool > *Tool)
{
...
}
(*Last_Tool is set by reading a file on the PC)
I'm not sure how I would go about to combine your example of "Button" and my use of "*Tool". Remember , I am not a coder by trade so my skills are somewhat limited.
Should I simply duplicate my Tool_Changer.c code and adapt your "Button" in the code that is called from the button presses and keep my original code the way it is , and works , for when G-code changes the tool? Or , do you see a way I could write the code only once , combining both variables? Something like "If button is pressed , set variable this way , else set it the original method" ?
Thanks for the prompt response!
int *Tool = &persist.UserData[TOOL_VAR];
printf("Tool : %d\n", *Tool); // Displays value of the tool to change to (From M06 TXX g-code)
// Logic to calculate rotation count and direction from Last_Tool and Tool.
if (*Last_Tool > *Tool)
{
...
}
(*Last_Tool is set by reading a file on the PC)
I'm not sure how I would go about to combine your example of "Button" and my use of "*Tool". Remember , I am not a coder by trade so my skills are somewhat limited.
Should I simply duplicate my Tool_Changer.c code and adapt your "Button" in the code that is called from the button presses and keep my original code the way it is , and works , for when G-code changes the tool? Or , do you see a way I could write the code only once , combining both variables? Something like "If button is pressed , set variable this way , else set it the original method" ?
Thanks for the prompt response!
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Passing persist variable using "Script-> action-> Program"
You might read it assuming it is an integer set by M6 and if it is invalid then assume it is a float set by a button. Something like:
Note your original code assumes that Tool is a pointer to an integer. So its value is obtained by de-referencing the pointer with *Tool to get the value. But in the above code Tool is a simple integer so use Tool everywhere. A pointer is useful if you need to change the original value, but I doubt if that is ever required.
Code: Select all
int Tool = persist.UserData[TOOL_VAR]; // assume integer
if (Tool <= 0 || Tool >= 10) // invalid Tool Number?
Tool = *(float *)&persist.UserData[TOOL_VAR]; // yes, must be float
printf("Tool : %d\n", Tool); // Displays value of the tool to change to (From M06 TXX g-code)
// Logic to calculate rotation count and direction from Last_Tool and Tool.
if (*Last_Tool > Tool)
{
...
}
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.