What's the easiest way to write and load a simple program?

More
30 Sep 2019 16:13 #146722 by BigJohnT
These are my M100 to open the collet and M101 to close the collet

M100
#!/bin/sh
# open the collet closer
eval halcmd setp or2.3.in1 1
sleep 0.25
eval halcmd setp or2.3.in1 0
sleep 0.5
exit 0

M101
#!/bin/sh
# close the collet closer
halcmd setp or2.4.in1 1
sleep 0.25
halcmd setp or2.4.in1 0
sleep 0.5
exit 0

This is my HAL file for the collet, I use an or2 so I can use both my physical buttons and the M100/M101 to operate the collet.
# External Collet Open/Close Buttons
net collet-open-btn or2.3.in0 <= hm2_5i20.0.gpio.027.in_not
net collet-close-btn or2.4.in0 <= hm2_5i20.0.gpio.025.in_not
# Collet Open/Close Outputs
net collet-open hm2_5i20.0.gpio.043.out <= or2.3.out
net collet-close hm2_5i20.0.gpio.041.out <= or2.4.out

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

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

More
30 Sep 2019 16:21 #146724 by Scot
Great info.

Now where did you put them? I think I found the spot, but we're still working on finding out for sure.

There is a file in the linuxcnc/config file called ngcgui_lib. It has a file in it named mfiles. In that mfiles file, there is a single file that has an icon with some gears on it. I don't know enough about how to identify that kind of file, but if it's an executable file, then it would make sense to make those bits of code in that mfiles folder. The code in that file is below:

#!/bin/sh
# Clear axis info notifications
# use in gcode subroutines and/or connect to pushbutton

# M1nn files must exist _before_ starting emc
# in the [DISPLAY]PROGRAM_PREFIX
# or in a dir specified by [RS274NGC]USER_M_PATH

# the pin for axisui.notifications-clear-info is in emc-2.4pre
# using an earlier version will print error to stdout

halcmd setp axisui.notifications-clear-info 1
sleep .100 ;# requires a sleep that does <1
halcmd setp axisui.notifications-clear-info 0

# if a M1nn command fails and its script exits with nonzero status,
# the gcode program exits. So always exit 0, and make sure
# the M1nn command prints a message in order to keep on going.
exit 0


Is that the location of the code with your setup and does the icon with gears mean an executable file? Keep in mind, I only used linux for about a year, mostly in gui and rarely in command line - and that was 18 years ago. So please forgive my ignorance.

Thanks,

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

More
30 Sep 2019 18:07 - 30 Sep 2019 18:08 #146734 by Todd Zuercher
One place to put the files is here

Then after you save the M-code file there, you simply right click the file, select "properties" from the pop up menu, then click the "Permissions" tab in the window that pops up, and check the "allow this file to run as a program" check box and click ok.
Attachments:
Last edit: 30 Sep 2019 18:08 by Todd Zuercher.
The following user(s) said Thank You: Scot

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

More
30 Sep 2019 18:19 #146737 by Scot
Todd, thank you SOOO much! This helps more than you know! I'm a very visual learner and limited in my command line abilities. But I'm learning fast. This makes it much easier.

I did have a rough idea of where I should put those files, but making them executable was giving me issues. I was literally in the middle of studying how to do that when your post came up.

Thanks again. This is great!

I'll keep you posted. Making this work is going to be feeding me. If what you offer helps, which I think it will, you're indirectly helping me get fed!

Scot

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

More
30 Sep 2019 18:48 #146741 by Scot
Todd, that really helped. But I made a sample file with Mousepad and I went to change the permissions in root via the gui, but I ran into a snag. I didn't see a selection in the drop down menus for allowing the file to be run as a program.

I assume that the permissions need to be changed as your info laid out. But even in root, under the gui, there is no "program" section for me to allow it to be running as a program. If it helps, I just made a simple text file and named it M101. Then I tried to change it to a program in root, but it didn't help. Then I renamed the file with an ngc suffix, and tried again. But nothing like what is showing on your screen was there, sans the four drop down boxes.

Any light you can shed on this subject for me will be very helpful.

Thanks,

Scot

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

More
30 Sep 2019 18:57 #146743 by BigJohnT
You don't do that as root, in fact you do very little as root. What OS are you using?

Most Debian based you start the file manager then right click on the file, select Properties and on the Permissions tab is where you will find a checkbox for executable.

JT

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

More
30 Sep 2019 19:03 #146744 by Scot
Well I guess I had the wrong folder. From what I could see there is a file called M110 in linuxcnc/nc_files/ngcgui_lib/mfiles.

I was thinking that since this folder mfiles had that file and it was what I thought was executable, then the mfiles folder was where I should place it. I need root privileges to put it there.

That being said, looking at your example, it's in your home directory path for you as a user and it's not that deep into the nc_files folder so I'll give it a whirl and try and place it into my nc_files folder in my home/scot/linuxcnc/nc_files path and see what happens.

Thanks again. It's been so long since I used linux and like I've probably said too much, I'm going by fading memory and limited experience.

Scot

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

More
30 Sep 2019 19:08 #146746 by Todd Zuercher
You don't need root privileges, and you should not be using them to do this.
The file should not have any suffix. (it will not work with a suffix added)

What is the first line or two in your file?
if it does not start with
#!/bin/sh
or
#!/bin/bash
Then the file browser (Thunar) won't recognize it as a shell script and won't give the option of setting it as executable.
(or the same happens if the file name has a file extension.)
The following user(s) said Thank You: Scot

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

More
30 Sep 2019 19:11 #146747 by Scot
WHACKY!

I just opened mouspad in my profile, copied the example text in the body of the file and saved it as M101. Then when I saved it, it came up with the icon with the gears on it, automatically? It didn't do that in root. Strange. I was able to move it into my home/scot/linuxcnc/nc_files folder without a hassle, too. Then I rightclicked on it and checked the permissions and bang! There was the check-box for making it run as a program.

Now all I have to do is to write the proper code to marry it to the PWM board and I'll be in business.

It was all about where I placed it. Placing it in the mfiles folder was only able to be done in root and not necessary.

I should have stuck with linux back a long time ago. But I'm getting the gist by learning the need-to-know stuff.

Thanks again. This was REALLY helpful! I'll keep you posted. It means a bunch.

Scot

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

More
30 Sep 2019 19:16 #146749 by Todd Zuercher

Well I guess I had the wrong folder. From what I could see there is a file called M110 in linuxcnc/nc_files/ngcgui_lib/mfiles.

I was thinking that since this folder mfiles had that file and it was what I thought was executable, then the mfiles folder was where I should place it. I need root privileges to put it there.

That being said, looking at your example, it's in your home directory path for you as a user and it's not that deep into the nc_files folder so I'll give it a whirl and try and place it into my nc_files folder in my home/scot/linuxcnc/nc_files path and see what happens.

Thanks again. It's been so long since I used linux and like I've probably said too much, I'm going by fading memory and limited experience.

Scot


That M110 in linuxcnc/nc_files/ngcgui_lib/mfiles is part of an example configuration for demonstration purposes. If you load that demo config, and look at it's INI file it should have an entry in the [RS247NGC] section that points to that directory so that it can use that custom M-code.
The following user(s) said Thank You: Scot

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

Time to create page: 0.491 seconds
Powered by Kunena Forum