![]() | |
| Home Page | Mark Forums Read | Today's Posts | My Replies | Classifieds | Reviews | Photo Gallery | Web Links | Share Files | Advertise With Us | Ad List |
| |||||||
| LinuxCNC (formerly EMC2) Discuss LinuxCNC (formerly EMC2) Controlers here! |
| This forum is sponsored by: |
![]() |
| LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
| |||
| |||
hi to all, the problem: in axis there is a signal " axis.0.joint-pos-fb" that it gives back the position of axis 0 (x in my case) how I make to read the variable from a program python? thanks Alessandro |
|
#3
| |||
| |||
| In your python code include python-HAL glue code. your python program will create a HAL pin and then you connect the signal you want to read to it. (This will not be realtime though) see: Creating Userspace Python Components with the 'hal' module By the way that signal name that was quoted is NOT from the AXIS display program. see here: EMC2's interface to HAL Chris M |
|
#4
| |||
| |||
|
Hello! Could you give me a small example. I want to get into Python code the value motion.program-line. (Userspace Python Components know how to create.) Sorry for my English. Last edited by nkp; 05-24-2012 at 01:29 AM. |
|
#5
| |||
| |||
| there is an example in the manual that i gave a link to. you would need to change the pin type to s32 instead of float, as the pin you wish to connect to is an s32 pin. then you would need to connect the pin you wish to read to the pin you made in the python program. You do that in a HAL file eg : net signal_name motion.program-line passthrough.in (using the example python program in the manual called passthrough) |
| Sponsored Links |
|
#6
| |||
| |||
| #!/usr/bin/python import hal, time h = hal.component("passthrough") h.newpin("in", hal.HAL_S32, hal.HAL_IN) h.newpin("out", hal.HAL_S32, hal.HAL_OUT) h.ready() try: while 1: time.sleep(1) h['out'] = h['in'] print h['in'] except KeyboardInterrupt: raise SystemExit try this version of passthrough... |
|
#7
| |||
| |||
| Thanks for the quick reply! But the question is slightly different. Here is my component pult.py : [code] Code: #!/usr/bin/python
import hal, time , serial
h = hal.component("pult")
h.newpin("out", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("a", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("b", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("c", hal.HAL_BIT, hal.HAL_OUT)
h.newpin("numberin", hal.HAL_S32, hal.HAL_IN)
h.newpin("numberout", hal.HAL_S32, hal.HAL_OUT)
h.ready()
h['a'] = False
h['b'] = False
h['c'] = False
h['out'] = False
try:
while 1:
time.sleep(1)
ser = serial.Serial('/dev/ttyS0', 115200, timeout=1)
x = ser.read()
if x == '2' :
h['out'] = True
else :
h['out'] = False
if x == '3' :
h['a'] = True
h['b'] = False
if x == '4' :
h['b'] = True
h['a'] = False
if x == '5' :
h['c'] = True
ser.close()
h['numberout'] = h['numberin']
n=h['numberout']
except KeyboardInterrupt:
raise SystemExit Code: loadusr -Wn pult python pult.py net numb motion.program-line pult.numberin Code: #!/usr/bin/python bla... bla...bla.. x=n I have tried so: Code: #!/usr/bin/python import pult x=n print n Code: >>> import pult HAL: ERROR: duplicate component name 'pult' Traceback (most recent call last): File " |
|
#8
| |||
| |||
| They here thus far prompted this method: Code: from subprocess import Popen, PIPE
a= Popen('halcmd getp minmax.0.max ', shell=True, stdout=PIPE).stdout.read()
x=int(a)
print x Code: loadrt conv_s32_float addf conv-s32-float.0 servo-thread net numb motion.program-line conv-s32-float.0.in loadrt minmax addf minmax.0 servo-thread net numb1 conv-s32-float.0.out minmax.0.in |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Newbie- G-code programming library in python | bermanmk | G-Code Programing | 1 | 11-09-2009 08:24 PM |
| Need Help!- How do I read the value of an F-type parameter into a macro variable? | Jan d. | Mazak, Mitsubishi, Mazatrol | 24 | 02-17-2009 10:47 PM |
| EMC2 variable pitch / variable diameter threading. | samco | General Metalwork Discussion | 0 | 03-09-2008 01:40 PM |
| just another python gcode thing | cyclestart | LinuxCNC (formerly EMC2) | 8 | 02-18-2008 08:54 AM |
| simple python g-code generators | Dan Falck | OpenSource Software | 0 | 11-26-2007 04:37 PM |