M100 command with arguments

More
11 May 2020 19:32 #167412 by JesusAlos
Hi.
I would like to use M100 P0 and M100 P1 to set a bit 1 or 0.
I created a machine with two VCP buttons, one to set a parport bit to on and other button to set the same bit off, with command M100 P0 and M100 P1.

The topic here is, when I execute the bash with linux ./M100 P0 or ./M100 P1 the bit is set true or false correctly, but when do M100 P0 or M100 P1 on MDI or using the vcp buttons, the bash don't read the arguments P1 or P0.

Attach the machine. I'm on the V2.9.

Thank you.



INI file
[HALUI]
MDI_COMMAND = M100 P0
MDI_COMMAND = M100 P1

hal file
net mdi-cmd-00 pyvcp.btn-on => halui.mdi-command-00
net mdi-cmd-01 pyvcp.btn-off => halui.mdi-command-01

vcp file
<?xml version='1.0' encoding='UTF-8'?>
<pyvcp>
<labelframe text="">
<hbox>
<button> <width>10</width> <text>"ON"</text> <halpin>"btn-on"</halpin> </button>
<button> <width>10</width> <text>"OFF"</text> <halpin>"btn-off"</halpin> </button>
</hbox>
</labelframe>
</pyvcp>

bash file
#!/bin/bash

echo "ini"

if [ "$1" = "P0" ]
then
halcmd setp parport.1.pin-02-out False
echo "is 0"
fi

if [ "$1" = "P1" ]
then
halcmd setp parport.1.pin-02-out True
echo "is 1"
fi

if [ "$1" = "P1" ]
then
halcmd setp parport.1.pin-02-out True
echo "is 1"
fi
Attachments:

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

More
12 May 2020 02:39 - 12 May 2020 02:55 #167449 by Todd Zuercher
I believe that your problem is that $1 will equal 1 or 0 not P1 or P0.
Your bash script for the M100 file could also be much shorter and simpler. Simply having this should work
#!/bin/bash
halcmd setp parport.1.pin-02-out $1
echo "is $1"
exit 0
Last edit: 12 May 2020 02:55 by Todd Zuercher.

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

More
12 May 2020 07:44 #167477 by JesusAlos
Thank you

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

More
12 May 2020 13:17 #167516 by Todd Zuercher
Does it work? I didn't actually test that.

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

More
12 May 2020 13:46 #167523 by JesusAlos
I just test it and doesn't work.
The problem is the data type.
We must to change from real to integer. So, works like this:

#!/bin/bash
INT=`echo "$1" | awk '{ V=$1+0 ; printf("%.0f\n", V); }'`
halcmd setp parport.1.pin-02-out $INT

The surprising is, the bash wich works with linux console, don't works with LCNC, and the bash wich works with LCNC, doesn't work with console command ./M100 Px.
Thank you.

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

More
12 May 2020 14:48 #167529 by Todd Zuercher
I was afraid that may have been the case. Glad to see you've sorted it. I think the difference is that Linuxcnc is passing the variable in the gcode not simply executing a command line.

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

Time to create page: 0.072 seconds
Powered by Kunena Forum