User Defined M codes

More
21 Nov 2018 13:27 #121122 by rds626
User Defined M codes was created by rds626
I would like to use these codes to wiggle some I/O lines using halcmd, or, perhaps there is a better method. Anyway, I've set my PCNC 1100 up using a MESA 7i92 board & this works fine. This board has 2 ports available which only 1 port is used for all the standard functions leaving the other port free.

It seems to me there should be an easy way to utilize these unused I/O lines on the free port through user defined M codes M1xx. In some examples I see the use of halcmd to toggle bits on the MESA cards.

So I'm pretty sure that I would need to re-flash my 7i92 card with some definitions for the unused port. Then it looks like PP has some limitations that need to be address. For example, if open a terminal in "~v2.1.5/bin$" I see the executable "halcmd" but you cannot simply run it like you can in LinuxCNC.

Maybe in the context of a M1xx call the "halcmd" does work, but I just don't enough about PP to know. It kind of feels like Tormach doesn't want you to use any hardware but their own.

So how do I reprogram my 7i92 to use the free port for some simple I/O, and then make PP able to use them through the user defined M codes.

Any insights appreciated.

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

More
21 Nov 2018 14:34 #121126 by PCW
Replied by PCW on topic User Defined M codes
You don't need to reprogram the 7I92 to access simple GPIO

The way all Mesa Hostmot2 configurations work is that all I/O pins can be used as
GPIO as long as they have not been assigned to special functions like step generators. PWM, encoders, etc

Depending on the firmware used, you may have to insure that special functions on the second connector are not enabled (this is done in hal file via the loadrt hostmot2 line with the num_stepgens=N num_pwmgens=M etc configuration tokens)

To use GPIO pins as outputs you must first set them into output mode, as all pins default to inputs with pullups.

Since they are high before LinuxCNC is running (because of the pullups), GPIO outputs should be used in active low mode, for example if you wish to drive a SSR connect SSR+ to 7I92 5V and SSR- to the 7I92 IO pin. This will insure tha the SSR is not activated at power up or power down.

Note that the second connector is GPIO 17..33

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

More
21 Nov 2018 15:26 #121131 by Todd Zuercher
Replied by Todd Zuercher on topic User Defined M codes
To some extent it is true about Tormach. But look at it from their perspective. Allowing customers to freely customize their products would make customer support on their end a nearly impossible nightmare. Keeping the hardware and software locked down to known designs make it much simpler for them to support, troubleshoot and fix.

I am pretty sure that you wouldn't need to reflash. My understanding is that any unused pins can be used as GPIO. Although if the firmware is assigning a purpose to that pin, you may be limited to the programed purpose of it (as an input or output). That said just give it a try, can you hook up an indicator of some sort, open a terminal while Linuxcnc is running type halcmd -kf then try to setp the appropriate GPIO pin and see if any thing happens. If that works then you should be good to go setting up your custom M-codes.

