Hello Guest it is April 16, 2024, 05:13:15 PM

Author Topic: script correction  (Read 1922 times)

0 Members and 1 Guest are viewing this topic.

script correction
« on: May 09, 2018, 02:40:22 AM »
Good morning
I put these two scripts in a me error button, individually they work
someone can kindly correct
I admit my complete ignorance in VB!
thank you


Sub Main
 Begin Dialog SelectCentering 350,145,230,150,"SELEZIONA CENTRO"
   OKButton 70,120,40,14
   CancelButton 120,120,40,14
   GroupBox 30,5,170,100,"CENTRATURA",.GroupBox1
   OptionGroup .OptionGroup1
   OptionButton 46,24,150,8," CENTRO PEZZO PIENO",.OptionButton1
   OptionButton 46,40,150,8," CENTRO PEZZO INTERNO"  ,.OptionButton2
   
   
  End Dialog

  Dim Dlg1 As SelectCentering
  Button = Dialog (Dlg1)
 
  If Button = 0 Then Exit Sub
  Selected  = Dlg1.OptionGroup1

  'CENTRO pezzo pieno is selected ***************************************************
  If Selected = 0 Then '********************************************

  Rem VBScript To center probe outside diameter Metric Version
Speak (" psizionarsi CINQUE millimetri sopra il pezzo") 'Avviso Vocale
response = MsgBox ("   5 mm    SOPRA IL PEZZO")

Sleep (1000) ' pausa di 1 secondi
Speak (" CONFERMARE centro pezzo pieno") 'Avviso Vocale
Message "INIZIO CENTRO PEZZO PIENO"
Sleep (1000) ' pausa di 1 secondi
response = MsgBox ("CONFERMARE CENTRO PEZZO PIENO")
 
CurrentFeed = GetOemDRO(818) 'Get the current feedrate to return to later
CurrentAbsInc = GetOemLED(48) 'Get the current G90/G91 state
CurrentGmode = GetOemDRO(819) 'Get the current G0/G1 state
CurrentToolDiameter = GetOemDRO(1000) 'gets the current tool diameter

If GetOemLed (825) <> 0 Then 'Check to see if the probe is already grounded or faulty

    Call ProbeGrounded()
    Exit Sub

Else

    XCurrent = GetDro(0)
    YCurrent = GetDro(1)
    OutsideDiameter = GetUserDRO(1152)

    Code "G4 P1" 'Pause 1 second to give time to position probe plate
    While IsMoving ()
    Wend
    Call SetDro (0,0.000)
    While IsMoving ()
    Wend
    Call SetDro (1,0.000)
    Code "F50" 'slow feed rate to 100mm/sec
    Code "G90 G0 X" &XNew + OutsideDiameter * .6
    Code "G91 G0 Z-10"

Rem Probe Left

    XNew = Xcurrent - OutsideDiameter * .6
    Code "G31 X" &XNew
    While IsMoving() 'wait for the move to finish
    Wend
    XPos1 = GetVar(2000) 'get the probe touch location
    Code "G91 G0 X2"
    Code "G91 G0 Z10"
    Code "G90 G0 X" &XCurrent 'rapid move back to start point
    Code "G91 G0 X" &XCurrent - OutsideDiameter * .6
    Code "G91 G0 Z-10"

Rem Probe Right

    XNew = XCurrent + 75 'probe 75mm to right
    Code "G31 X" &XNew
    While IsMoving()
    Wend
    XPos2 = GetVar(2000)
    Code "G91 G0 X-2"
    Code "G91 G0 Z10"
    XCenter = (XPos1 + XPos2) / 2 'center is midway between XPos1 and XPos2
    Code "G90 G0 X" &XCenter 'rapid move to the x center location
    While IsMoving ()
    Wend
    Call SetDro (0,0.000)
    Code "G4 P0.25"
    Code "G90 G0 Y" &YNew - OutsideDiameter * .6
    Code "G91 G0 Z-10"

Rem Probe up

    YNew = YCurrent + 75
    Code "G31 Y" &YNew
    While IsMoving()
    Wend
    YPos1 = GetVar(2001)
    Code "G91 G0 Y-2"
    Code "G91 G0 Z10"
    Code "G90 G0 Y" &YCurrent
    Code "G91 G0 Y" &YCurrent + OutsideDiameter * .6
    Code "G91 G0 Z-10"

Rem Probe down

    YNew = YCurrent - 75
    Code "G31 Y" &YNew
    While IsMoving()
    Wend
    YPos2 = GetVar(2001)
    Code "G91 G0 Y2"
    Code "G91 G0 Z10"
    YCenter = (YPos1 + YPos2) / 2

