Hello Guest it is May 11, 2021, 12:13:32 PM

Author Topic: Macro only runs in editor  (Read 3035 times)

0 Members and 1 Guest are viewing this topic.

Macro only runs in editor
« on: October 19, 2016, 06:45:36 PM »
Hey all, I have been working on this script and it will only run within the editor. I tried to run it in the Macro pump and via the part program as "M1000". As a Macropump it does nothing as M1000 the program halts at the M1000 command.

I created a button to call the script and it also halts the Gcode from processing.

I added the DoOEMbutton (1000) to the script for testing and it works perfectly.

Any help would be appreciated.

Sub Main()
SetuserLed (1003,1)

Open "c:\TESTFILE.csv" For Output As #1 ' Open to write file.
Dooembutton (1000) 'added to  test the script

oldX = GetOEMDRO (800)
oldY = GetOEMDRO (801)
oldZ = GetOEMDRO (802)
oldL = GetOEMDRO (816)

Write #1, "X", "Y","Z","Line","Time","Date"
Write #1, oldX, oldY, oldZ,oldL, Time (Now), Date()

Do While GetoemLED (804)
newx = GetOEMDRO (800)
newy = GetOEMDRO (801)
newz = GetOEMDRO (802)
OldL = GetOEMDRO (816)
If oldX <> newX Or oldY <> newY Or oldZ <> newZ Then
   oldX = newX
   oldY = newY
   oldZ = newZ
   OldL = oldL
Write #1, oldX, oldY, oldZ,oldL, Time (Now), Date()
End If
'Filter timer - a low value will collect more data points
'a high value will collect fewer data points
'1 sample per second = 1000, 10 persecond = 1

Sleep (500)
Message "Recording Started"     


Close #1
SetuserLed (1003,0)
Message "Recording Stopped"

End Sub

Re: Macro only runs in editor
« Reply #1 on: October 19, 2016, 09:30:18 PM »
As I understand it, the Sub Main() and End Sub are not needed.  When the macro is called it sees this as a subroutine and does not execute it as there is no call to run the subroutine.  Try taking those two statements out and see if that works for you.

Stephen "Highspeed" Kruse

Offline stirling

  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: Macro only runs in editor
« Reply #2 on: October 20, 2016, 06:54:29 AM »
I agree with @Highspeed - why we see this a lot - I don't know. FWIW it shouldn't actually run because there's no call. It does however which I suspect is a either a bug in CB or the way CB is implemented in Mach.

However, moving on...

running your code in the macropump:
The macropump runs (or tries to run) your macro over and over every 1/10th of a second. Can you see why your code is going to kill it because of your do while loop? Can you also see that you'll be continually opening the text file?

running your code as an MCode:
GCode runs line by line. It can't run the next line until the MCode has finished. It can't finish the MCode until the GCOde has finished because of your do while loop. Can you see a deadlock issue here?

Running it from a button works here (without your Dooembutton (1000) line)

Curious as to what you're trying to do - particularly why you'd write the date on every iteration - how long is your gcode file going to take to run?
« Last Edit: October 20, 2016, 06:58:33 AM by stirling »
Re: Macro only runs in editor
« Reply #3 on: October 20, 2016, 07:50:41 AM »
Thanks for the input High speed and Stirling,
I will remove the SubMain() and End Sub, give it a try.

I would rather not run it in a macro pump it was just a trial. I am collecting the data to correlate DRO data with vibration, temperature and spindle load Data. This is somewhat a science project but it is very interesting to see the data and how it reflects quality and processing time.

Thanks again for the feedback
Re: Macro only runs in editor
« Reply #4 on: October 20, 2016, 05:58:23 PM »
The problem actually came down to how I had the button configured, I configured it to standard code 34.
Re: Macro only runs in editor
« Reply #5 on: October 20, 2016, 07:07:24 PM »
That'll do it too. Glad you got that figured out.