Python Component - $PATH

More
24 Jul 2023 03:22 #276122 by zz912
Replied by zz912 on topic Python Component - $PATH
Here:
 

File Attachment:

File Name: passthrough.py
File Size:0 KB
Attachments:

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

More
24 Jul 2023 03:31 #276123 by cmorley
Replied by cmorley on topic Python Component - $PATH
You posted the error message  (note line 2):

halcmd: Traceback (most recent call last):
  File "/home/zdenek/linuxcnc/linuxcnc-2.8.4/bin/passthrough", line 2, in <module>
    h = hal.component("passthrough")
NameError: name 'hal' is not defined

But the file you posted line 2 is different:
1 #!/usr/bin/env python3
2 import hal, time
3 h = hal.component("passthrough")
4 h.newpin("in", hal.HAL_FLOAT, hal.HAL_IN)
5 h.newpin("out", hal.HAL_FLOAT, hal.HAL_OUT)
6 h.ready()
7 try:
8    while 1:
9       time.sleep(1)
10       h['out'] = h['in']
11 except KeyboardInterrupt:
12   raise SystemExit

You might not be running the file you think you are.
 
The following user(s) said Thank You: zz912

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

More
24 Jul 2023 03:34 #276124 by cmorley
Replied by cmorley on topic Python Component - $PATH
Also I don't think 2.8 can run python3 code
The following user(s) said Thank You: zz912

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

More
24 Jul 2023 04:39 #276125 by zz912
Replied by zz912 on topic Python Component - $PATH

But the file you posted line 2 is different:

Because, this is not halcompiled file.I will find the halcompiled file and send it tonight.

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

More
25 Jul 2023 02:44 #276196 by zz912
Replied by zz912 on topic Python Component - $PATH
/home/zdenek/linuxcnc/linuxcnc-2.9/bin/passthrough :
#!/usr/bin/python3.7
h = hal.component("passthrough")
h.newpin("in", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("out", hal.HAL_FLOAT, hal.HAL_OUT)
h.ready()
try:
    while 1:
        time.sleep(1)
        h['out'] = h['in']
except KeyboardInterrupt:
    raise SystemExit

halcompile stole "import hal, time".
Why?

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

More
25 Jul 2023 03:48 #276199 by phillc54
Replied by phillc54 on topic Python Component - $PATH
Try adding a blank line immediately before the import line in passthrough.py
 
The following user(s) said Thank You: zz912

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

More
25 Jul 2023 13:18 #276223 by zz912
Replied by zz912 on topic Python Component - $PATH

Try adding a blank line immediately before the import line in passthrough.py

 


It helped. It works. Thank you.

/home/zdenek/linuxcnc/linuxcnc-2.9/passthrough.py
#!/usr/bin/env python3

import hal, time
h = hal.component("passthrough")
h.newpin("in", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("out", hal.HAL_FLOAT, hal.HAL_OUT)
h.ready()
try:
    while 1:
        time.sleep(1)
        h['out'] = h['in']
except KeyboardInterrupt:
    raise SystemExit

/home/zdenek/linuxcnc/linuxcnc-2.9/bin/passthrough
#!/usr/bin/python3.7
import hal, time
h = hal.component("passthrough")
h.newpin("in", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("out", hal.HAL_FLOAT, hal.HAL_OUT)
h.ready()
try:
    while 1:
        time.sleep(1)
        h['out'] = h['in']
except KeyboardInterrupt:
    raise SystemExit

Is this a bug?

This example is here:
linuxcnc.org/docs/2.9/html/hal/halmodule..._basic_usage_example


 

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

More
25 Jul 2023 23:41 #276274 by phillc54
Replied by phillc54 on topic Python Component - $PATH
Yes, it is a bug. A fix has been pushed to 2.9.
 
The following user(s) said Thank You: zz912

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

More
26 Jul 2023 16:35 #276314 by zz912
Replied by zz912 on topic Python Component - $PATH
I tested your fix:
github.com/LinuxCNC/linuxcnc/pull/2597

It works. Good job.
The following user(s) said Thank You: phillc54

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

Time to create page: 0.090 seconds
Powered by Kunena Forum