Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: noeltam75 on January 21, 2013, 01:45:08 AM

Title: Code "gcode" running in VB but not running in sequence
Post by: noeltam75 on January 21, 2013, 01:45:08 AM
This is my first post, trying to learn vbscript from scratch.
I ran a simple gcode below:
S20 M3
G1 Z20
M5
M30
And my machine runs as written correctly in sequence: first turn on spindle, move Z, once Z reached 20mm, stop spindle.
However, I tried running this on Option->VB Scripter Window, with slight modification as such:
code "S20 M3"
code "G1 Z20"
code "M5"
code "M30"
My machine does this: move Z, once Z reached 20mm, turn on spindle, 1 sec later, spindle stopped.

How can I run this simple gcode in sequence?
In case you ask me why vb marco, because I will be needing to add some conditional features like IF ELSE THEN WHILE etc, building from this as a start.
Hoped to get some help please.
Title: Re: Code "gcode" running in VB but not running in sequence
Post by: noeltam75 on January 21, 2013, 08:54:52 PM
Anyone? Pls help me to understand this.
Title: Re: Code "gcode" running in VB but not running in sequence
Post by: noeltam75 on January 21, 2013, 09:37:20 PM
somemore new findings.
I saved the same codes and named it "M8888.m1s"
Then I ran it at MDI tab at the "INPUT", I typed M8888.
Behold!! It ran in sequence.
So conclusion, it only time that it doesn't run in sequeue is when I click on the "run script" button at the VB Scripter Window.
Strange behaviour.
Anyone?
Title: Re: Code "gcode" running in VB but not running in sequence
Post by: ger21 on January 21, 2013, 10:26:33 PM
If you want everything to run in sequence, the script needs to wait for each move to finish before executing the next one.
To do that, you need to add While IsMoving() statements.

code "S20 M3"
While IsMoving()
Wend
code "G1 Z20"
While IsMoving()
Wend
code "M5"
While IsMoving()
Wend
code "M30"
While IsMoving()
Wend
Title: Re: Code "gcode" running in VB but not running in sequence
Post by: noeltam75 on January 22, 2013, 02:13:43 AM
This forum is great.
Thanks ger21!!
Your code works!
Thread closed.
Title: Re: Code "gcode" running in VB but not running in sequence
Post by: BR549 on January 22, 2013, 11:35:00 AM
I have found that you can run groups of code together then add in the wait at the right points.  IF you have a group of Gcode then nee to issue a M5 you would do it like this,


code "S20 M3"
code"G1 X1 F20"
code"X1Y1"
code"X0Y1"
code"X0Y0"
code "G1 Z20"       'end of large group of Gcode motions
While Ismoving()
Wend
code "M5"
code "M30"