Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: Octathorpe on September 06, 2008, 10:44:42 PM

Title: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe on September 06, 2008, 10:44:42 PM
I am using a Sherline mill as an X-Y table with the goal of automating a sampling machine in my laboratory.  I have the mill set up and it seems to function fine under Mach 3.  The laboratory sampling machine (spectrometer) is able to take a data point at specific time intervals.  I would like to move the samples on the X-Y table using mach 3 so that a new sample is moved into position under the spectrometer after a data file is written.  The spectrometer is set up to sample for 1 minute, wait 20 seconds, sample for 1 minute, wait 20 seconds, etc.

I would like to write a VB script to be the interface between Mach 3 and the spectrometer file writing events.  I was thinking that I could run a VB script in Mach 3 that would watch the directory where the spectrometer stores its files.  Every time a new file appears I would like this event to result in the execution of some G-code that moves the x-y table to the next sample. 

Can anyone here tell me from the start if this is reasonable or if there is some reason why this could never work?

I am a novice with both VB script and mach 3 but since what I'm trying to do is really very simple I am optimistic about my chances of making it happen.

I'll put a tad more detail in here for those that are interested.  There are 96 samples on a 8 X 12 grid with exactly 9 mm between sample centers.  The movement would simply be to step through this grid in a systematic fashion.   Mach3 would move to the first spot and then wait until a file appears in the directory of interest.  These files will be numbered from 1 to 96 in case that helps (number at the end of a string in the file name - name_#.spc).  When a new file or the next numbered file appears then mach 3 will see it and then simply move the table to the next sample in the sequence.  Then it will wait for the next file to be written, etc. 

Any basic suggestions on how to accomplish this most efficiently would be greatly appreciated.  This is the only task that Mach 3 and the mill will do.
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe on September 07, 2008, 12:12:50 AM
For example, can I use the following type of script:

Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
    ("SELECT * FROM __InstanceCreationEvent WITHIN 2 WHERE " _
        & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
            & "TargetInstance.GroupComponent= " _
                & "'Win32_Directory.Name=""c:\\\\automation""'")

Do
    Set objLatestEvent = colMonitoredEvents.NextEvent
   
REM  Then execute appropriate movement of stage and then loop.
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe on September 07, 2008, 09:52:21 AM
I am concerned that I will not be able to run the script I previously posted because mach3 may not understand that kind of command.  If that is the case, is there a way to run a native VB script and still be able to send a move/G code command to Mach3 from outside the program?

The following is a description of the sequence that I want to script.  Sorry, I'm not a programmer myself so I don't know the proper syntax, but what I'm trying to do is rather simple so I just wrote it out in text so you can get the general idea.  Any comments or suggestions as to how to create this would be appreciated.

Sample layout is a square grid of 96 points with 8 rows on the X axis and 12 columns on the Y axis.  Points are 9.00 mm apart.

Start loop1 with  Y=0
Start loop2 with X=0
Wait for a new file to appear in directory, then move to next line
Gcode command: Move to point (X+9, Y)
If X=63 then goto next line, else goto loop2 repeat point above
If Y=99 then end
Let Y=Y+9, goto loop1 repeat point above
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe on September 08, 2008, 02:38:10 PM
Yet another follow up. ;D

I have determined that my spectrometer program has an option to "allow data to be sent via DDE to a spectrum analysis application".  However, I believe it is only set up to work with one particular program.  Still, this may again provide some kind of handle. 
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: zealous on September 08, 2008, 10:31:01 PM
I think there might be a better ways then looking at the number of files in a directory....

can you trigger an external switch with your machine?

You can also use Flash with Zinc to access full functioning VB!

If you want to look at the amount of files in a directory use:

Code: [Select]
'Get File count
GetFileCount = objFSO.GetFolder(folderpath).Files.Count

You could also look at the file name and have set functions per file name as well.


Here is some quick code to do what you want I think  ::)  ...at least its a good starting point to get what you want perhaps.

I have not tested it on a machine... and barely debugged it  :-\

I'm thinking your machine is staring from the bottom left corner and working to the right 8 steps.....then when reaching 8 steps... up 1 row.... and back over to  step 1 then over 8 steps etc...

1. Copy past the code below in to a text File.
2. Rename the text File to "Macropump.m1s"
3. Drop "Macropump.m1s" in to your profile Example "C:\Mach3\macros\Mach3Mill"
4. Add a button to toggle LED2000 on/off to activate the script

You can also add DRO2000 to see how may files are in there.


Code: [Select]
'Ignore If loading a file
ProgLoading = IsLoading()

'***Make a Button to turn on/OFF LED2000 (This could be your run button)***

