Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started by: maxsteak on November 10, 2011, 11:01:10 AM
-
Hello there,
Based on a simple g-code program, I try to transfer it on vb to improve and make a more complex algorithm. However, when running the simple code below, I cannot see the wait time between down/up unless I put >2seconds.
What's wrong in my code?
Global Const nT_Wid = 3
Global Const Dpitch = 10.0
Sub Main()
Dim i As Integer
Code "G17 G21 G91 G64 G40"
For i = 1 To nT_Wid
Touch
Code "G0 X" & Dpitch
Next i
End Sub
Sub Touch
Code "G1 F1000" Z5"
Sleep(1000)
Code "G0 Z5"
End Sub
-
IF you are going to mix Gcode and CB I would suggest using while Ismoving() to insure the code stays in sync.
Global Const nT_Wid = 3
Global Const Dpitch = 10.0
Sub Main()
Dim i As Integer
Code "G17 G21 G91 G64 G40"
While Ismoving()
Wend
For i = 1 To nT_Wid
Touch
Code "G0 X" & Dpitch
While Ismoving()
Wend
Next i
End Sub
Sub Touch
Code "G1 F1000" Z5"
While Ismoving()
Sleep(1000)
Wend
Code "G0 Z5"
While Ismoving()
Wend
End Sub
(;-) TP
-
Thank you, the ismoving is making the trick.
However, I compare my g-code and vb similar code and see the program is slower in vb than g-code. Is it normal due to additional steps?
-
You have a 1 second delay in your sub. Try removing the Sleep(1000)
-
I have removed the sleep and compare exactly the same steps, but the total program takes more time on vb than g-code.
-
SURE it will be slower in CB than in straight Gcode. LOOK at all the wait states require to make it stable(;-)
I would be using "this" code as a SUB routine in gcode. BUT beware there are dragons ( as Stirling would say) in SUB code as well (;-).
(;-) TP
-
Ok, I will hunt the dragon.
Thank you for the answers.