pyVCP button to control generic digital out
21 Jan 2021 21:43 #196150
by oddwick
pyVCP button to control generic digital out was created by oddwick
Just curious if this is even possible. I have searched the forum and to be honest i am not really sure what to search for. what i am trying to do is create a pyvcp button to toggle a digital output. specifically with a mesa 7i96 using one of the general outputs to turn on and off an extraction fan. i can do it using an M code, but i would really like to do it with a button and toggle if possible. any ideas?
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19304
- Thank you received: 6463
21 Jan 2021 22:28 #196160
by tommylight
Replied by tommylight on topic pyVCP button to control generic digital out
It should be,
www.anderswallin.net/tag/pyvcp/
linuxcnc.org/docs/2.8/html/gui/pyvcp.html
First link, second example should do what you need, or checkbutton on the second link, but the latter is very small.
www.anderswallin.net/tag/pyvcp/
linuxcnc.org/docs/2.8/html/gui/pyvcp.html
First link, second example should do what you need, or checkbutton on the second link, but the latter is very small.
Please Log in or Create an account to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
Less
More
- Posts: 5008
- Thank you received: 1441
22 Jan 2021 03:31 - 22 Jan 2021 03:32 #196177
by Todd Zuercher
Replied by Todd Zuercher on topic pyVCP button to control generic digital out
Yes it very much is possible. It's even possible to have both a custom m-code and a vcp button. In fact it can make it easier. If you set up an m-code, you can trigger it with a halui mdi command with the vcp button.
Without the M-code you have to use either a hal toggle component, or a toggle button in your vcp.
Without the M-code you have to use either a hal toggle component, or a toggle button in your vcp.
Last edit: 22 Jan 2021 03:32 by Todd Zuercher.
Please Log in or Create an account to join the conversation.
22 Jan 2021 19:40 #196265
by oddwick
Replied by oddwick on topic pyVCP button to control generic digital out
hey thanks tommy, i got that far, i have some buttons that turn on the pump and flood, and that works pretty well. and that example is pretty much what i had going, but where i got lost there seems to be no attributes that i can set for motion.digital-out-NN. like with mist, there is halui.mist.on/halui.mist.off etc. that i can manipulate. how do i do that with digital-out?
is it better to use the m-code? that is what i use (o subs anyway) to do generic canned operations like parking head, probe touch off. but how would i actually toggle it or would the m code toggle it when its called? if i used a mdi command, can it process logic or access machine variables?Without the M-code you have to use either a hal toggle component, or a toggle button in your vcp.
Please Log in or Create an account to join the conversation.
22 Jan 2021 20:23 - 22 Jan 2021 20:26 #196270
by chris@cnc
Replied by chris@cnc on topic pyVCP button to control generic digital out
Hi,
not sure what do you want do with motion but i think you want enter some straight postion or switch on or off somthing.
I do also some off this and here my exmaple.
First button is for touching tool. I use a old style dial indicator and touch always 100mm top of the surface.
Second is for laser switch on and after find X and Y i set position. In my case not zero mounted.
And "Parkpositon" is drive to front or rearside.
not sure what do you want do with motion but i think you want enter some straight postion or switch on or off somthing.
I do also some off this and here my exmaple.
First button is for touching tool. I use a old style dial indicator and touch always 100mm top of the surface.
Second is for laser switch on and after find X and Y i set position. In my case not zero mounted.
And "Parkpositon" is drive to front or rearside.
Warning: Spoiler!
ini file to enter postion
[HALUI]
MDI_COMMAND = G10 L20 P0 X83 ( Set X to 83.000)
MDI_COMMAND = G10 L20 P0 Y-38 ( Set Y to -38.000 )
MDI_COMMAND = G10 L20 P0 Z0 ( Set Z to zero )
MDI_COMMAND = G10 L20 P0 Z100 ( Set Z to 100 )
MDI_COMMAND = G0 G53 X100 Y10 Z-10 (Park Position 1)
MDI_COMMAND = G0 G53 Y1000 Z-10 (Park Position 2)
hal file for IO
## --- Antasten ----
net MDI-x0 pyvcp.MDI-x0 halui.mdi-command-00
net MDI-y0 pyvcp.MDI-y0 halui.mdi-command-01
net MDI-z0 pyvcp.MDI-z0 halui.mdi-command-02
net MDI-z100 pyvcp.MDI-z100 halui.mdi-command-03
net Park-1 pyvcp.Park-1 halui.mdi-command-04
net Park-2 pyvcp.Park-2 halui.mdi-command-05
# --- Laser An ---
net laser-button hm2_7i76e.0.7i76.0.0.output-02 pyvcp.status-laser pyvcp.laser-an
XML code
<!-- Antasten-->
<label>
<text> "Antasten" </text>
<font>("Helvetica",14)</font>
</label>
<font>("Helvetica",14)</font>
<hbox>
<relief>RAISED</relief>
<button>
<halpin>"MDI-z100"</halpin>
<text>"Z=100.000"</text>
<bd>4</bd>
</button>
</hbox>
<hbox>
<checkbutton>
<halpin>"laser-an"</halpin>
<text>"Laser An"</text>
</checkbutton>
<led>
<halpin>"status-laser"</halpin>
<size>25</size>
<on_color>"green"</on_color>
<off_color>"red"</off_color>
</led>
<relief>RAISED</relief>
<button>
<halpin>"MDI-x0"</halpin>
<text>"X=83.000"</text>
<bd>4</bd>
</button>
<relief>RAISED</relief>
<button>
<halpin>"MDI-y0"</halpin>
<text>"Y=-38.000"</text>
<bd>4</bd>
</button>
<relief>RAISED</relief>
<button>
<halpin>"MDI-z0"</halpin>
<text>"Z=0.000"</text>
<bd>4</bd>
</button>
</hbox>
<!-- Parkposition-->
<label>
<text> "Parkposition" </text>
<font>("Helvetica",14)</font>
</label>
<hbox>
<relief>RAISED</relief>
<button>
<halpin>"Park-1"</halpin>
<text>"G0 G53 X100 Y10 Z-10"</text>
<bd>4</bd>
</button>
<button>
<halpin>"Park-2"</halpin>
<text>"G0 G53 Y1000 Z-10"</text>
<bd>4</bd>
</button>
</hbox>
</pyvcp>
Attachments:
Last edit: 22 Jan 2021 20:26 by chris@cnc.
Please Log in or Create an account to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
Less
More
- Posts: 5008
- Thank you received: 1441
22 Jan 2021 21:00 #196275
by Todd Zuercher
Replied by Todd Zuercher on topic pyVCP button to control generic digital out
A custom M-code can be pretty much any executable file, but is usually a Bash or Python script. In it's simplest form it may be just a bash script that executes a halrun command to setp the value of a hal input pin. The hal pin will then hold that value until it is changed by something else. (You have to remember though, you can't setp a hal input pin if it is already connected to an output.)
What might be the best approach will depend on the complexity of what you're trying to accomplish.
Unfortunately custom m-codes can't contain g-code, so o-sub logic and machine parameter variables aren't available. But you can do that by remapping an m-code.
What might be the best approach will depend on the complexity of what you're trying to accomplish.
Unfortunately custom m-codes can't contain g-code, so o-sub logic and machine parameter variables aren't available. But you can do that by remapping an m-code.
The following user(s) said Thank You: tommylight
Please Log in or Create an account to join the conversation.
22 Jan 2021 21:08 #196278
by rodw
Replied by rodw on topic pyVCP button to control generic digital out
Its not often done, but it is possible to maintain a separate pin inside your screen handler that is set by a screen control or by analog or digital input. Its a long time since I've done it but it does work.
Please Log in or Create an account to join the conversation.
07 Feb 2021 16:13 #197926
by oddwick
Replied by oddwick on topic pyVCP button to control generic digital out
so for what i am trying to do, that is a bit of overkill. basically i just need to hit button on screen and toggle one of the digital outputs on a 7i96. i would think that it would have been simpler than that. i can do it with the mist and flood, but i have two more that need to do the same thing to...
Now, when you say m code can be any executable, that really peaks my interest for other things. BUT, (there's always a but) you say that one cant pass machine parameters to it unless you remap it. could you elaborate?
Now, when you say m code can be any executable, that really peaks my interest for other things. BUT, (there's always a but) you say that one cant pass machine parameters to it unless you remap it. could you elaborate?
Please Log in or Create an account to join the conversation.
07 Feb 2021 20:30 #197950
by rodw
Replied by rodw on topic pyVCP button to control generic digital out
This very old example with help from islander261 is extracted from a python screen handler file for Gmocappy
In this case an analog input is connected to a pin called command-from-file in the handler
Different numeric ranges sent by M67/M68 override the screen controls
So in your case you could connect the screen button to your fan and set it from gcode as well...
In this case an analog input is connected to a pin called command-from-file in the handler
Different numeric ranges sent by M67/M68 override the screen controls
So in your case you could connect the screen button to your fan and set it from gcode as well...
Warning: Spoiler!
#ISLANDER - input for control codes from gcode file (M67 E0 & M68 E0)
self.command_from_file = hal_glib.GPin(halcomp.newpin("command-from-file", hal.HAL_FLOAT, hal.HAL_IN))
self.lock_height = hal_glib.GPin(halcomp.newpin("lock-height-from-file", hal.HAL_BIT, hal.HAL_OUT))
self.halcomp["lock-height-from-file"] = False
#ISLANDER - service command from gcode
self.command_from_file.connect("value-changed", self.on_new_command_from_file)
self.hal_btn_THC = self.builder.get_object("hal-btn-THC")
#ISLANDER - this function is used to decode command from gcode file
# if real time control of height hold is desired then 1X and 2X need to be
# decoded in a realtime component
def on_new_command_from_file(self, hal_pin, data = None):
if hal_pin.get() != 0:
command = hal_pin.get()
#THC run from file
if 20 <= command < 30:
self.halcomp["lock-height-from-file"] = False
#no need to decode I% here no Hypertherm RS-485
# height hold from file
elif 10 <= command < 20:
self.halcomp["lock-height-from-file"] = True
#no need to decode I% here no Hypertherm RS-485
#global THC on
elif 900 == command:
#self.hal_btn_THC.set_active(True)
self.halcomp["hal-btn-THC"] = True
# global THC off
elif 999 == command:
#self.hal_btn_THC.set_active(False)
self.halcomp["hal-btn-THC"] = False
#get arc voltage
elif 360 <= command < 400 or 3060 <= command < 3201:
if command >= 3060:
command = command - 3000
else:
command = command - 300
self.halcomp["target-voltage"] = command
self.lbl_prog_volt.set_label("%d" % command)
#get preset Amps not actually used
elif 410 <= command < 500 or 4000 <= command < 4201:
if command >= 4000:
command = command - 4000
else:
command = command - 400
#nothing else to do here for now
#get arc servo delay time
elif 50 <= command < 60 or 500 <= command < 600:
if command >= 500:
command = (command - 500)
else:
command = command - 50
self.adj_THC_delay.set_value(command)
#get THC tune
elif 710 <= command < 720:
command = command - 710
#nothing to set yet
elif 80 <= command < 90 or 800 <= command < 900:
if command >= 800:
command = (command - 800)
else:
command = command - 80
self.adj_pierce_delay.set_value(command)
Please Log in or Create an account to join the conversation.
09 Feb 2021 00:26 #198105
by andypugh
Replied by andypugh on topic pyVCP button to control generic digital out
If you just want to link an onscreen button to a physical IO pin it is just a case of making the control in a PyVCP panel and (in HAL) connecting the pyvcp pin to the io pin.
It would be as simple as
net this-pin pyvcp.button -> hm2_7i96.0.gpio.000.out
Or similar.
It would be as simple as
net this-pin pyvcp.button -> hm2_7i96.0.gpio.000.out
Or similar.
Please Log in or Create an account to join the conversation.
Time to create page: 0.123 seconds