Macropump for Galesburg Mill
From MachCustomizeWiki
Option Explicit
' Macropump for demo panel and Mill Const slave = 1 ' **** Change this if you use another ModBus Slave address Dim swT1 as Boolean ' toggle 1 true is Down Dim swT2 as Boolean ' toggle 2 true is down Dim swR1 as Integer ' Rotary 1 three positions 1, 2 and 3 Dim swR2 as Integer ' Rotary 2 four positions 1, 2, 3 and 4 Dim CurrScreen as Integer Const scrProgRun = 1 Const scrOffsets = 7 Const scrMDI = 2 Const scrDiags = 5 Const FeedHolding = 1244 ' LED shows Had one red button press Const OUTBASE = OUTPUT7 - 1 ' ============================================================= Sub Main () Preamble GetConsistent DecodeSwitches ActionSwitches ReadButtons SetFRO WriteDisplays End Sub 'Main '================================================================= ' Action functions to implement changes ' ================================================================ Sub ButtonDown (nButt as Integer) ' Called when a button is pressed. nButt says which If nButt = 1 Then ' Green buttons If CurrScreen = scrProgRun OR CurrScreen = scrDiags Then DoButton 0 ' Cycle Start **** 033 ElseIf CurrScreen = scrMDI Then ' we are going to deal with the spindle If GetOEMLED (11)= 0 Then ' Spindle is stopped Code "M3" End If End If ' different screen actions End If ' Button 0 If nButt = 3 Then ' Red button If CurrScreen = scrProgRun OR CurrScreen = scrDiags Then If GetUserLED (FeedHolding) Then SetUserLED FeedHolding, 0 ' now in stop state DeActivateSignal (OUTBASE + 3) DoButton 3 ' **** 033 Else If GetLed (4) Then ' its running SetUserLED Feedholding, 1 ' now in Hold state ActivateSignal (OUTBASE + 3) DoButton 1 ' **** 033 End If ' was running End If ' whatever state we were in ElseIf CurrScreen = scrMDI Then ' we are going to deal with the spindle If GetOEMLED (11)<>0 Then ' Spindle is running Code "M5" End If End If ' different screen actions End If ' Button 3 End Sub 'ButtonDown ' ------------------------------------------------------------------ Sub ButtonUp (nButt as Integer) ' Called when a button is released. nButt says which ' Probably not much use but here in case End Sub 'ButtonUp '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Sub swT1ChangedTo (ison as Boolean) ' Toggle switch 1 changed Message "Toggle 1 changed" End Sub ' swUpdated '----------------------------------------------------------------------- Sub swT2ChangedTo (ison as Boolean) ' Toggle swich 2 changed If GetOEMLED (106) <> 0 AND ison = 0 Then ' need to toggle DoOEMButton (284) ' toggle Shuttle End If If GetOEMLED (106) = 0 AND ison <> 0 Then ' need to toggle DoOEMButton (284) ' toggle Shuttle End If End Sub ' swUpdated '----------------------------------------------------------------------- Sub swR1ChangedTo (posn as Integer) ' Rotary 1 changed Message "Tool number " & posn SetDRO 24, posn End Sub ' swUpdated '----------------------------------------------------------------------- Sub swR2ChangedTo (posn as Integer) ' Rotary 2 changed To set Axis to Jog Dim iCount as Integer If GetOEMLed (97 + posn) = 0 Then ' not on the right axis For iCount = 1 to 6 ' 6 times bound to be enough if it is ever going to happen If GetOEMLED (97 + posn) = 0 Then DoOEMButton 281 ' toggle the button until it comes good End If Next iCount End If ' now a bodge as MPG1 axis gets changed out of the blue needs to be C to disable If GetOEMLed (64) = 0 Then ' not on the C axis For iCount = 1 to 6 ' 6 times bound to be enough if it is ever going to happen If GetOEMLED (64) = 0 Then DoOEMButton 175 ' toggle the button until it comes good End If Next iCount End If End Sub ' swUpdated ' ===================================================================== Sub Preamble () ' Do the interesting things to setup data here CurrScreen = GetPage () End Sub ' Preamble ' ------------------------------------------------------------------- Sub GetConsistent () ' Here we see if user has done anthing funng (e.g. with screen buttons) ' that invalidates the state we think we are in. End Sub ' GetConsistent '---------------------------------------------------------------------- Sub WriteDisplays () ' Here we write to the LCD and real LEDs reflecting the state things are in Dim strText as String Dim strLabB1 as String ' label for button 1 Dim strLabB2 as String ' label for button 2 Dim strLabB3 as String ' label for button 3 strLabB2 = " " ' not currently used If GetOEMLED (106) Then ' Shuttle is ON ActivateSignal OUTBASE + 5 Else DeActivateSignal OUTBASE + 5 End If ' displaying the Shuttle State If GetLED (6) Then ' Tool change request ActivateSignal OUTBASE + 1 ActivateSignal OUTBASE + 4 ' flash LEDs 1 and 4 Else DeActivateSignal OUTBASE + 1 DeActivateSignal OUTBASE + 4 End If ' displaying the Tool Change LED Select Case CurrScreen ' put out the heading line Case = scrProgRun strText = " Program Run " strLabB1 = "Run " If GetLed (4) <> 0 Then ' its running so we might pause strLabB3 = "Hold" ElseIf GetLED (6) Then ' Toolchange request strLabB1 = "Tool" strLabB3 = " " Else If GetOEMLed (11) <> 0 Then ' spindle is running so we must be paused strLabB3 = "Stop" Else strLabB3 = " " End If End If ' dealing with the button 3 label If GetLed (5) = 0 Then ' we are not paused DeActivateSignal (OUTBASE + 3) ' don't flash the LED Else ActivateSignal (OUTBASE + 3) ' flash the LED 3 End If Case = scrOffsets strText = " Offsets " strLabB1 = " " strLabB3 = " " Case = scrMDI strText = " MDI " strLabB1 = "Spin" strLabB3 = "Stop" Case = scrDiags strText = " Diagnostics " StrLabB1 = "Run " Case Else strText = " " 'unknown screen End Select strText = strText & " " strText = strText & " " strText = strText + strLabB1 & " " & strLabB2 & " " & strLabB3 _ & " " & strLabB1 SetModIOString slave, 0, 0, strText ' write it End Sub ' Write displays '--------------------------------------------------------------------------- Sub ReadButtons () ' Looks at the inputs for transitions and calls the ButtonDown routine if Transition Rem could be a loop but I hope this code is clearer If IsActive (INPUT1) Then If GetUserLED (1241) = 0 Then ' It is a new press SetUserLED 1241, 1 ButtonDown 1 End if ' dealing with new press Else ' button is up If GetUserLED (1241) <> 0 Then ' It is new unpress SetUserLED 1241, 0 ButtonUp 1 End if ' dealing with new press End IF ' button 1 processing If IsActive (INPUT2) Then If GetUserLED (1242) = 0 Then ' It is a new press SetUserLED 1242, 1 ButtonDown 2 End if ' dealing with new press Else ' button is up If GetUserLED (1242) <> 0 Then ' It is new unpress SetUserLED 1242, 0 ButtonUp 2 End if ' dealing with new press End IF ' button 2 processing If IsActive (INPUT3) Then If GetUserLED (1243) = 0 Then ' It is a new press SetUserLED 1243, 1 ButtonDown 3 End if ' dealing with new press Else ' button is up If GetUserLED (1243) <> 0 Then ' It is new unpress SetUserLED 1243, 0 ButtonUp 3 End if ' dealing with new press End IF ' button 3 processing End Sub ' ReadButtons '----------------------------------------------------------------- Sub SetFRO () ' Does simple analog read and straight to DRO Dim fro as Integer fro = GetInput (64) ' read Analog1 setUserDRO 1253, fro fro = (fro * 95.0)/1024.0 setDRO 21, fro+5 ' range is now 5 to 100% End Sub ' SetFRO ' ---------------------------------------------------------------------- Sub DecodeSwitches () ' This routine takes the analog ports and sets up the switch states from them Dim ana as Integer ana = GetInput(65) 'analog Input 2 On ModIO Select Case ana Case < 100 swT1 = True swR1 = 1 Case < 340 swT1 = True swR1 = 2 Case < 510 swT1 = True swR1 = 3 Case < 690 swT1 = False swR1 = 1 Case < 910 swT1 = False swR1 = 2 Case >= 910 swT1 = False swR1 = 3 End Select ana = GetInput(66) 'analog Input 3 On ModIO Select Case ana Case < 68 swT2 = True swR2 = 1 Case < 212 swT2 = True swR2 = 2 Case < 340 swT2 = True swR2 = 3 Case < 511 swT2 = True swR2 = 4 Case < 684 swT2 = False swR2 = 1 Case < 819 swT2 = False swR2 = 2 Case < 954 swT2 = False swR2 = 3 Case >= 954 swT2 = False swR2 = 4 End Select End Sub ' DecodeSwitches ' ------------------------------------------------------------------------- Sub ActionSwitches () ' This routine displays switch states on Diags page and ' calls the Action routines if they have been changed If GetUserLED (1251) = 0 Then ' previously T1 was OFF If swT1 Then SetUserLED 1251, 1 swT1ChangedTo TRUE End If Else ' T1 was ON If swT1 = 0 Then SetUserLED 1251, 0 swT1ChangedTo FALSE End If End If If GetUserDRO (1251) <> swR1 Then ' change in rotary 1 position SetUserDRO 1251, swR1 swR1ChangedTo swR1 End If If GetUserLED (1252) = 0 Then ' previously T2 was OFF If swT2 Then SetUserLED 1252, 1 swT2ChangedTo TRUE End If Else ' T2 was ON If swT2 = 0 Then SetUserLED 1252, 0 swT2ChangedTo FALSE End If End If If GetUserDRO (1252) <> swR2 Then ' change in rotary 2 position SetUserDRO 1252, swR2 swR2ChangedTo swR2 End If End Sub ' ActionSwitches ' ---------------------------------------------------------------

