Button to executes M-Code with adjustable argument

More
31 Jan 2013 19:05 #29357 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

Please Log in or Create an account to join the conversation.

More
31 Jan 2013 19:53 #29363 by ArcEye
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

Please Log in or Create an account to join the conversation.

More
01 Feb 2013 00:54 #29390 by ArcEye
A simple adaptation of the code in the link would look like
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.

More
01 Feb 2013 08:22 - 01 Feb 2013 08:31 #29413 by alan_3301
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
<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.

More
01 Feb 2013 17:30 #29431 by ArcEye

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 :cheer:

So long as the M66 parameter is not in use should work fine.

Please Log in or Create an account to join the conversation.

More
07 Aug 2013 22:01 #37479 by Blackwind
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)
<spinbox>
                <width>"6"</width>
                <halpin>"cantidad"</halpin>
button>
            <halpin>"actual-param"</halpin>
            <text>"Actualizar"</text>
custom_postgui.hal code here:
net remote-analin00 motion.analog-in-00 <= pyvcp.cantidad
net remote-actual-param halui.mdi-command-00 <= pyvcp.actual-param
mdi-command-00 invokes 101.ngc sub, here it is:
o<101> sub
M66 E0 L0 
(#1=#5399)
o<101> endsub
M2
Simple Test Gcode is:
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.075 seconds
Powered by Kunena Forum