Button to executes M-Code with adjustable argument
- goaran
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 1
31 Jan 2013 19:05 #29357
by goaran
Button to executes M-Code with adjustable argument was created by goaran
Hellon
i have a panel with a pyvcp button, and a scale control.
now i want the button to execute an M-Code with the value of the scale control.
If is generate a MDI-command for the M-Code i cannot take the value from the scale control.
so how can this be done?
The aim is to get a button eg. button M104 that executes M104 P31415 if the scale control is set to 31415
thanks in advance
i have a panel with a pyvcp button, and a scale control.
now i want the button to execute an M-Code with the value of the scale control.
If is generate a MDI-command for the M-Code i cannot take the value from the scale control.
so how can this be done?
The aim is to get a button eg. button M104 that executes M104 P31415 if the scale control is set to 31415
thanks in advance
Please Log in or Create an account to join the conversation.
- ArcEye
- Offline
- Junior Member
Less
More
- Posts: 24
- Thank you received: 758
31 Jan 2013 19:53 #29363
by ArcEye
Replied by ArcEye on topic Button to executes M-Code with adjustable argument
Hi
A common problem in its many guises, along with the related one of getting a return value back.
This is a similar issue in this thread, albeit different requirement.
www.linuxcnc.org/index.php/english/forum...om-a-button?start=12
The answer was to write a component which received the values and then output them as required.
Something along those lines should work.
regards
A common problem in its many guises, along with the related one of getting a return value back.
This is a similar issue in this thread, albeit different requirement.
www.linuxcnc.org/index.php/english/forum...om-a-button?start=12
The answer was to write a component which received the values and then output them as required.
Something along those lines should work.
regards
Please Log in or Create an account to join the conversation.
- ArcEye
- Offline
- Junior Member
Less
More
- Posts: 24
- Thank you received: 758
01 Feb 2013 00:54 #29390
by ArcEye
Replied by ArcEye on topic Button to executes M-Code with adjustable argument
A simple adaptation of the code in the link would look like
You would just need something like this in your postgui.hal file
loadusr -W getscale
net scale-out getscale.scale <= pyvcp.scale-widget
net trigger-clicked getscale.trigger <= pyvcp.trigger-button
(altered to suit your actual pyvcp pin names)
regards
component getscale;
pin in float scale "Receives scale value";
pin in bit trigger = 0 "connected to the button";
option singleton yes;
option userspace yes;
author "ArcEye";
license "GPL";
;;
#include <stdio.h> /* Standard input/output definitions */
#include <stdlib.h>
#include <stdint.h> /* Standard types */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <signal.h>
int done = 0;
void adios(int sig)
{
done = 1;
}
void user_mainloop(void)
{
char buff[256];
int triggered = 0;
signal(SIGINT, adios);
signal(SIGTERM, adios);
bzero(buff,256);
while(!done)
{
usleep(250000);
FOR_ALL_INSTS()
{
if(trigger && !triggered)
{
sprintf(buff, "M101 P%08.03f", scale);
system(buff);
bzero(buff,256);
triggered = 1; // prevent further activations until button released
}
else if(!trigger && triggered)
{
triggered = 0;
}
}
}
exit(0);
}
You would just need something like this in your postgui.hal file
loadusr -W getscale
net scale-out getscale.scale <= pyvcp.scale-widget
net trigger-clicked getscale.trigger <= pyvcp.trigger-button
(altered to suit your actual pyvcp pin names)
regards
Please Log in or Create an account to join the conversation.
- alan_3301
- Offline
- Elite Member
Less
More
- Posts: 256
- Thank you received: 33
01 Feb 2013 08:22 - 01 Feb 2013 08:31 #29413
by alan_3301
Replied by alan_3301 on topic Button to executes M-Code with adjustable argument
This might be way more steps than necessary, and wont return a value (not sure if you need to) but I think it should work.
edit: forgot to add a button in panel.xml and hal file
panel.xml
postgui.hal file
machine.ini file
m104file.ngc
edit: forgot to add a button in panel.xml and hal file
panel.xml
<scale>
<font>("Helvetica",10)</font>
<width>"15"</width>
<halpin>"m104scale"</halpin>
<resolution>0.5</resolution>
<orient>HORIZONTAL</orient>
<initval>15</initval>
<min_>1</min_>
<max_>30</max_>
</scale>
<button>
<halpin>"m104button"</halpin>
<text>"Execute M104"</text>
<font>("Helvetica",10)</font>
</button>
postgui.hal file
net m104-scale pyvcp.m104scale-f => motion.analog-in-00
net m104-button halui.mdi-command-00 <= pyvcp.m104button
machine.ini file
MDI_COMMAND = o<m104file> call
m104file.ngc
o<m104file> sub
M66 E0 L0 (store analog pin 0)
#<scalenumber> = #5399
M104 P#<scalenumber>
o<m104file> endsub
M2
Last edit: 01 Feb 2013 08:31 by alan_3301. Reason: error in code
Please Log in or Create an account to join the conversation.
- ArcEye
- Offline
- Junior Member
Less
More
- Posts: 24
- Thank you received: 758
01 Feb 2013 17:30 #29431
by ArcEye
A good bit of lateral thinking
So long as the M66 parameter is not in use should work fine.
Replied by ArcEye on topic Button to executes M-Code with adjustable argument
This might be way more steps than necessary, and wont return a value (not sure if you need to) but I think it should work.
A good bit of lateral thinking
So long as the M66 parameter is not in use should work fine.
Please Log in or Create an account to join the conversation.
- Blackwind
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 1
07 Aug 2013 22:01 #37479
by Blackwind
Replied by Blackwind on topic Button to executes M-Code with adjustable argument
hi folks, i have use this example but having problems with Axis gcode preview, made a new post in GCODE section repost here, if someone has an answer!
Hi folks i have a little question here
i have a pyvcp spinbox to set #5399 and a button to refresh it.
pyvcp .xml code here (clipped)custom_postgui.hal code here:mdi-command-00 invokes 101.ngc sub, here it is:Simple Test Gcode is:
All works and runs very well, but Axis stop backplot drawing of gcode!, it is normal or its me?!
Anyone?
Regards
Rick
PS: LinuxCNC 2.5.3
Hi folks i have a little question here
i have a pyvcp spinbox to set #5399 and a button to refresh it.
pyvcp .xml code here (clipped)
<spinbox>
<width>"6"</width>
<halpin>"cantidad"</halpin>
button>
<halpin>"actual-param"</halpin>
<text>"Actualizar"</text>
net remote-analin00 motion.analog-in-00 <= pyvcp.cantidad
net remote-actual-param halui.mdi-command-00 <= pyvcp.actual-param
o<101> sub
M66 E0 L0
(#1=#5399)
o<101> endsub
M2
g0 x#5399
g91
x150
y150
x-150
y-150
m30
All works and runs very well, but Axis stop backplot drawing of gcode!, it is normal or its me?!
Anyone?
Regards
Rick
PS: LinuxCNC 2.5.3
Please Log in or Create an account to join the conversation.
Time to create page: 0.142 seconds