Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started by: sinkyster on June 30, 2011, 02:09:46 AM
-
Hi all,
I am setting up Mach3 to run with a Oxy Fuel process. I have searched everywhere but can't seem to find any info.
I want to put a simple safety feature in place that cuts off the gas supply if auto ignition haven't been confirmed by the operator within a certain time frame. Since I don't know too much about VB it is a bit difficult... I have read through a lot of posts but I still can't get something. The basic process would be something like this:
Timer countdown 25s (a visible counter would be best)
If "operator have confirmed ignition before " then "resume cycle"
else
STOP
or maybe on different approach:
Timer countdown 25s (a visible counter would be best)
if counter = 0 and confirm = 0 then stop
if counter >= 0 and confirm = 1 then Resume
Any help would be much appreciated.... I've spend many hours trying to work it out but to no avail.
Sinkyster
-
A very simple start would be this: Not knowing the method you use to turn on the torch it is a start. It simply counts down and sendstheount to the message bar.
'Countdown timer for AutoTorch light
'(turn on torch)
Message "26"
Sleep(1000)
Message "25"
Sleep(1000)
Message "24"
Sleep(1000)
Message "23"
Sleep(1000)
Message "22"
Sleep(1000)
Message "21"
Sleep(1000)
Message "20"
Sleep(1000)
Message "19"
Sleep(1000)
Message "18"
Sleep(1000)
Message "17"
Sleep(1000)
Message "16"
Sleep(1000)
Message "15"
Sleep(1000)
Message "14"
Sleep(1000)
Message "13"
Sleep(1000)
Message "12"
Sleep(1000)
Message "11"
Sleep(1000)
Message "18"
Sleep(1000)
Message "17"
Sleep(1000)
Message "16"
Sleep(1000)
Message "15"
Sleep(1000)
Message "14"
Sleep(1000)
Message "13"
Sleep(1000)
Message "12"
Sleep(1000)
Message "11"
Sleep(1000)
Message "10"
Sleep(1000)
Message "9"
Sleep(1000)
Message "8"
Sleep(1000)
Message "7"
Sleep(1000)
Message "6"
Sleep(1000)
Message "5"
Sleep(1000)
Message "4"
Sleep(1000)
Message "3"
Sleep(1000)
Message "2"
Sleep(1000)
Message "1"
Sleep(1000)
Message "0"
Sleep(1000)
'(IF signal yes then end)
'(ELSE Shut off torch)
'(END IF)
LET US KNOW if you need further help, (;-)TP
-
We need a little bit more information. When does the ignition need to be confirmed: at the beginning of a cycle, and/or periodically throughout the cycle?
Would a messagebox asking for confirmation be appropriate in your situation? How should the confirmation be initiated, do you want it executed from a macro called from the GCode (ie M1001)? Or would it be safer/more desirable to have it run every time you click cycle start so it is executed every time no matter what?
Any other considerations.
Once this info has been provided a suitable solution for your circumstances can be given!
I could just throw out a few possible answers/scripts, but it sounds like you've had enough pain on this one! Let's just get it right the first time.
A dialog must be used to give you control while the box is displayed so you can close the box when the countdown reaches 0 and decrement the counter every second. We'll get something put together for you pretty quickly I think.
Thanks,
Chris
-
OK. My idea is to start the cycle. Then torch moves to start coordinates, and start the ignition process. The ignition process will first open the LP gas and then the timer must start. Right after it has started i want to start the auto ignition. But as it happens, it doesn't always start and i want to manually confirm that the torch is on. Then when it comes on, it stays on for the whole cycle. I want to ignite only at the beginning of each job.
The steps must be something like this:
Torch on
Timer on
Igniter on
The Operator must confirm [torch OK] before the timer hits 0 or the machine will go to STOP or RESET state. And if the Operator did confirm, the G-Code must continue...
I would prefer a macro being called for that, yes! See image for how I pictured it to be in mach3.
Just a BTN with Yellow LED flashing(while not confirmed) and green LED that comes on when confirmed. At the btm is the counter in a DRO.
Maybe a MSG popup only when operator did not confirm? That way thay i can leave a small message to tel the operator what he did wrong...
I think it can't be too difficult, I just don't know how exactly.. :)
Thanks for you replies!
-
...here is the image ;)
-
Heres the script to replace the cycle start button!
Note that cycle start can also be run from other screens, so you might want to direct them to this script as well.
********** CODE **********
Const CR = 13
Const LF = 10
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
Const btnCycleStart = 1000
Const ConfirmedLED = 1001 'change to your LED number
Sub Main
Dim TimerStart, TimerNow As Long
Dim Confirmed As Boolean
Dim NewLine, Message, Title As String
Dim Answer As Integer
Dim Timeout As Integer
NewLine = Chr(13) & Chr(10)
Timeout = 25 'set timout time in seconds
SetUserLED(ConfirmedLED, 0)
DoOEMButton(btnCycleStart)
TimerStart = Timer
Do
Confirmed = CBool(GetUserLED(ConfirmedLED))
Sleep(250) 'check about 4 times per second to reduce CPU load
TimerNow = Timer
Loop While Not Confirmed And TimerNow - TimerStart < Timeout
If Not Confirmed Then
Message = "Operator failed to confirm ignition." & NewLine & NewLine & "Operation Aborted!"
Title = "Error"
Answer = MsgBox(Message, msgboxBtnOK + msgboxIconStop, Title)
End If
End Sub
********** CODE **********
-
I didn't put in the countdown, but you can output TimerNow - TimerStart to a DRO or UserLabel.
Also at the end of the If Not Confirmed block you should add a command to stop or feedhold or other applicable actions if you don't get confirmation.
If you need more information or you want some clarification on the code let me know. I didn't have much time when I did it so it's not commented very well.
Chris
-
Thnx Chris, I'll take a look today! ;)
-
Sargon,
Maybe it's better if you could clarify it... I'm still learning... :)
apart from that, i have 3 qstns:
1. how would the code for the countdown look like? Something like this?
timeleft = Timernow - Timerstart
setUSERDRO(1056, timeleft) ? '1056 is my userDRO ID
2. Where should that code be put in?
3. You say I need to replace the cycle start button script. I use Machscreen for editing, can I just change the cycle start button with all these script in there?
Cheers!
-
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**********
-
Thanx for all the help. I'm almost finished with it. Only one thing didn't work... I can't get the DRO to show the actual time being counted down (25 to 0)
I'll just keep on to battle with it, and when I have a bit more time I'm sure I will get it working! ;)
THNX!
-
Can you confirm that you are able to change it with the script at all? E.g. Change it once with the script to a different value and confirm that it does change.
Chris
-
Yes, I can change it. I currently have it at 10s for testing purposes.
C
-
Try this little bit of code. It should count up on the A axis from 0 to 10. This works here, could you please try it?
Dim tstart As Long
Dim elapsed As Integer
tstart = Timer
Do
elapsed = Timer - tstart
SetOEMDRO(803, elapsed)
Sleep(250)
Loop While elapsed < 10
If this works but you can't get your script to work, please post your code. Must be something minor.