Rem move To the center

    Code "G90 G0 Y" &YCenter
    While IsMoving ()
    Wend
    Call SetDro (1,0.000)
    While IsMoving ()
    Wend
    Call SetUserDro (1152,YPos2 - YPos1 - CurrentToolDiameter)

    Code "G4 P0.25"

    Code "F" &CurrentFeed 'restore starting feed rate
   Call ReturnG90G91State()
   Exit Sub
End If
 
Sub ProbeGrounded()
   Code "(Probe plate is grounded, check connection and try again)"
   Call ReturnG90G91State()
End Sub

Sub ReturnG90G91State()
   If CurrentAbsInc = 0 Then 'if G91 was in effect before then return to it
      Code "G91"
   End If
   If CurrentGMode = 0 Then 'if G0 was in effect before then return to it
      Code "G0"
   End If
   
   
End Sub 
   


 End If '*********************************************************
 
  'CENTRO PEZZO INTERNO is selected **************************************************
  If Selected = 1 Then '*******************************************
 
 
Speak ("ricerca centro pezzointerno") 'Avviso Vocale
Message "RICERCA CENTRO PEZZO INTERNO"
Sleep (1000) ' pausa di 1 secondi
response = MsgBox ("CONFERMARE RICERCA CENTRO PEZZO INTERNO")

Sleep (1000) ' pausa di 1 secondi
Speak (" CONFERMARE centro pezzo interno") 'Avviso Vocale
Message "INIZIO CENTRO PEZZO INTERNO"
Sleep (1000) ' pausa di 1 secondi
response = MsgBox ("CONFERMARE CENTRO PEZZO INTERNO")


   
   Call SetDRO(0,0)
   Call SetDRO(1,0)
   Xpos = GetParam("XDRO")
   Ypos = GetParam("YDRO")
   Fcurr = GetParam("FeedRate")
   SP = 80 ' avanzamento prima palp impostare diametro mm del cerchio da palpare
   VSP = "F200" ' velocita avanzamento prima palp
   bkSP = 3 ' ritorno dopo palp mm
   VbkSP = "F240" ' velocita ritorno
   Spp = 5 ' avanzamento seconda palp mm
   VSpp = "F40" ' velocita seconda palp
   
   Code "G31 X" & (GetParam("XDRO")+SP) & (VSP)
   While IsMoving()
   Wend
   
   Code "G0 X" & (GetParam("XDRO")-bkSP) & (VbkSP)
   While IsMoving()
   Wend
   
   Code "G31 X" & (GetParam("XDRO")+Spp) & VSpp
   While IsMoving()
   Wend
   
   B=GetParam("XDRO")
   
   Code "G0 X" & Xpos
   
   Code "G31 X" & (GetParam("XDRO")-SP) & (VSP)
   While IsMoving()
   Wend
   
   Code "G0 X" & (GetParam("XDRO")+bkSP) & (VbkSP)
   While IsMoving()
   Wend
   
   Code "G31 X" & (GetParam("XDRO")-Spp) & VSpp
   While IsMoving()
   Wend
   
   A=GetParam("XDRO")
   
   measuredX = B-A
   
   Code "G0 X" & (A+(B-A)/2)
   While IsMoving()
   Wend
   
   Code "G31 Y" & (GetParam("YDRO")+SP) & (VSP)
   While IsMoving()
   Wend
   
   Code "G0 Y" & (GetParam("YDRO")-bkSP) & (VbkSP)
   While IsMoving()
   Wend
   
   Code "G31 Y" & (GetParam("YDRO")+Spp) & VSpp
   While IsMoving()
   Wend
   
   B=GetParam("YDRO")
   
   Code "G0 Y" & Ypos
   
   Code "G31 Y" & (GetParam("YDRO")-SP) & (VSP)
   While IsMoving()
   Wend
   
   Code "G0 Y" & (GetParam("YDRO")+bkSP) & (VbkSP)
   While IsMoving()
   Wend
   
   Code "G31 Y" & (GetParam("YDRO")-Spp) & VSpp
   While IsMoving()
   Wend
   
   A=GetParam("YDRO")
   
   
   measuredY = B-A
   SetOEMDro(1152,measuredY + GetOEMDro(1000))
   
   Code "G0 Y" & (A+(B-A)/2)
   SetParam("FeedRate",Fcurr)
   
   MsgBox (" Measurement X: " & nFmt(measuredX,3) & " mm  Measurement Y: " & nFmt(measuredY,3) & " mm")


   


       

         
 

  End If '*********************************************************
   
