Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: Apfel23 on November 29, 2023, 12:19:55 PM

Title: JogOn and JogOff in Macros
Post by: Apfel23 on November 29, 2023, 12:19:55 PM
Dear All,
I am new to use Mach3 and I am using this in a completly diffrent way with an entirely diffrent purpose. It's going to controll a very precise pick&place unit. For this I will have to teach positions. All this will run on a Windows 11 Platform  and is programed in  C#. I require two very simple Macros. I called them M910 and M911. M910 is used to start jogging the X Axis in positive direction. It is the single comand JogOn(0,0) , M911 is JogOff(0). Both are working fine in the VB Script Editior, but as soon as I call the Macros as an MDI, nothing happens. Do you have an idea what is going wrong or what I need to do to get this working. Thank you in advance and best regards from a snowy Germany
Title: Re: JogOn and JogOff in Macros
Post by: TPS on November 29, 2023, 01:22:54 PM
only idea i have is that your M910 and M911 are not in the right folder?
folder should be in

C:\Mach3\Macros\Your profile name

and they should have the extibsion .M1S
Title: Re: JogOn and JogOff in Macros
Post by: Apfel23 on November 29, 2023, 01:35:56 PM
Hello  TPS,
Name and extension is correct and file is in the correct folder, because, if I add a message("Jogging X") to the Macro, the message is propperly displayed.
Title: Re: JogOn and JogOff in Macros
Post by: Graham Waterworth on November 29, 2023, 06:38:06 PM
You may need a short delay after the M code

M910
While IsMoving
  sleep(25)
Wend
Title: Re: JogOn and JogOff in Macros
Post by: Apfel23 on November 30, 2023, 03:56:58 AM
Hello Graham,

Hello Graham,

thank you for your response, but...
This is how my macro is looking now:

i = 0
JogOn(1,0) 
While IsMoving
  sleep(25)
  i = i + 1
Wend
Message "Macro done " & i

This time I gave y-Axis a try.
I set Jog-Mode to step
If I run M910 from MDI, Status is Macro done 0, Axis is not moving
If I run the code in the Editor without breakpoints, Status is Macro is done 0, but Axis is moving 1 Step as defined. Jogon is working, while IsMoving appears to be ignored
if I run the code in the Editor with a Breakpoint at JogOn and step through the code, everything is working as expected, Status is Macro done 16.
Isn't this funny?  8{
Doing the same in continous jog mode:
If I run M910 from MDI, Status is Macro done 0, Axis is not moving
If I run the code in the Editor without breakpoints, Status is Macro is done 0, but Axis is moving endless. Jogon is working, while IsMoving appears to be ignored
if I run the code in the Editor with a Breakpoint at JogOn and step through the code, everything is working as expected, writing the status is never reached, as expected (jog is running continously).

Nobody out there, who has a board connected and can simulate this? Not even a stepperdriver needs to be attached.

Thank you all
Title: Re: JogOn and JogOff in Macros
Post by: TPS on November 30, 2023, 06:32:25 AM
tested this code over here, also used M900.M1s

Code: [Select]
Code "F1000"
 JogOn(0,0)

in MPG Step mode, however i had to set a speed first, then is was working.
Title: Re: JogOn and JogOff in Macros
Post by: Apfel23 on November 30, 2023, 09:29:30 AM
Hello TPS,

are you having a MPG Unit connected? And is it working when you are calling the Macro from MDI or inside a G-Code File?
In my case it is working only in the Editor Window, I do not have a MPG connected. Might this be the reason? Strange...

Best regards

Title: Re: JogOn and JogOff in Macros
Post by: TPS on November 30, 2023, 10:15:10 AM
i have no physical mpg connected.
i created a macro in my macro folder and run it via MDI and it was working.

i tested with Version R3.043.022
Title: Re: JogOn and JogOff in Macros
Post by: Apfel23 on November 30, 2023, 11:42:40 AM
I am using the .62 in Demo Mode. What are your settings? if I am running in MPG-Mode it is not working at all. Sorry for bothering you with this BS
Title: Re: JogOn and JogOff in Macros
Post by: TPS on November 30, 2023, 02:02:05 PM
for the test i use the "virtual" MPG from 1024 screenset by pressing the TAB key.

