linuxcnc.command().mdi() vs .program_open()

  • scsmith1451
  • scsmith1451's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
19 Oct 2025 23:17 #336731 by scsmith1451
linuxcnc.command().mdi() vs .program_open() was created by scsmith1451
Can anyone tell me the difference(s) between calling an ngc routine with .mdi("o<myfunction> call") and .program_open("myfunction.ngc")?

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

More
20 Oct 2025 10:31 #336740 by Aciera
Replied by Aciera on topic linuxcnc.command().mdi() vs .program_open()
A file containing a subroutine callable with .mdi("o<myfunction> call") is different from a program file that can be opened using .program_open("myfunction.ngc")

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

More
20 Oct 2025 16:14 #336753 by JT
mdi(string) send an MDI command. Maximum 254 chars

MDI executes the command

program_open(string) open an NGC file

Open loads a file into memory but does not run the file.

JT
The following user(s) said Thank You: scsmith1451

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

  • scsmith1451
  • scsmith1451's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
21 Oct 2025 17:50 #336842 by scsmith1451
Replied by scsmith1451 on topic linuxcnc.command().mdi() vs .program_open()
Follow-on:

I'm working on a python program to check the levelness of my table.

I have several o<word> functions that are currently attached to buttons on the gmoccapy vcp, one to set zero_z, one to make the measurement and one to reset the spindle back to zero_z preparatory to the next measurement. All work as expected.

The python program is an attempt to automate the process measuring the four corners and the center of the table, then record the values into a spreadsheet. The hope is that overtime I can create run charts for each point to evaluate accuracy and precision.

Currently, the application moves to the Z height and sets zero_z calling the first .ngc function as expected. Next it moves the spindle to the first corner and calls the measurement.ngc. The spindle is lowered to the touch plate, but fails to move up and back down for the final measurement. It appears as though the function is failing to execute all of the commands before returning to the application complaining that the spindle failed to reach the touch plate.

I'm wondering if calling an o<word> function is limited to executing just one command when called by c.mdi("o<word>")?

Perhaps o<word> commands need to be processed with c.program_open. However, your previous response indicates that the code would be loaded but, not executed. 1) How do I get the file to execute after opening it, 2) Will loading a program preempt the execution of the running python program?

Any hints to get around this SNAFU?

Regards,

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

More
21 Oct 2025 20:47 #336851 by JT
auto(int[, int]) run, step, pause or resume a program.

This is how I open then run a program in Flex GUI

github.com/jethornton/flexgui/blob/maste...exgui/actions.py#L13

github.com/jethornton/flexgui/blob/maste...xgui/actions.py#L296

assuming you're using a probe you can store the probe results in a file.

JT
The following user(s) said Thank You: scsmith1451

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

  • andypugh
  • andypugh's Avatar
  • Away
  • Moderator
  • Moderator
More
22 Oct 2025 13:32 #336878 by andypugh
Replied by andypugh on topic linuxcnc.command().mdi() vs .program_open()
Why not just write a simple G-code program to probe your 5 points and log the data to file?
(probeopen proberesults.txt)
G53 G0 Z 100
G53 G0 X0 Y0
G38.2 Z0
G53 G0 Z100
G53 G0 X0 Y1000
G38.2 Z0
G53 G0 Z100
G53 G0 X1000 Y1000
G38.2 Z0
G53 G0 Z100
G53 G0 X1000 Y0
G38.2 Z0
G53 G0 Z100
G53 G0 X500 Y500
G38.2 Z0
G53 G0 Z100
(probeclose)
M2
The following user(s) said Thank You: tommylight, scsmith1451

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

  • scsmith1451
  • scsmith1451's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
23 Oct 2025 16:22 #336967 by scsmith1451
Replied by scsmith1451 on topic linuxcnc.command().mdi() vs .program_open()
My effort is to learn g-code subtleties that are new to me as well as to improve my python coding abilities.  Consequently, I trying to fully automate the measurement process. To that end, I decided that I could combine both Andypugh and JT's approaches to first capture the data with a g-code script then process it with python.

As I studied o-code subroutine examples I attempted to use an internal subroutine with Andypugh's suggestion for a more elegant approach. I've attached my code for your inspection. 

When I load the code into LCNC this warning is raised:

 Near line 40 of ./check_level.ngc "Bad character '>' used". 

I'm lost as it appears that the code follows the examples in the documentation. Please help me understand the issue.

Kind regards
Attachments:

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

More
24 Oct 2025 08:17 #337032 by rodw
A long time since I played with this. I think you should use [ ] symbols. But check the docs

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

  • scsmith1451
  • scsmith1451's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
24 Oct 2025 11:17 #337039 by scsmith1451
Replied by scsmith1451 on topic linuxcnc.command().mdi() vs .program_open()
Thanks rodw.

Turns out that the error was misreporting the line number. When I parameterized the subroutine I inadvertently left a stray > on line 33.

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

  • scsmith1451
  • scsmith1451's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
25 Oct 2025 15:08 #337138 by scsmith1451
Replied by scsmith1451 on topic linuxcnc.command().mdi() vs .program_open()
You folks have been awesome helping a retired guy get into LinuxCNC. Thank you for your patience as I get my machine working properly.

One lase issue.

The .ngc probe code is working flawlessly, however, the (probeopen filename.txt) is not opening a file and therefore not capturing the measurements. what might be the problem and how do I resolve it?

Kind regards

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

Time to create page: 0.197 seconds
Powered by Kunena Forum