End Sub '**********************************************************
       

         

 

Offline TPS

*
  •  2,505 2,505
    • View Profile
Re: script correction
« Reply #1 on: May 09, 2018, 02:51:45 AM »
Code: [Select]
Sub Main
 Begin Dialog SelectCentering 350,145,230,150,"SELEZIONA CENTRO"
   OKButton 70,120,40,14
   CancelButton 120,120,40,14
   GroupBox 30,5,170,100,"CENTRATURA",.GroupBox1
   OptionGroup .OptionGroup1
   OptionButton 46,24,150,8," CENTRO PEZZO PIENO",.OptionButton1
   OptionButton 46,40,150,8," CENTRO PEZZO INTERNO"  ,.OptionButton2
   
   
  End Dialog

  Dim Dlg1 As SelectCentering
  Button = Dialog (Dlg1)
 
  If Button = 0 Then Exit Sub
  Selected  = Dlg1.OptionGroup1

  'CENTRO pezzo pieno is selected ***************************************************
  If Selected = 0 Then '********************************************

  Rem VBScript To center probe outside diameter Metric Version
Speak (" psizionarsi CINQUE millimetri sopra il pezzo") 'Avviso Vocale
response = MsgBox ("   5 mm    SOPRA IL PEZZO")

Sleep (1000) ' pausa di 1 secondi
Speak (" CONFERMARE centro pezzo pieno") 'Avviso Vocale
Message "INIZIO CENTRO PEZZO PIENO"
Sleep (1000) ' pausa di 1 secondi
response = MsgBox ("CONFERMARE CENTRO PEZZO PIENO")
 
CurrentFeed = GetOemDRO(818) 'Get the current feedrate to return to later
CurrentAbsInc = GetOemLED(48) 'Get the current G90/G91 state
CurrentGmode = GetOemDRO(819) 'Get the current G0/G1 state
CurrentToolDiameter = GetOemDRO(1000) 'gets the current tool diameter

If GetOemLed (825) <> 0 Then 'Check to see if the probe is already grounded or faulty

    Call ProbeGrounded()
    Exit Sub

Else

    XCurrent = GetDro(0)
    YCurrent = GetDro(1)
    OutsideDiameter = GetUserDRO(1152)

    Code "G4 P1" 'Pause 1 second to give time to position probe plate
    While IsMoving ()
    Wend
    Call SetDro (0,0.000)
    While IsMoving ()
    Wend
    Call SetDro (1,0.000)
    Code "F50" 'slow feed rate to 100mm/sec
    Code "G90 G0 X" &XNew + OutsideDiameter * .6
    Code "G91 G0 Z-10"

Rem Probe Left

    XNew = Xcurrent - OutsideDiameter * .6
    Code "G31 X" &XNew
    While IsMoving() 'wait for the move to finish
    Wend
    XPos1 = GetVar(2000) 'get the probe touch location
    Code "G91 G0 X2"
    Code "G91 G0 Z10"
    Code "G90 G0 X" &XCurrent 'rapid move back to start point
    Code "G91 G0 X" &XCurrent - OutsideDiameter * .6
    Code "G91 G0 Z-10"

Rem Probe Right

    XNew = XCurrent + 75 'probe 75mm to right
    Code "G31 X" &XNew
    While IsMoving()
    Wend
    XPos2 = GetVar(2000)
    Code "G91 G0 X-2"
    Code "G91 G0 Z10"
    XCenter = (XPos1 + XPos2) / 2 'center is midway between XPos1 and XPos2
    Code "G90 G0 X" &XCenter 'rapid move to the x center location
    While IsMoving ()
    Wend
    Call SetDro (0,0.000)
    Code "G4 P0.25"
    Code "G90 G0 Y" &YNew - OutsideDiameter * .6
    Code "G91 G0 Z-10"

Rem Probe up

    YNew = YCurrent + 75
    Code "G31 Y" &YNew
    While IsMoving()
    Wend
    YPos1 = GetVar(2001)
    Code "G91 G0 Y-2"
    Code "G91 G0 Z10"
    Code "G90 G0 Y" &YCurrent
    Code "G91 G0 Y" &YCurrent + OutsideDiameter * .6
    Code "G91 G0 Z-10"

Rem Probe down

    YNew = YCurrent - 75
    Code "G31 Y" &YNew
    While IsMoving()
    Wend
    YPos2 = GetVar(2001)
    Code "G91 G0 Y2"
    Code "G91 G0 Z10"
    YCenter = (YPos1 + YPos2) / 2

