Hello Guest it is April 29, 2024, 01:20:06 AM

Author Topic: Using M7 to run a script in a command window.  (Read 673 times)

0 Members and 1 Guest are viewing this topic.

Using M7 to run a script in a command window.
« on: January 18, 2022, 05:03:09 PM »
Hello everyone,

I'm trying to do an experiment. I'm really new to Mach4 and doing any custom programming in it. What I'm trying to do is create a custom m7 macro that will launch a command window and run a vb script or a batch file. The script will turn on a smart outlet and then the m9 script will turn off the smart outlet.
The script I created works to perform those functions if I just run the vb script manually on my computer. Now, I want to use m7 and m9 to call these scripts from Mach4.

I think I need to use the os.execute option, but I'm just not sure what else I need in the macro to make it work correctly. Any help would be much appreciated.

Thank you.
Re: Using M7 to run a script in a command window.
« Reply #1 on: January 18, 2022, 05:35:19 PM »
Hi,
What are you wanting to achieve?. Are you just trying to turn a solid state relay on or off?

m7 and m9, note the deliberate use of lower case....it is important as I will explain, are built in m-codes and are generally left alone, otherwise you risk upsetting Machs internal behavour
to those m-codes. That is not to say you cannot write your own but now Mach will execute YOUR m-code and if its not complete or the functionality differs from the standard m-code
you have created a f...up.

Its common practice that if you write custom m-codes that you number them 100 and above....as that will avoid clashing with any internal m-codes.


When Mach encounters an m-code in a Gcode file, it first parses the block to ALL lowercase, strips out leading zeros and strips out whitespace.
Thus: M 07 will be reduced to m7....and then Mach will search for that function, in the first instance in your profiles Macros folder, and if it does not find it there it will search up the file tree until it finds
a compliant macro. For this reason its a good idea to create and write macros using lowercase etc so that there is no possibility that Mach misses the macro you intended to run.

If you are just trying to turn on or off a solid state relay however you are going off the deep-end, there is a much MUCH simpler way to turn on or off a relay.

Craig

'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Using M7 to run a script in a command window.
« Reply #2 on: January 19, 2022, 08:58:23 AM »
I have an Avid CNC and the M7 and M9 controls a relay that turns on and off an outlet in the electronics enclosure. I was using that outlet to control the solenoid for an air cylinder that opens and closes the blast gate for dust collection that happens to be above the CNC at the ceiling. I am trying to eliminate the power cord that runs from the outlet in the enclosure by using a smart outlet. It's plugged into an outlet in the ceiling and the solenoid plugs into it.

I can control the smart outlet with a VB script or batch file that I created, so that part works fine. Now, I wanted to take the next step and not have to do it manually, but have the software control the smart outlet instead of the outlet in the enclosure.

I hope that makes sense.