then i switch the Jog Mode to Step
choose Mode Single Step
select Cycle Jog Step with the button for example 1.0
then call M900 in MDI and it moves 1.0 mm in my case.
Title: Re: JogOn and JogOff in Macros
Post by: Apfel23 on December 01, 2023, 03:36:15 AM
Thank you very much for your support, but it is not working in my case. I will have to find another solution for my application. On first sight it appeared to be very easy using jogon and jogoff, but reality is diffrent..
Title: Re: JogOn and JogOff in Macros
Post by: TPS on December 01, 2023, 05:43:24 AM
so what are you realy trying to do? maybe there is an other way for it.
Title: Re: JogOn and JogOff in Macros
Post by: Apfel23 on December 01, 2023, 06:24:39 AM
It is a very simple task. As I wrote it has nothing to do with a Mills, Lathes etc. The Mach3 is going to run in a minimzed Window, no commands will be entered directly into the Mach3 SW. My UI, Control System, Vision System and Motion System is written in C# using MS VS. At one point, I need to teach setpoints for the stepper motors (4 of them). They are used for a timing belt driven loading system. The accuracy of this system has to be better than 0.1mm. In the past I used motion controllers which are unfortunately not available anymore. This lead me to use Mach3 with a CL stepper driver running in 12800steps/rev microstep-mode. So far, so easy. Now, for teaching the positions, I am using standard buttons on a screen. Actually the mousedown event is used to send a G1 code to mach3 which will start a move to the max possible position. If the button is released, the Mouse_Up event is used to send a Stop using OEMButton 1003. This is working, but there is always a delay until the motor stopps. It is not the ramp down of the movement profile. Therefor I thought the JogOn/Off would be a better way to do this.
Title: Re: JogOn and JogOff in Macros
Post by: TPS on December 01, 2023, 06:40:55 AM
what is the interface between your vision system and Mach3?

why cant you send G1 to the expected position?

if you want to do small steps, like jog in step mode
you can send a "G91 G1 X1 F10" for example
Title: Re: JogOn and JogOff in Macros
Post by: Apfel23 on December 01, 2023, 07:15:27 AM
I found my solution !!!!
In C#
I added a Referenc to Mach3.exe (Reference is named Mach4.. Why? No idea

using Mach4;

in my class (Form)

        private IMach4 _mach;
        private IMyScriptObject _mInst;

and

private void GetMachInstance()
        {
            try
            {
                _mach = (IMach4)Marshal.GetActiveObject("Mach4.Document");
                _mInst = (IMyScriptObject)_mach.GetScriptDispatch();
                Status_label.Text = "Mach3 Instance found";
            }
            catch
            {
                _mach = null;
                _mInst = null;
                Status_label.Text = "No Mach3 Instance found";
            }
        }

now, the _mInst object can be used foralmost everything.

_mInst.JogOn(0,0)    IS WORKING
_mInst_JogOff(0)      IS WORKING TOO

I only need to figure out, how to set Jog Speed. F comand is not working..

If you are intrested in this, I can send you my C# test-project
Title: Re: JogOn and JogOff in Macros
Post by: TPS on December 01, 2023, 09:02:11 AM
great!

with OEMDro(3) you should be able to set the slow jog speed in %, i think.
Title: Re: JogOn and JogOff in Macros
Post by: Apfel23 on December 02, 2023, 06:12:00 AM
Yes, that is what I am using. Working fine. Do you know, if there is a way to jog multiple axis at the same time? I would need X&Y and Z&A
Title: Re: JogOn and JogOff in Macros
Post by: TPS on December 02, 2023, 07:13:26 AM
here:

https://www.cnczone.com/forums/attachments/5/2/5/2/6/61017.attach

i found some time ago a document for OEM Buttons

352-355 do other axis combination's but never found something for X&Y or Z&A sorry.

maybe you can do a brain witch jog's two axis via a UserLED you can write, never tryed it.
Title: Re: JogOn and JogOff in Macros
Post by: TPS on December 02, 2023, 07:27:01 AM
here is a brain where i played arround a bit