'Ignore If loading a file and if LED2000 is off
If(ProgLoading = 0 And GetUserLEd(2000)=1) Then


'***Create file system object***

'File Sytem Object
Dim objFSO As Object

'Set VB System object
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Folder path
folderpath= "C:\automation"


'Check to see if the folder is there
If objFSO.FolderExists(folderpath) Then


'Get File count
GetFileCount = objFSO.GetFolder(folderpath).Files.Count


'No files
If GetFileCount = 0 Then

'***Set Default Values***

'Clear interLock
 Call SetUserDRO(2000,"0")

Print "File Count Zero"
'Send Machine to Zero's !!! You might want to set a LED before doing this and send the axis to zero :)
'Code("G1 X0 Y0")



'***File Number return larger then 0 see how many***
Else

'If new file added Store in a DRO InterLock
If Not GetOEMDRO(2000) = StoredFileCount Then

Print("Stored Value " & GetOEMDRO(2000))

'Store new value
StoredFileCount = GetFileCount

'Store interLock User DRO 2000
SetOEMDRO(2000,StoredFileCount)

'***Depending on File count will depend will trigger one of the Case statments***

'***Check Row Count***
Select Case  GetFileCount
   
    Case 8   
   
    'Move Y up + 9mm
MoveY = getoemdro(801) + 9

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

'Move X
Code ("G1 X0")

Print "Row "& GetFileCount
                 
     Case 16
     
     'Move Y up + 9mm
MoveY = GetOemDRO800 + 9

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

'Move X
Code ("G1 X0") 

Print "Row "& GetFileCount
       
      Case 24 
     
      'Move Y up + 9mm
MoveY = GetOemDRO800 + 9

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

'Move X
Code ("G1 X0")

Print "Row "& GetFileCount
     
       Case 32 
       
       'Move Y up + 9mm
MoveY = GetOemDRO800 + 9

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

'Move X
Code ("G1 X0")

Print "Row "& GetFileCount
       
        Case 40
       
        'Move Y up + 9mm
MoveY = GetOemDRO800 + 9

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

'Move X
Code ("G1 X0") 

Print "Row "& GetFileCount
       
         Case 48
         
         'Move Y up + 9mm
MoveY = GetOemDRO800 + 9

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

'Move X
Code ("G1 X0")

Print "Row "& GetFileCount
         
          Case 56
           
           
'Move Y up + 9mm
MoveY = GetOemDRO800 + 9

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

'Move X
Code ("G1 X0")

Print "Row "& GetFileCount
           Case 64
           
'Move Y up + 9mm
MoveY = GetOemDRO800 + 9

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

'Move X
Code ("G1 X0")
           
Print "Row "& GetFileCount

            Case 72
           
'Move Y up + 9mm
MoveY = GetOemDRO800 + 9

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

'Move X
Code ("G1 X0")

Print "Row "& GetFileCount
           
             Case 80
             
'Move Y up + 9mm
MoveY = GetOemDRO800 + 9

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

'Move X
Code ("G1 X0")

Print "Row "& GetFileCount
             
              Case 88
             
'Move Y up + 9mm
MoveY = GetOemDRO800 + 9

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

'Move X
Code ("G1 X0")
             
Print "Row "& GetFileCount

               Case 96
               
'Move Y up + 9mm
MoveY = GetOemDRO800 + 9

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

'Move X
Code ("G1 X0")

Print "Row "& GetFileCount


'End Case Statment
     Case Else   
   
   End Select
   
'END If new file added Store in a DRO InterLock
End If
'END No files
End If
   
Else

'No folder exist
MsgBox "Bad File Path"

'END Folder exists
End If

'END Ignore If loading a file
End If

'Clean up
Set objFSO = Nothing
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe on September 09, 2008, 07:48:08 AM
Fantastic! 

I will try to test that code today and let you know what happens.  If I can at least get it to move in response to a single file creation event then all of the movement can be worked out.

When I paste the code into notepad, the question marks appear as little box.  Is that what is expected?

You asked if I could generate an external trigger using the machine.  There is an option to use an LED on the instrument that goes on and off as an analog trigger for mach3.  I have been considering using a phototransistor to trigger a high (5V) setting to one of the parallel port input pins when the LED is on (LED on means collecting  data, LED turns off means that file is done).  This is essentially the same information that can be obtained with the filecount variable you used in the script.  I would like to try the VB filecount route first, but if there is some significant reason why it would be best/easiest to do this whole process using the LED and a 5V input trigger then let me know and I will get that little circuit put together and get a 5V trigger coming into the parallel port.  I have the parts to build the optical sensor, but I have not made it yet - I assume it _has_ to be relatively easy to build such a sensor (I have a few schematics) and get it working, but then again, my first award after joining the department was "most likely to electrocute himself" so I can't guarantee the success of my sensor building abilities  ;)

