Hello Guest it is April 19, 2024, 01:23:15 AM

Author Topic: Macro not working if called with M code  (Read 4539 times)

0 Members and 1 Guest are viewing this topic.

Macro not working if called with M code
« on: June 25, 2015, 04:26:20 AM »
Hello,

I have tested some VB macro with VB Script Editor and is all OK.
I have saved the macro on my profile with extension m1s ( M901.m1s , M902.m1s ....... )
When I execute the macro from the VB Script Editor the macro is executed correctly.

When I call from Gcode with M901 command ( or M902 ) the macro don't work ...... and I need to press the RESET button to stop because the machine is like freezed.

What can be the problem ?

Thank you for help
RedBlob

Offline TPS

*
  •  2,505 2,505
    • View Profile
Re: Macro not working if called with M code
« Reply #1 on: June 25, 2015, 05:26:34 AM »
Hi,

let us see your macros.

Thomas
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: Macro not working if called with M code
« Reply #2 on: June 25, 2015, 05:34:46 AM »
The macro is this .... in the VB Editor it work without problem.




  SoftLimitsOff
 
  DoOEMButton(204) 

  Xaxis = 0
  Yaxis = 1
  Zaxis = 2
  Plus = 0
  Minus = 1
 
  SetOEMDRO(3,10)
 

  If GetCsmioIn(6) = False Then JogOn(Zaxis,Plus)
 
  Do
 
    If GetCsmioIn(6) = True Then Exit Do
 
  Loop
   
  JogOff(Zaxis) 
 
  Sleep(1000)

 
  If GetCsmioIn(6) = True Then JogOn(Zaxis,Minus)
 
  Do
 
    If GetCsmioIn(6) = False Then Exit Do
 
  Loop
   
  JogOff(Zaxis) 
 
  Sleep(2000)
   
 
  DoOEMButton(141)
 

  Sleep(2000)
 
 
  Code("G01 Z-10 F1000")
  Sleep(2000)

 
 
 
     
   
   
   






'************************************************************************
'*                         SUBs & FUNCTIONs
'************************************************************************

Sub SoftLimitsOff ()
   If(GetOEMLED(23)) Then
      DoOEMButton(1029)
   End If
End Sub
' -----------------------------------------------------------------------------
Sub SetSoftLimits (state As Boolean)
   If(state) Then
      If(GetOEMLED(23) = 0) Then
         DoOEMButton(1029)
      End If
   Else
      If(GetOEMLED(23)) Then
         DoOEMButton(1029)
      End If
   End If
End Sub
' -----------------------------------------------------------------------------
Sub WaitForMove ()
   While IsMoving()
      Sleep(15)
   Wend
End Sub
' -----------------------------------------------------------------------------
Public Function GetCsmioIn (n As Integer) As Boolean
   Dim reg As Integer
   
   If(n < 16) Then
      reg = 90
   Else
      reg = 91
      n = n - 16
   End If
   
   If(GetInBit(reg, n)) Then
      GetCsmioIn = true
   Else
      GetCsmioIn = false
   End If
   Exit Function
End Function
' -----------------------------------------------------------------------------
Public Sub SetCsmioOut (ByVal n As Integer, ByVal state As Boolean)
   If(state) Then
      SetOutBit(90, n)
   Else
      ResetOutBit(90, n)
   End If
End Sub
' -----------------------------------------------------------------------------         

Offline TPS

*
  •  2,505 2,505
    • View Profile
Re: Macro not working if called with M code
« Reply #3 on: June 25, 2015, 06:40:08 AM »
Hi,

modified yiur code a little bit. Hopefuly i can test tonight on my CSMIO machine.

Thomas

Sub Main()

  SoftLimitsOff
 
  DoOEMButton(204) 

  Xaxis = 0
  Yaxis = 1
  Zaxis = 2
  Plus = 0
  Minus = 1
 
  SetOEMDRO(3,10)
 

  If GetCsmioIn(6) = False Then
    JogOn(Zaxis,Plus)
  End If
 
  Do
 
    If GetCsmioIn(6) = True Then
      Exit Do
    End If
   
  Loop
   
  JogOff(Zaxis) 
 
  Sleep(1000)

 
  If GetCsmioIn(6) = True Then
     JogOn(Zaxis,Minus)
  End If
 
  Do
 
    If GetCsmioIn(6) = False Then
       Exit Do
    End If
        
  Loop
   
  JogOff(Zaxis) 
 
  Sleep(2000)
   
 
  DoOEMButton(141)
 

  Sleep(2000)
 
 
  Code("G01 Z-10 F1000")
  Sleep(2000)

End Sub

anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.

Offline TPS

*
  •  2,505 2,505
    • View Profile
Re: Macro not working if called with M code
« Reply #4 on: June 25, 2015, 07:14:54 AM »
Hi,

by the way your code looks like a kind of homing/probing function.

why don't you use G28 or G31 (or M31 from CSMIO homepage)
for this job.

this macro solution will be imprecise anyway.

Thomas
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: Macro not working if called with M code
« Reply #5 on: June 25, 2015, 07:25:12 AM »
Double check that you're saving in the correct profile folder. I've seen many instances where users thought they were, but were actually using a different profile than they thought.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: Macro not working if called with M code
« Reply #6 on: June 25, 2015, 10:37:48 AM »
I think to have find the problem , but not the solution ......

The macro don't execute the instruction JogOn(Zaxis,Plus) .

If I disable the JogOn the script is executed correctly.

How is possible ?


Offline TPS

*
  •  2,505 2,505
    • View Profile
Re: Macro not working if called with M code
« Reply #7 on: June 25, 2015, 03:23:28 PM »
Hi,

ok again, what are you trying to do with this macro.

i still think it is a homing/probing.

Thomas

sometimes an other way is the better way.
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: Macro not working if called with M code
« Reply #8 on: June 26, 2015, 04:36:17 AM »
The macro move the axis in Jog until an external switch is pressed ( like an automatic pallet finder ).

I need to move the axis in manual Jog with a VB macro ......... I don't understand why this function is available but don't work in my application .

What is wrong ?

Offline TPS

*
  •  2,505 2,505
    • View Profile
Re: Macro not working if called with M code
« Reply #9 on: June 26, 2015, 05:40:24 AM »
Hi,

The macro move the axis in Jog until an external switch is pressed ( like an automatic pallet finder ).

I need to move the axis in manual Jog with a VB macro ......... I don't understand why this function is available but don't work in my application .

What is wrong ?



have a look for G31/M31 for this, would be perfect for this.

Thomas

anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.