Newbie question - linuxcnc & python3

More
19 Oct 2023 18:39 - 19 Oct 2023 18:43 #283312 by gaba
hi guys! Newbie question here

im trying to send commands to a CNC machine using linuxcnc & python 3 but i dont quite understand what im missing ...

i was able to compile linuxcnc (v 2.9.1), install it (on debian 10, might upgrade it later) and use it from the default GUI (move the motors and stuff) without problems. But, when I try to use it with python 3 I cant make it work. Could it be the im missing something?

I have this script for example, when i execute poll() it fails with this:


>>> import linuxcnc
>>> c = linuxcnc.command()
>>> s = linuxcnc.stat()
>>> s.poll()
tool_mmap_user(): tool mmap not available
poll(): continuing without tool mmap data
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
linuxcnc.error: emcStatusBuffer invalid err=3
>>>


Im not sure if i should be doing something else before using linuxcnc package on python3. Could you give a hand ? not sure what im missing ...
Last edit: 19 Oct 2023 18:43 by gaba.

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

More
19 Oct 2023 21:27 #283321 by gaba
Replied by gaba on topic Newbie question - linuxcnc & python3
So... not sure what im missing yet but ... when i open the LinuxCNC GUI and I execute those python commands, it works ... so ... im guessing that i need the gui or somekind of poweron python command before a poll() ... naf (newbie as f**k :D)

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

More
21 Oct 2023 01:54 #283405 by MakerYang
Replied by MakerYang on topic Newbie question - linuxcnc & python3
I also encountered this problem. I suspect it's an issue with the user or the process, and I'm trying to resolve it.

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

More
21 Oct 2023 02:43 #283406 by gaba
Replied by gaba on topic Newbie question - linuxcnc & python3
ohhh ... ok ... then it should work right away? i mean, without opening de gui ?

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

More
21 Oct 2023 02:51 - 21 Oct 2023 02:57 #283407 by MakerYang
Replied by MakerYang on topic Newbie question - linuxcnc & python3
My solution is as follows:

1、If you use the built-in GUI interface, like axis, when you run the python program, you need to specify a user. This user needs to be consistent with the user running the GUI.
sudo -u armcnc python3 ./launch.py

It's important to note that you need to ensure the GUI has already been started first.

2、If you have customized your own GUI, such as DISPLAY=halui, you can follow the method below.
sudo -u armcnc linuxcnc machine.ini
sudo -u armcnc python3 ./launch.py
Last edit: 21 Oct 2023 02:57 by MakerYang.
The following user(s) said Thank You: gaba

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

More
21 Oct 2023 02:55 #283408 by gaba
Replied by gaba on topic Newbie question - linuxcnc & python3
Is there any way to avoid the GUI? i want to avoid using the stop or start / poweron from the gui to start sending commands to linuxcnc

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

More
21 Oct 2023 03:03 #283409 by MakerYang
Replied by MakerYang on topic Newbie question - linuxcnc & python3
In that case, you need to set the DISPLAY in the [DISPLAY] section of the machine.ini configuration to halui. If you have configured HALUI in the [HAL] section, you need to comment out or delete it. This way, when starting linuxcnc, the GUI will not appear. Subsequently, you can communicate with Linuxcnc via a Python program. For details, you can refer to: linuxcnc.org/docs/2.9/html/config/python-interface.html.
sudo -u armcnc linuxcnc machine.ini
sudo -u armcnc python3 ./launch.py
The following user(s) said Thank You: gaba

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

More
21 Oct 2023 03:16 #283410 by gaba
Replied by gaba on topic Newbie question - linuxcnc & python3
Thank you, ill try that. By the way, for future reference, starting the gui with from a bash console and then turning on the machine works great.

sudo -u user linuxcnc machine.ini
sudo -u user python3 ./launch.py

python file (launch.py in this example):
import linuxcnc 
c = linuxcnc.command()
c.mode(linuxcnc.MODE_MDI)
c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.mdi("G0 X10")

that code might need some waits but it works!

ty MakerYang!




 

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

More
21 Oct 2023 03:21 #283411 by MakerYang
Replied by MakerYang on topic Newbie question - linuxcnc & python3
LinuxCNC requires some time to start up. I'm working on how to better ensure that linuxcnc is ready when python starts. Relying on /tmp/linuxcnc.lock to judge isn't very reliable.

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

More
21 Oct 2023 03:24 #283412 by MakerYang
Replied by MakerYang on topic Newbie question - linuxcnc & python3
I actually manage it using a service.
[Unit]
Description=armcnc_linuxcnc
After=syslog.target network.target

[Service]
Type=simple
User=armcnc
WorkingDirectory=/opt/armcnc/
EnvironmentFile=/opt/armcnc/.armcnc/environment
Environment=DISPLAY=:0.0
ExecStart=/usr/bin/linuxcnc /opt/armcnc/configs/${MACHINE_PATH}/machine.ini
Restart=on-failure

[Install]
WantedBy=multi-user.target

The setting Environment=DISPLAY=:0.0 is a good one. Whether you use DISPLAY=halui or DISPLAY=axis, it can start linuxcnc effectively.
[Unit]
Description=armcnc_launch
After=syslog.target network.target

[Service]
Type=simple
User=armcnc
WorkingDirectory=/opt/armcnc/
EnvironmentFile=/opt/armcnc/.armcnc/environment
ExecStart=/usr/bin/python3 -B /opt/armcnc/configs/${MACHINE_PATH}/launch/launch.py
Restart=on-failure

[Install]
WantedBy=multi-user.target
The following user(s) said Thank You: gaba

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

Time to create page: 0.069 seconds
Powered by Kunena Forum