Meanwhile I will test the script - which I very much appreciate.  I will comment out all of the case statements for now and just see if I can get a response from a filewrite event in that directory.
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: zealous on September 09, 2008, 04:11:15 PM
Hey,

Here is all you need to get the axis moving depending on number of files:

Open Mach Script editor and add this code in and hit run:

The "IF" statement is looking to see if there are 7 files "GetFileCount = 7"
Code: [Select]
'***Create file system object***

'File Sytem Object
Dim objFSO As Object

'Set VB System object
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Folder path
folderpath= "C:\automation"

'Get File count
GetFileCount = objFSO.GetFolder(folderpath).Files.Count

'Message number of files
Print "There are " & GetFileCount &" Files"

'How many to check for
If GetFileCount = 7 Then

Print "If statment True"

'Get current position Move Y up + 9mm
MoveY = getoemdro(801) + 9

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

'Move X
Code ("G1 X0")

End If


'Clean up
Set objFSO = Nothing


It would be better to look at the UserLed and when Not active run the above Macro. That way you don't need to run the macro pump

You might have another button to exit the function in case of an emergency.

You can do it all in a "Brain" would be the best.

Thanks

Title: Re: Using VB script to wait for an external event and then execute G code
Post by: zealous on September 09, 2008, 04:22:01 PM
hey Octathorpe,

I made a typo in the two codes above but corrected them...I had: "getoemdro801" ....rather then "getoemdro(801)"

There shouldn't be any question marks....perhaps it is an unrecognized font types? What part of the country are you from...this might have something to do with it.
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe on September 09, 2008, 06:21:55 PM
It's Alive!!

...well it's pretty exciting for me, anyways.

I was able to paste your code into the script editor and it reads the number of files correctly in the target directory and then moves the machine.  So that is good news - at least that file system function for reading the number of files works and should function as a trigger. 

btw, I'm not sure what the "?" are in my view of the code, could be a font issue - I'm in Atlanta.  I'll keep working with the screen editor (can't get it to work for me yet).  I also have to set up some other variables - it's currently moving 11.5 mm instead of 9 mm per move.  I'll report when I have more info.  Thanks very much for your effort, it's nice to see the critical part functioning!
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe on September 09, 2008, 10:19:14 PM
I've managed to get the motors tuned correctly and moving the correct distance.  I've got a button working with VB code attached to it.  I couldn't get screen designer 4 working, but I got it to work in screen designer verision 3.  I'll need to figure out more about how to turn LEDs on and off and get something going to be able to stop the program if something goes wrong.

I've attached an image of what the sample plate looks like as well as some example coordinates.   I am planning to move from the top left in the image (0,0) to the right across the 12 columns in the X direction to (99,0) in multiples of 9 mm and then come back to (0,9) and move across the 12 points to (99,9), etc.   

I am going to do some more testing to get more familiar with the process of working within Mach with VB.  I'm still getting used to the debugging process and how to complete if, then, else logic.  It's not something I have done much of.   Next I'll deal with the logic of making it work through the array in some logical fashion.  I'm sure there are a thousand different ways to accomplish that process.

It's all moving along quite well....
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Chaoticone on September 09, 2008, 10:28:20 PM
 :)

Brett
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: zealous 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

Title: Re: Using VB script to wait for an external event and then execute G code
Post by: zealous 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.



Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe 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.

Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Chaoticone on September 10, 2008, 10:55:02 PM
Aint Jason great.  ;)


Thanks Jason,
Brett
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe 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)
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: zealous 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!
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe 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. 
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe 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....
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: zealous 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.


Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe on September 14, 2008, 10:14:51 AM
The issue with running on one machine has to do with the spectrometer program.  I don't have the install program for that as it came with the machine.  All I have is the computer with the app installed (and an image of the drive in case it goes down).  So it's  fine that it's running on two machines.  I've got a stack of boxes all going through one KVM switch to run various machines in the lab anyway.

I have a question:  Is there a way to use an output signal (I guess 5V on the parallel port cable) to turn off my spectrometer when the data is finished? The laser source has a finite lifetime.  I'm guessing this would be some kind of power/solenoid type electrical switch.  Is there such a device?  I assume it would be fairly simple to add some code that tells mach 3 to go hi on a certain pin when file #96 is reached, yes? 
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Chaoticone on September 14, 2008, 10:33:16 AM
Octa, are you using a breakout board on your Mach PC? If so, what kind is it? Either way, it would be no trouble to add the code to your macro to do this for you if all you need to do is kill the power to it.

ActivateSignal (Output1)
DeActivateSignal (Output1)

