Hello Guest it is March 28, 2024, 04:27:40 PM

Author Topic: Using VB script to wait for an external event and then execute G code  (Read 30809 times)

0 Members and 1 Guest are viewing this topic.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Using VB script to wait for an external event and then execute G code
« Reply #10 on: September 09, 2008, 10:28:20 PM »
 :)

Brett
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline zealous

*
  •  489 489
  • HI!
    • View Profile
    • Artsoft Solutions
Re: Using VB script to wait for an external event and then execute G code
« Reply #11 on: September 10, 2008, 05:59:59 PM »
DownLoad the Zip File located below the JPG image below this message is has the set screen and Macro pump code.

1. Place: Macropump.m1s
In your Profile Example: "C:\Mach3\macros\Mach3Mill\"

2. In Mach: View/Load Screen " FileWatch.set"

3. In Config/GenConfig: turn on Macropump


I added a tab at the top to get to the "File Watch" page.

It will look at: "C:\automation" about every second (you can change the "Sleep time in the macro"***You can take the sleep function out if you like...some people think it helps slower computer.

If DRO 2000 returns the same file count twice it exits the function and waits for the number to change( InterLock).

You shouldn't have to add much more code to finish things up.

So I think then you will just have to tell it how far to move depending on the file number....I would use Modulus and check the current file number in the loop to determine if you need to move Y.


Thanks,
Jason Blake

« Last Edit: September 10, 2008, 09:21:00 PM by zealous »

Offline zealous

*
  •  489 489
  • HI!
    • View Profile
    • Artsoft Solutions
Re: Using VB script to wait for an external event and then execute G code
« Reply #12 on: September 10, 2008, 06:16:02 PM »
I forgot to mention.

I commented out the "Ref Home" and "G1 X0 Yo" if file count equals "0"

If you comment that part out then if your # of files returns 0 it will send the machine to "X0 Y0" and turn off the "File watch" function.

You can then start back up the "File Watch" function when your other machine is ready....


One intresting thing that wouldn't take but a few lines of code....

When your machine if finished and has reached 96 files...you could copy the files to another location, and automate the restart process by simply deleting the files from the "Watch Files" location.
This would allow full automation and no user interaction.



Re: Using VB script to wait for an external event and then execute G code
« Reply #13 on: September 10, 2008, 10:51:57 PM »
FANTASTIC!!

I installed Mach 3 on a machine at home (no CNC but it doesn't seem to care all that much).  It all loaded up perfectly! 

I can paste files into the C:\automation directory and the LEDs go on.  This is really getting fancy now!

I'll try it on the real machine tomorrow and start trying to add the movement commands in there.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Using VB script to wait for an external event and then execute G code
« Reply #14 on: September 10, 2008, 10:55:02 PM »
Aint Jason great.  ;)


Thanks Jason,
Brett
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Using VB script to wait for an external event and then execute G code
« Reply #15 on: September 11, 2008, 09:48:43 AM »
Jason totally Rocks!

I have added a blerb of script to do the movements, and (amazingly), it worked!

Since this is running as a macropump and goes through and then restarts, it isn't necessary to have logic for stepping through the spots in sequence, all that has to be done is just move X + 9 unless the end of a row has been reached.  This is easly figured out based on the number of files. 

If anyone has comments please let me know, otherwise I'll put it on the actual machine today and see what happens.
----------------------- (code below - I coudn't figure out how to make the 'code' box)

'for all cases not described in select below set move to be X+9

MoveX = GetOemDRO(800) + 9
MoveY = getoemdro(801) + 0

'for the special cases at end of rows override previous settings

Select Case  GetFileCount
  Case 12   
    MoveY = getoemdro(801) - 9
    MoveX = GetOemDRO(800) - 99
  Case 24
    MoveY = getoemdro(801) - 9
    MoveX = GetOemDRO(800) - 99
  Case 36
    MoveY = getoemdro(801) - 9
    MoveX = GetOemDRO(800) - 99
  Case 48
    MoveY = getoemdro(801) - 9
    MoveX = GetOemDRO(800) - 99
  Case 60
    MoveY = getoemdro(801) - 9
    MoveX = GetOemDRO(800) - 99
  Case 72
    MoveY = getoemdro(801) - 9
    MoveX = GetOemDRO(800) - 99
  Case 84
    MoveY = getoemdro(801) - 9
    MoveX = GetOemDRO(800) - 99
  Case 96
    MoveY = getoemdro(801) - 63
    MoveX = GetOemDRO(800) - 99
end select

'Move Y
Code ("G1 Y" & MoveY)
'Move X
Code ("G1 X" & MoveX)

Offline zealous

*
  •  489 489
  • HI!
    • View Profile
    • Artsoft Solutions
Re: Using VB script to wait for an external event and then execute G code
« Reply #16 on: September 11, 2008, 07:35:55 PM »
Short simple and to the point  ;D

Looks good!

Not necessary but might be useful to add extra protection and error checking of accuracy of the machine also double checking end of file and next row.

Accuracy Check:
Is current position “99” and File count “12” or “24” est.…

End of column:
Check to see if the next move of X will be greater than 99 o determine the end of column.

Reach end of file:
Check to see if next move of Y will be greater than -63 to determine the end of file.

Great job!
Re: Using VB script to wait for an external event and then execute G code
« Reply #17 on: September 11, 2008, 08:10:37 PM »
Everything is working great!

I put it all together on the actual machine today and it all checked out .  Everything moves as it should and behaves as intended.  What a great result!

I will play around with those other suggestions and make sure that it ends cleanly and has no errors.

I have one more step I have to complete before a real run.  The spectrometer program is rather lame and takes up a huge amount of CPU - there really isn't much I can do about it.  But I was not able to install Mach 3 and run it at the same time as the spectrometer app on the same machine.  It just crashed the machine. So I'm going to leave mach 3 on a separate machine and do the file check on the spectrometer box.  It won't really change much.  I'll set that networking up tomorrow, set the new file path and gather my first set of data. 

Jason, I really appreciate your effort.  I've been fretting about this and trying various approaches for quite a long time - with very limited success.  However, what you have provided is solid and really looks like it will work perfectly for me. 
Re: Using VB script to wait for an external event and then execute G code
« Reply #18 on: September 12, 2008, 02:27:54 PM »
I set up the system with dual machines - one running the spectrometer instrument, the other Mach 3.  Cross-over cable and shared drives.  It all works fine.

I have set up the first proper data collection in full automation mode and it is currently running!

All of this hard work just so that I can type this message to you while mach 3 is doing my work for me....

Offline zealous

*
  •  489 489
  • HI!
    • View Profile
    • Artsoft Solutions
Re: Using VB script to wait for an external event and then execute G code
« Reply #19 on: September 12, 2008, 09:58:25 PM »
Great to hear!

Its too bad that you could not run it all on one system.  :(

Would using a dual core help any?

Let us know if you run into any other enhancments or issues.