Sinkyster:
1) See code below. Much easier to decipher when it has comments!
2) Also see code below!
3) In machscreen click the button and change it's function from Cycle Start to the Execute VBScript function. Paste in the code and change it to fit your needs. The code is now embedded into the CycleStart button.
Enjoy!
**********CODE**********
Option Explicit 'Require variables to be defined by DIM before using. Reduces typing mistakes and headaches dramatically.
Const CR = 13 'Carriage Return
Const LF = 10 'Line Feed
'message box constants
Const msgboxBtnOK = 0
Const msgboxBtnOkCancel = 1
Const msgboxBtnAbortRetryIgnore = 2
Const msgboxBtnYesNoCancel = 3
Const msgboxBtnYesNo = 4
Const msgboxBtnRetryCancel = 5
Const msgboxIconStop = 16
Const msgboxIconQuestion = 32
Const msgboxIconExclamation = 48
Const msgboxIconInformation = 64
Const msgboxDefaultbtnFirst = 0
Const msgboxDefaultbtnSecond = 256
Const msgboxDefaultbtnThird = 512
Const msgboxDefaultbtnFourth = 768
Const msgboxApplicationModal = 0
Const msgboxSystemModal = 4096
'mach3 OEM button constants
Const btnCycleStart = 1000
Const btnFeedHold = 1001
Const btnRewind = 1002
Const btnStop = 1003
'user defined interfaces
Const ConfirmedLED = 1001 'change to your LED number
Const CountdownDRO = 1056
Sub Main
Dim TimerStart, TimerNow As Long
Dim Confirmed As Boolean
Dim NewLine, Message, Title As String 'variables for msgbox
Dim Answer As Integer
Dim TimeElapsed, TimeRemaining, Timeout As Integer
NewLine = Chr(CR) & Chr(LF) '<CR><LF>
Timeout = 25 'set confirmation timout time in seconds
SetUserLED(ConfirmedLED, 0) 'reset LED to off state
DoOEMButton(btnCycleStart) 'initiate cycle start
TimerStart = Timer 'set starting timer. Timer is elapsed seconds since midnight.
'loop through this block until we get confirmation or timeout
Do
Confirmed = CBool(GetUserLED(ConfirmedLED)) 'Retrieve LED status and convert to boolean
Sleep(250) 'check about 4 times per second to reduce CPU load
TimerNow = Timer 'set current timer value
TimeElapsed = TimerNow - TimerStart 'calculations have been broken down into small steps to
TimeRemaining = Timeout - TimeElapsed 'make it easy to follow
SetUserDRO(CountdownDRO, TimeRemaining) 'display countdown
Loop While Not Confirmed And TimeRemaining > 0
'If we didn't get confirmation in time then do the following
If Not Confirmed Then
'set variables for message box
Message = "Operator failed to confirm ignition." & NewLine & NewLine & "Operation Aborted!"
Title = "Error"
'display message box. Answer will be the position of the button that was clicked (ie 1 for first button, 2 for second.)
Answer = MsgBox(Message, msgboxBtnOK + msgboxIconStop, Title)
'perform shutdown operations.
DoOEMButton(btnFeedhold) 'Feedhold to stop machine nicely
Sleep(500) 'Wait for half second to ensure we came to a smooth stop. Reduce if it's too much.
DoOEMButton(btnStop) 'Full Stop.
DoOEMButton(btnRewind) 'Rewind code ready to retry
'Add anything else you need to do (like maybe torch off, LP off, etc)
Exit Sub 'Exit script
End If
'add anything you want to do if we do get confirmation before timeout
End Sub
**********CODE**********