These could control and Opto relay if one is needed.

Brett
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe on September 14, 2008, 10:56:41 AM
I am using a breakout board, I think it is a Xylotec. 

To be clear, although it would also be handy to turn off the juice to the motors, what I want to control is the power cord to the spectrometer.  A Photo-coupled SSR normally open would do it I believe.  Then I coudl send 5V after file 96 and open the relay and kill the power to the spectrometer.  This should be pretty easy once I find the right part.

Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Chaoticone on September 14, 2008, 11:29:10 AM
Have a look at these.

http://www.opto22.com/site/pr_cat_sc.aspx?qs=100610161052

Brett
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe on September 14, 2008, 04:08:47 PM
Great!  I ordered a relay.  I think I can figure out the output pins and put the code in there to do the hi/low switching as needed. 
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe on October 09, 2008, 04:43:42 PM
Hello all,

First, let me say that the system is working very well and I have been collecting a lot of data!  I still run it on two different computers with a switcher, but it works fine that way. 

I am writing now to ask if anyone has a suggestion concerning the wiring of the relay that I would like to use to shut off power to the spectrometer when the data collection is complete.

I have an Opto 22 (mentioned above) relay that accepts 3 to 32 V DC input.  I have been able to identify and wire the pins for an output that I set up in Mach3.  I can use the VB script editor to turn the voltage to this pin on and off.  It sends about 4.25V DC to the output.  I am using a Dell optiplex to drive the on-board parallel port (in ECP mode with no DMA assigned).   When I hook the output from the parallel port to the relay (with nothing on the 120VAC side) the voltage drops to 2.6 C DC and the other side of the relay shows no change.  I suspect that the parallel port can not manage to supply enough current to make the relay function.  I am wondering if the parallel port is wimpy or perhaps I have a relay that needs lots of power.  I would guess that folks have run into this problem before so if anyone has any advice I would appreciate it.

I have a nice parallel port card but it is full height and the Dell that I have (got it free...) has half-height card slots.  I can get a different box and use the card to drive the parallel port if folks think that this will supply enough current to control the relay. 
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Chaoticone on October 09, 2008, 10:15:43 PM
It should only take about 5ma to operate the relay. I haven't checked you exact specs though. On the pic., coil isn't a coil, but hopefully it makes sense.

Brett
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe on October 09, 2008, 10:47:20 PM
That is the way that I have it wired - although when I tested it I did not put anything on the 110V side except a voltmeter.  I'll check it again tomorrow and confirm.

A bit of googling suggests that the parallel port is not supposed to drive the relay directly, but rather an external power source is used to drive the relay using the logic signal from the parallel port.  An example schematic is here:

http://www.winfordeng.com/download/rly102_schematic.pdf

This is the part link:

http://www.winfordeng.com/products/rly102.php

Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Bodini on October 10, 2008, 07:46:48 AM
I'd run it from the breakout board if possible.  Also, those opto relays are WEIRD.  I seem to remember that the ones I have did not totally cut off the voltage, even when 'off'. 
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Bodini on October 10, 2008, 07:51:56 AM
Oh yeah, if you do run it from breakout board, dont miss the 'Automated setting of inputs' (or whatever that button is called, but thats close) in the 'ports and pins'.  It automaticly finds what port/pin you're hooked up to.  Another fantastic Mach feature.  However, do it a few times, sometimes it gets a false reading (sounds like you know how to conduct an experiment anyway  :D)
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe on October 10, 2008, 07:59:28 AM
I've ordered a dual relay board.  That way I'll be able to turn off the power to the spectrometer _and_ the power to the motor controller card.  I'll report back after it arrives and I've installed/tested.
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: Octathorpe on October 14, 2008, 06:55:46 PM
The little breakout relay board arrived today.  It only took a short while to get it wired up.  It worked on the first try.  I have added some buttons to the screen to control the relays manually (even got an LED to turn on and off, which is very basic, I know, but it was pretty advanced for me).  I then added some code to the macropump to turn off the power to the motors (not the controller board) and the laser power once the files have reached 96 (the end) and the probe has returned to the home position.  It took me much longer to do the code because it was pretty much trial and error, but it works.

It all seems to function well.  I may try to add some extra features now such as the option of running two or three plates at one time instead of just one.  Overall the system seems to function quite well and is pretty robust so far.  And now I have saved myself a lot of money because I won't have to replace the laser as soon  :D

Thanks, y'all for your help on this.
Title: Re: Using VB script to wait for an external event and then execute G code
Post by: ataheri on July 06, 2016, 11:47:58 AM
Hello Octathorpe and Jason,
How and where did you put this code? Did you add it in the macro file? It is an interesting project and I am planning to implement similar system as well.

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)