(I don't know if any of this is possible in Path Pilot.)

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

More
21 Nov 2018 15:35 #121134 by andypugh
Replied by andypugh on topic User Defined M codes

Maybe in the context of a M1xx call the "halcmd" does work, but I just don't enough about PP to know. It kind of feels like Tormach doesn't want you to use any hardware but their own.


It should be easy enough to try it and see.

Note that halcmd will fail on any system if LinuxCNC is not running.

Does "halrun" work under PP? (That needs to be run with LinuxCNC _not_ running)

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

More
23 Nov 2018 22:10 #121274 by rds626
Replied by rds626 on topic User Defined M codes
OK, thanks for the feedback.

I'm able to create a file M101 in "~/tmc/configs/tormach_mill/nc_subs/" with the contents of
#!/bin/bash
halcmd show all
exit 0
and can see the output in the terminal program when I enter M101 into the MDI box.

So this looks promising. According to some of the examples the "halcmd" will need to be something like:
halcmd setp parport.0.pin-14-out True
to wiggle a pin. So I'm not sure yet what the parameters will be for my case, or even how to figure them out.

For reasons I don't understand I'm unable to run any of the linuxcnc utilities in "~/tmc/bin" such as "halcmd" and or "mesaflash". Simply typing the command returns "command not found" even though it's listed in the directory & is executable. If I type "./haclcmd" then I get "./halcmd: error while loading shared libraries: liblinuxcncini.so.0: cannot open shared object file: No such file or directory" which I don't understand. Is halcmd a program or some kind of script?

Anyway, In my quest to figure out the 7i92 contents I downloaded & install "mesaflash" and ran:
$ mesaflash --device 7i92 --addr 10.10.10.10 --readhmid
which produce the following file.

Note that for my mill I'm connected to P2 and I added the Tormach PCNC 1100 S3 column to this file.

File Attachment:

File Name: My7i92crlf.txt
File Size:5 KB

Note: This printout shows pin numbers based on a DB25 connector. The pin numbers change if using a IDC header.

What I'm interested in are the P1 pins since these are not being used. It's interesting to see that many of these pins are defined for what must be another Tormach device - perhaps the lathe???.

Anyway, there are some simple IO pins available to use on P1 (Is there a way to reflash these to be all simple IO pins?).

So now the question is how do I use this information to form a an argument for "halcmd" to wiggle a bit, let say on P1, Pin 14, IOPort 18?

Thanks again.
Attachments:

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

More
24 Nov 2018 01:00 - 24 Nov 2018 01:13 #121278 by PCW
Replied by PCW on topic User Defined M codes
_All_ I/O pins are available as simple GPIO with _any_ configuration, as long as they are not claimed
by a enabled special function.

Special functions are enabled in the config string, so you can make all pins become GPIO if you wish
by setting all the num_XXXX tokens in the configuration string to 0 (not recommended)

Typically special functions like stepgens are numbered so that higher numbered instances are on the second connector, so its normally possible to disable all special functions on the second connector by setting the configuration string properly. Once this is done the second connector I/O will become straight GPIO

The config string is located either in the hal or ini file

So to toggle a bit (say IO bit 17 = P1.pin1), you would first (typically in the hal file)
set the pin into output mode:

setp hm2_7i92.0.gpio.017.is_output true

And then either net the output pin to a signal:

net flood iocontrol.0.coolant-flood hm2_7i92.0.gpio.017.out

Or set/clear it by hand:

setp hm2_7i92.0.gpio.017.out true
setp hm2_7i92.0.gpio.017.out false
Last edit: 24 Nov 2018 01:13 by PCW.

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

More
24 Nov 2018 17:25 #121297 by rds626
Replied by rds626 on topic User Defined M codes
OK, after playing around with different arguments to halcmd in my M101 file, it appears something has happened & halcmd is no longer working.

When viewing the terminal output while issuing a M101 in PP I no longer see halcmd outputs. The terminal outputs:
Issuing MDI command: M101
REMAP hal component ...
So it looks like I can no longer issue halcmd's from within the M101 file???
Ignoring this I did try your suggestions but none of the lines are wiggling on P1 or gpio.017.
I'm still confused why I cannot simply open a terminal up in "~/tmc/bin" and run "halcmd" or any of the listed programs there.
This works in linuxcnc without any problems so what's going on with PP?

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

More
24 Nov 2018 17:37 #121298 by Clive S
Replied by Clive S on topic User Defined M codes
Are you using the PP gui ? if you are on the MDI try "ADMIN HALMETER"

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

More
24 Nov 2018 17:53 #121299 by andypugh
Replied by andypugh on topic User Defined M codes

Issuing MDI command: M101
REMAP hal component ...


REMAP? That's a surprise...

Halcmd won't work if LinuxCNC isn't active. (No shared memory area to connect to)

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

More
24 Nov 2018 18:57 #121301 by rds626
Replied by rds626 on topic User Defined M codes
Are you using the PP gui ? if you are on the MDI try "ADMIN HALMETER"
Yes & ADMIN HALMETER works as expected.
Halcmd won't work if LinuxCNC isn't active. (No shared memory area to connect to)
Not sure what that means while running PP. The only way I have been able to get halcmd to work was through a user defined M code where my file, M101, contained something like:
#!/bin/bash
halcmd show all
exit 0
Now this no longer works & reports:
Issuing MDI command: M101
REMAP hal component ...
My machine continues to work fine. The only way I figure to get back to where I was is to do a restore.

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

Moderators: cncbasher
Time to create page: 0.093 seconds
Powered by Kunena Forum