Home
Downloads
Mach3
Plugins
CAM Post Processors
Screensets
Purchase
Support
Forum
Tutorial Videos
Documentation
Yahoo Group
Mach Wiki
Resources
Contact Us
Links
CNCZone
German Forum
Italian Forum
Korean Forum
Portugese (Brazil) Forum
Russian Forum (RSK CNCROUTER)
Thai Forum
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
May 25, 2012, 11:04:35 AM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Select from and to languages
Chinese-simp to English
Chinese-trad to English
English to Chinese-simp
English to Chinese-trad
English to Dutch
English to French
English to German
English to Greek
English to Italian
English to Japanese
English to Korean
English to Portuguese
English to Russian
English to Spanish
Dutch to English
Dutch to French
French to English
French to German
French to Greek
French to Italian
French to Portuguese
French to Dutch
French to Spanish
German to English
German to French
Greek to English
Greek to French
Italian to English
Italian to French
Japanese to English
Korean to English
Portuguese to English
Portuguese to French
Russian to English
Spanish to English
Spanish to French
Machsupport Forum
Mach Discussion
VB and the development of wizards
escape or interrupt a VB script for toolchange m6start
Pages:
1
Go Down
« previous
next »
Author
Topic: escape or interrupt a VB script for toolchange m6start (Read 1379 times)
0 Members and 1 Guest are viewing this topic.
mecky
Active Member
Offline
Posts: 2
escape or interrupt a VB script for toolchange m6start
«
on:
November 04, 2009, 09:08:32 PM »
hey,
i have got a probably simple problem to solve in VB.
i got my m6start tool change macro to work but it appears that if i need to interrupt the tool change for whatever reason, by pressing esc., the macro continues a couple of lines down or in the second subroutine called. i am not quite sure about this.
is there any way to build an interrupt or escape loop/subroutine or something similar into a macro that is going to take care of this problem?
thanks
_mecky
here is the toolchange macro:
Sub Main()
oldtool = GetCurrentTool()
newtool = GetSelectedTool()
'newtool = 1
x = GetToolChangeStart( 0 )
y = GetToolChangeStart( 1 )
z = GetToolChangeStart( 2 )
maxtoolnum = 3
toolup = 0.0
If newtool = oldtool Then
Exit Sub
End If
While newtool > maxtoolnum
newtool = Question (" ey! there are only " & maxtoolnum)
Wend
code "G0 G53 Z" & toolup 'first operation, moving the tool up
While IsMoving()
Wend
Call ReturnTool(oldtool) 'return old tool
While IsMoving()
Wend
Call GrabTool(newtool) 'grab new tool
While IsMoving()
Wend
SetCurrentTool(newtool)
Code "G00 X" & x & "Y" & y
End Sub
Sub ReturnTool (ByVal ToolNumber As Integer)
Xclear = 141.5
toolup = 0.0
Select Case ToolNumber
Case = 1
Xpos = 144.6
Ypos = 2
Zpos = -10.68
Case = 2
Xpos = 144.6
Ypos = 4
Zpos = -10.68
Case = 3
Xpos = 144.7
Ypos = 6
Zpos = -10.64
End Select
Code "G53 G00 X" & Xclear & "Y" & YPos
While IsMoving()
Wend
Code "G53 G01 F20 Z" & Zpos
While IsMoving()
Wend
Code "G53 G01 F20 X" & Xpos
While IsMoving()
Wend
ActivateSignal(output3)
code "G04P2000"
While IsMoving()
Wend
Code "G53 G01 F20 Z" & toolup
While IsMoving()
Wend
End Sub
Sub GrabTool (ByVal ToolNumber As Integer)
Xclear = 141.5
toolup = 0.0
Select Case ToolNumber
Case = 1
Xpos = 144.6
Ypos = 2
Zpos = -10.68
Case = 2
Xpos = 144.6
Ypos = 4
Zpos = -10.68
Case = 3
Xpos = 144.7
Ypos = 6
Zpos = -10.64
End Select
Code "G53 X" & Xpos & "Y" & YPos
While IsMoving()
Wend
Code "G53 G01 F20 Z" & Zpos
While IsMoving()
Wend
code "G04P2000"
DeactivateSignal(output3)
code "G04P2000"
While IsMoving()
Wend
Code "G53 G01 F20 X" & Xclear
While IsMoving()
Wend
Code "G53 G01 F20 Z" & toolup
While IsMoving()
Wend
End Sub
Main
Logged
melee
Guest
Re: escape or interrupt a VB script for toolchange m6start
«
Reply #1 on:
November 07, 2009, 12:09:45 PM »
Hi
At first I thought, 'this should be quite simple' , but after scouring the documentation etc. I can see why you asked.
Despite providing a SetKeys() function to stuff the keyboard buffer and feed keys to the window with focus, the Cypress VBS does not have a corresponding GetKeys() function.
Historically, I would have used Int 9 in assembler to interrogate the keyboard buffer, when I used to program in Windows years ago.
Not much use in VBS though.
The main problem in any windowing system, is that mouse and keyboard input is directed and read in terms of which window has focus.
Usually this will be by way of this sort of psuedo code
winptr = GetWindowWithFocus()
KeyPressed = winptr->keyboardEvent.GetKey()
You want a system wide remit, to see what is in the keyboard buffer and act on an Escape sequence.
So far as I can ascertain, the way to read the keystrokes at a system level in Windows using VB, is to access the functions in the user32.dll, namely
GetAsyncKeyState()
The below code should test the keyboard buffer for an Escape key press, by calling EscapeKeyPressed() from within your code.
'''''Determining if Escape has been pressed (vbKeyEscape)
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Function EscapeKeyPressed() As Boolean
Dim bResult As Boolean
'Check First Key (need to call twice, the first call clears
'the keyboard buffer then second checks it's still pressed)
If VarType(vKey1) = vbString Then
bResult = CBool(GetAsyncKeyState(Asc(vbKeyEscape)))
bResult = CBool(GetAsyncKeyState(Asc(vbKeyEscape)))
Else
bResult = CBool(GetAsyncKeyState(vbKeyEscape))
bResult = CBool(GetAsyncKeyState(vbKeyEscape))
End If
EscapeKeyPressed = bResult
Exit Function
End Function
One possible place to put this test is inside your
While IsMoving() loops
You have a lot of these, and should in any case have something like sleep(100) inside them to allow processor time back to the system whilst waiting on the completion of a move.
Something like this might be a starting point
Dim abort As Boolean
abort = false
.
.
.
While IsMoving()
abort = EscapeKeyPressed()
If abort = true Then
'''Initiate whatever needs doing here
End If
sleep(100)
Wend
Alternately, you could simply periodically call EscapeKeyPressed() thoughout the code.
I am no expert on VB or VBS, but I have seen other code where the functions from system .dll s are declared and then the function called, so it should work.
Hopefully someone else can assist with the exact coding required to get it to work in VBS if you have problems.
regards
Melee
PS
I seem to remember reading that the Escape key was not actually a good key to use for anything in macros, because it would likely conflict with the hard coded keybindings in Mach.
You might want to use the Space Bar, commonly used as a pause signal in various apps, so vbKeySpace or Chr(0x20) maybe.
«
Last Edit: November 08, 2009, 10:45:23 AM by melee
»
Logged
melee
Guest
Re: escape or interrupt a VB script for toolchange m6start
«
Reply #2 on:
November 09, 2009, 06:10:59 AM »
Hi Again,
I have now been able to do some experimentation and have come up with some much simplified code which works with Cypress VBS.
I named the code M989.m1s and ran from the MDI line and it works. It permanently loops displaying "Still Looping" on the message line.
When the space bar is pressed, it exits and displays "Loop Aborted".
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Const VK_SPACE = &H20
Sub Main()
Dim abort As Boolean
Message("")
Do
abort = HaltKeyPressed()
If abort = true Then
Message "Loop Aborted"
Exit Do
End If
Message "Still Looping"
Sleep(100)
Loop
End Sub
Main
Sub HaltKeyPressed()
Dim bResult As Boolean
If GetAsyncKeyState(VK_SPACE) < 0 Then
bresult = true
Else
bresult = false
End If
HaltKeyPressed = bResult
End Sub
You will note that I have specifically declared a constant of value 0x20h for the space key. Whilst VBS does not throw an error if you use vbKeySpace, I had no way of knowing if all those constants were accessible to VBS and when I ran the script in debug it did not seem to pick up the key press.
You should now be able to cut and paste the HaltKeyPressed() function into your macro and then use the return from it in your code to determine if the macro should halt.
Don't forget to cut and paste the declaration from user32.dll and the Const declaration too at the start of your code.
Hope this does what you want
regards
Melee
«
Last Edit: November 22, 2009, 12:09:59 PM by melee
»
Logged
mecky
Active Member
Offline
Posts: 2
Re: escape or interrupt a VB script for toolchange m6start
«
Reply #3 on:
November 09, 2009, 02:17:14 PM »
thanks a lot for this. i have not been able to implement your suggestions yet but will let you know some time this week how it turns out.
best
_mecky
Logged
Pages:
1
Go Up
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Mach Discussion
-----------------------------
=> General Mach Discussion
=> Mach3 under Vista
=> Quantum
=> Mach SDK plugin questions and answers.
===> Finished Plugins for Download
=> VB and the development of wizards
=> Brains Development
=> Video P*r*o*b*i*n*g
=> Mach Screens
===> Screen designer tips and tutorials
===> Works in progress
===> Finished Screens
===> Flash Screens
===> JetCam screen designer
===> Machscreen Screen Designer
===> CVI MachStdMill (MSM)
=> Feature Requests
=> Non English Forums
===> Italian
===> French
===> Spanish
===> Chinese
===> German
===> Russian
===> Romanian
===> Japanese
===> Vietnamese
=> FAQs
-----------------------------
*****VIDEOS*****
-----------------------------
=> *****VIDEOS*****
-----------------------------
General CNC Chat
-----------------------------
=> Share Your GCode
=> Show"N"Tell ( What you have made with your CNC machine.)
=> Building or Buying a Wood routing table.. Beginnners guide..
=> Show"N"Tell ( Your Machines)
-----------------------------
G-Code, CAD, and CAM
-----------------------------
=> G-Code, CAD, and CAM discussions
=> LazyCam (Beta)
-----------------------------
Third party software and hardware support forums.
-----------------------------
=> LazyTurn
=> GearoticMotion Preliminary testing
=> Tempest Trajectory Planner
=> Contec
=> dspMC/IP Motion Controller
=> HiCON Motion Controller
=> Third party software and hardware support forums.
=> Galil
=> Newfangled Solutions Wizards
=> Mach3 and G-Rex
=> Mesa
=> Modbus
=> NC Pod
=> PoKeys
=> SmoothStepper USB
=> Sieg Machines
=> Promote and discuss your product
-----------------------------
Tangent Corner
-----------------------------
=> Tangent Corner
=> Competitions
=> Polls
=> Bargain Basement
-----------------------------
Support
-----------------------------
=> Downloads
===> XML files
===> Post Processors
===> Macros
===> Tutorials
===> Others
===> Beta Brains
===> Screen Sets
===> Documents
===> MACH TOOL BOX
=> One on one phone support.
=> Forum suggestions and report forum problems.
-----------------------------
Mach4
-----------------------------
=> Mach4 pre-Alpha Testing
Loading...