Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: maxsteak on November 10, 2011, 11:01:10 AM

Title: sleep issue
Post 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   
Title: Re: sleep issue
Post by: BR549 on November 10, 2011, 05:57:36 PM
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
Title: Re: sleep issue
Post by: maxsteak on November 11, 2011, 06:23:26 AM
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?
Title: Re: sleep issue
Post by: ger21 on November 11, 2011, 08:09:42 AM
You have a 1 second delay in your sub. Try removing the Sleep(1000)
Title: Re: sleep issue
Post by: maxsteak on November 11, 2011, 08:12:10 AM
I have removed the sleep and compare exactly the same steps, but the total program takes more time on vb than g-code.
Title: Re: sleep issue
Post by: BR549 on November 11, 2011, 09:49:33 AM
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
Title: Re: sleep issue
Post by: maxsteak on November 14, 2011, 02:02:05 AM
Ok, I will hunt the dragon.

Thank you for the answers.