Updating pyVCP halpin from user defined M code Python file

More
8 years 4 months ago #113132 by lorenzn
I defined M103 as:
Code:
#!/usr/bin/env python # This file is M103 on the USER_M_PATH # testing Python interface import sys import subprocess import linuxcnc import hal print(sys.argv) #len always 3 try: s = linuxcnc.stat() # create a connection to the status channel s.poll() # get current values except linuxcnc.error, detail: print "error", detail sys.exit(1) g5x = (getattr(s, 'g5x_offset')) rotation = (getattr(s, 'rotation_xy')) print("g5x_offset = {}".format(g5x)) print("rotation = {}".format(rotation)) if False: # this is incorrect (error): hal.set_p("pyvcp.scope-xvalue", "888") if True: # this works but is there a better/recommended method (not using subprocess)? subprocess.call("halcmd setp pyvcp.scope-xvalue 123", shell=True)


Can I eliminate subprocess.call() to do this differently?

Please Log in to join the conversation.

More
8 years 4 months ago #113135 by nkp
Code:
#!/usr/bin/env python # -*- coding: utf-8 -*- import linuxcnc c = linuxcnc.command() c.mode(linuxcnc.MODE_MDI) c.wait_complete() c.mdi("M68 E0 Q123")





in HAL:
Code:
net vscope pyvcp.scope-xvalue motion.analog-out-00

Please Log in to join the conversation.

More
8 years 4 months ago #113138 by lorenzn
Thank you. I had to move c.mode call into a try block to get it to work.
Code:
try: c.mode(linuxcnc.MODE_MDI) except KeyboardInterrupt: pass

I see the number of I/O can be increased too. docs:
" If the number of analog I/O needed is more than the default of 4 you can add up to 16 analog I/O by using the num_aio option when loading motmod."

Please Log in to join the conversation.

More
8 years 3 months ago #113238 by andypugh

lorenzn wrote: Can I eliminate subprocess.call() to do this differently?


The LinuxCNC testsuite seems to use subprocess, though wrapped in a function;

github.com/LinuxCNC/linuxcnc/blob/af15a4...nlink/hallink.py#L20

So I think you can probably assume that subprocess is a good way to do it.

I think calling an M-code from G-code that then runs an MDI command to set a HAL pin that is netted to the pin that needs to be changed is needlessly complicated.

Though if you want to change a HAL pin from G-code then the GM68 (etc) codes are the simplest and most reliable way. But do it directly, not via an M-code.

Please Log in to join the conversation.

More
7 years 7 months ago #127701 by pl7i92
you might consider to use this option here
by Mcode

Please Log in to join the conversation.

Time to create page: 0.292 seconds
Powered by Kunena Forum