Rem move To the center

    Code "G90 G0 Y" &YCenter
    While IsMoving ()
    Wend
    Call SetDro (1,0.000)
    While IsMoving ()
    Wend
    Call SetUserDro (1152,YPos2 - YPos1 - CurrentToolDiameter)

    Code "G4 P0.25"

    Code "F" &CurrentFeed 'restore starting feed rate
   Call ReturnG90G91State()
   Exit Sub
End If
 


 End If '*********************************************************
 
  'CENTRO PEZZO INTERNO is selected **************************************************
  If Selected = 1 Then '*******************************************
 
 
Speak ("ricerca centro pezzointerno") 'Avviso Vocale
Message "RICERCA CENTRO PEZZO INTERNO"
Sleep (1000) ' pausa di 1 secondi
response = MsgBox ("CONFERMARE RICERCA CENTRO PEZZO INTERNO")

Sleep (1000) ' pausa di 1 secondi
Speak (" CONFERMARE centro pezzo interno") 'Avviso Vocale
Message "INIZIO CENTRO PEZZO INTERNO"
Sleep (1000) ' pausa di 1 secondi
response = MsgBox ("CONFERMARE CENTRO PEZZO INTERNO")


   
   Call SetDRO(0,0)
   Call SetDRO(1,0)
   Xpos = GetParam("XDRO")
   Ypos = GetParam("YDRO")
   Fcurr = GetParam("FeedRate")
   SP = 80 ' avanzamento prima palp impostare diametro mm del cerchio da palpare
   VSP = "F200" ' velocita avanzamento prima palp
   bkSP = 3 ' ritorno dopo palp mm
   VbkSP = "F240" ' velocita ritorno
   Spp = 5 ' avanzamento seconda palp mm
   VSpp = "F40" ' velocita seconda palp
   
   Code "G31 X" & (GetParam("XDRO")+SP) & (VSP)
   While IsMoving()
   Wend
   
   Code "G0 X" & (GetParam("XDRO")-bkSP) & (VbkSP)
   While IsMoving()
   Wend
   
   Code "G31 X" & (GetParam("XDRO")+Spp) & VSpp
   While IsMoving()
   Wend
   
   B=GetParam("XDRO")
   
   Code "G0 X" & Xpos
   
   Code "G31 X" & (GetParam("XDRO")-SP) & (VSP)
   While IsMoving()
   Wend
   
   Code "G0 X" & (GetParam("XDRO")+bkSP) & (VbkSP)
   While IsMoving()
   Wend
   
   Code "G31 X" & (GetParam("XDRO")-Spp) & VSpp
   While IsMoving()
   Wend
   
   A=GetParam("XDRO")
   
   measuredX = B-A
   
   Code "G0 X" & (A+(B-A)/2)
   While IsMoving()
   Wend
   
   Code "G31 Y" & (GetParam("YDRO")+SP) & (VSP)
   While IsMoving()
   Wend
   
   Code "G0 Y" & (GetParam("YDRO")-bkSP) & (VbkSP)
   While IsMoving()
   Wend
   
   Code "G31 Y" & (GetParam("YDRO")+Spp) & VSpp
   While IsMoving()
   Wend
   
   B=GetParam("YDRO")
   
   Code "G0 Y" & Ypos
   
   Code "G31 Y" & (GetParam("YDRO")-SP) & (VSP)
   While IsMoving()
   Wend
   
   Code "G0 Y" & (GetParam("YDRO")+bkSP) & (VbkSP)
   While IsMoving()
   Wend
   
   Code "G31 Y" & (GetParam("YDRO")-Spp) & VSpp
   While IsMoving()
   Wend
   
   A=GetParam("YDRO")
   
   
   measuredY = B-A
   SetOEMDro(1152,measuredY + GetOEMDro(1000))
   
   Code "G0 Y" & (A+(B-A)/2)
   SetParam("FeedRate",Fcurr)
   
   MsgBox (" Measurement X: " & nFmt(measuredX,3) & " mm  Measurement Y: " & nFmt(measuredY,3) & " mm")


   


       

         
 

  End If '*********************************************************
   
End Sub '**********************************************************



Sub ProbeGrounded()
   Code "(Probe plate is grounded, check connection and try again)"
   Call ReturnG90G91State()
End Sub

Sub ReturnG90G91State()
   If CurrentAbsInc = 0 Then 'if G91 was in effect before then return to it
      Code "G91"
   End If
   If CurrentGMode = 0 Then 'if G0 was in effect before then return to it
      Code "G0"
   End If
   
   
End Sub 
   


anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: script correction
« Reply #2 on: May 09, 2018, 03:32:38 AM »
TPS works well
always very available
  THANK YOU !! ;) ;)