Hi,
Well, at the start of this thread, I steered you to some initial info to introduce you to mach’s script capabilities. It now seems that you want to tackle more complex sctipt tasks – so I’ll offer some more pointers.
Well I tried to get fancy and have the script both pop up a message
This we have already seen how to do.
Well and then to also update the value in Mach for which pulley ratio it got changed to.
This can be done via mach’s scripts also. Look up the “Set Pulley” call in the mach programmers reference manual.
Well Unfortunately I quickly found that it looks like all the MSM stuff are compiled files an not text scripts. So I got into the tools for how screens are done and buttons and realized it was not a small project.
Yes, the MSM scripts are compiled. Conceptually, the MSM scripts are extensions of Mach and as such are not intended for modification by end users. The MSM scripts, particularly those that handle MSM’s handing of M6 are not simple. Allowing end user modification of MSM scripts would create a support burden that MSM pricing won’t support. However, an MSM user can do any customization that can be done without MSM – it’s just that the technical techniques for doing so are different.
If you want to extend the actions associated with the processing of the M6 M-code, I’ll refer you to section 15 of the MSM user manual to start learning about customizing MSM. In particular, there are event hooks supplied by MSM to enable you to hook user scripts into the M6 handling – see section 15.9.1. of the user manual.
You can easily extend the actions of M6 by simply supplying the script that you want run as part of MSM’s m6 processing. This does not require the addition or alterations of any existing buttons (which is also available when using MSM) .
So I bailed out and just went with the simple popup message. I made an M441 and M442 file for the 2 speed ranges and modified my post for my cam package (HSMexpress) for manual NC commands and just had a pulldown option to pick Hi or Lo ratio and the post would then put an M441 or 2 into the g-code.
So the scripts are very basic.
Dave, one other item I tried was to make a user script to load the probe tool and turn on tool length offset. Specifically I tried to do the following sequence: G49, T250 M06, G43. I do a G49 first because it seems like sometimes mach flakes and doesn't change the offset value if it was already on. The problem seems to be thought that the M06 runs another script (an MSM one that is compiled and not editable I think), and thus either ends my user script before it completes or it does the G43 before it gets very far in the M06 script (not sure if scripts can run parallel). Ideally a simple button on the probing page that would do a tool change and then a G43 would be great. But if there is a simple way to get my script to do it that would be fine too.
Thanks,
Bryan
Now you are starting to get into more complicated script topics. Earlier in the thread I mentioned that it’s a good idea to put one user defined mcode per block as it avoids some scripting (synchronization) problems.
I’d guess that you may have attempted to write a simple script similar to this:
Code(“G49 T250 M06 G43”) – while that’s a reasonable first attempt, it’s going to cause problems that you probably didn’t expect. Let’s break that down into a multiple block version:
Code(“G49”)
Code(“T250 M06”)
Code(“G43”)
You probably expect each of the above lines to get executed in order and for each line to complete before the next line is started…. But mach won’t do that for you…. To understand this, you’ll need to know that mach implements M6 handling as a call to multiple user level M6 scripts (typically M6start and M6end when in stop&Wait tool change mode). But the above code fragment creates a recursive call from mach back into mach – and mach was not written to be either recursive or re-entrant, mach provides no script sync capabilities, and in general mach’s m6 handing is one of the most complex (error prone) areas of mach. Nesting mcode calls gets you quickly into a complex area of mach script programming (if the script writer is not up to doing things like inventing semaphore capabilities from scratch, then this an an area where you probably don't want to be).
Consider:
Now you are running a gcode file, it encounters a M441 (for example); you have now caused mach to leave the gcode interpreter and call a user mcode. This causes mach to start a new thread to run the M441. Mach will wait for this new thread to complete before continuing the original gcode block. But…. The new thread starts running and then it does the G49 – ok. The G49 is pretty fast, so it usually executes before the T250 M6 block gets called – but not always. You as the script programmer need to insert a sync wait step after the G49.
You want something more like this:
Code(“G49”)
<insert code to wait for G49 tom complete before going on>
Code(“T250 M06”)
Code(“G43”)
Now life gets really complicated…. You hit the code:T250 M6 and another new async thread is started…. (we are now 3 levels deep) and then that thread calls M6start and then M6end and each of those may do arbitrary user calls…. To make matters worse, Mach does not treat M6 as an atomic operation – the code call will return from the T250 M6 line before the M6 processing is complete! You now have multiple threads running in parallel – so generally the G43 is going to get executed sometime during the M6 execution period…. The result is not going to be pretty – it’s easy to crash a machine this way.
So we now want
Code(“G49”)
<insert code to wait for G49 tom complete before going on>
Code(“T250 M06”)
<insert code to wait for M6 to complete>
Code(“G43”)
The <insert code to wait for M6 to complete> is a real problem, mach does not provide a call to wait for that condition. Yes, if you beat on mach long enough you can discover ways to accomplish this… I had to invent one for MSM.
However, rather than delve down into this level of mach complexity, I’d suggest that you not make a user mcode (Ex m441) invoke another mcode (M6). Avoiding nesting Mcodes will make life much simpler. And I expect that nested mcodes are not needed for what you want to accomplish – take a look a the hooks that MSM offers for extending M6 processing – they will probably let you do what you want and MSM already will take care of the synchronization needed when calling from the MSM m6 handing into the user scripts that you supply (this is part of the MSM M6 event hooks).
Dave