Hello Guest it is April 19, 2024, 02:49:21 PM

Author Topic: How to make a Script PERSISTANT?  (Read 4008 times)

0 Members and 1 Guest are viewing this topic.

How to make a Script PERSISTANT?
« on: November 21, 2010, 05:25:43 PM »
Hello,

I wrote a script which uses GetRPM(), then calculates and displays the RPM's in increments of 50 on a UserDRO.
I use a 'start' button to run the script (in a semi-hard loop), and a 'stop' button to terminate the loop.

I would like the script to be able to run before loading g-code.
I would like the script to run after pressing system 'stop' or 'reset'.
I would like the script to Always be running unless I tell it to stop.

How can this be achieved?

Thanks for any suggestions,
Scott.

Offline Hood

*
  •  25,835 25,835
  • Carnoustie, Scotland
    • View Profile
Re: How to make a Script PERSISTANT?
« Reply #1 on: November 21, 2010, 05:29:18 PM »
Save it as macropump.m1s and place it in your profiles macro folder. On General Config page enable Use Macropump and then restart Mach.
Hood
Re: How to make a Script PERSISTANT?
« Reply #2 on: November 21, 2010, 05:44:25 PM »
Thanks!

I will give it a try.

--Scott
Re: How to make a Script PERSISTANT? Need more help.
« Reply #3 on: November 26, 2010, 04:48:05 PM »
Here is the script I used in macropump.m1s.
I get a flashing LED showing the script is running,
but nothing I do reads the current rpm
(from the spindle pulse) into the RPM variable.
I do not understand the Mach3 style of documentation.
How do I get the rpms into the RPM variable?

This script worked when it was defined as a button
script in my screenset. I can't remember whether I
used GetRPM() or GetOEMDRO(39) or something
else.

'file: macropump.m1s

Option Explicit
Dim RpmDRO, DiameterDRO, RPM, SFM
RpmDRO = 39
DiameterDRO = 105

While GetUserLED(1001)
  RPM = GetRPM()
  'or RPM = GetOEMDRO(RpmDRO)
  SFM = 0.2618 * RPM * GetOEMDRO(DiameterDRO)
  RPM = Int(RPM / 50) * 50
  SFM = Int(SFM / 5) * 5

  'display RPMs in increments of 50
  SetUserDRO(1000, RPM)

  'display SFM in increments of 5
  SetUserDRO(1001, SFM)

  'flash an LED to show that script is running
  if GetUserLED(1002) then
    SetUserLED(1002, 0)
  else
    SetUserLED(1002, 1)
  end if

  Sleep(1000)
Wend

Thanks for any additional help,
Scott

Offline zealous

*
  •  489 489
  • HI!
    • View Profile
    • Artsoft Solutions
Re: How to make a Script PERSISTANT?
« Reply #4 on: November 27, 2010, 04:00:07 AM »
You might want to use the new "StartPeriodicScript" function rather then the Macropump:

StartPeriodicScript
Function StartPeriodicScript(ByVal ScriptQFN as String, ByVal UpdatePeriod as
Double) as Integer
This function causes Mach to start a script that will be invoked with the specified
periodicity.
Arguments:
ScriptQFN: the string of the Qualified File Name (QFN) for the script to be run.
The qualified path name is relative to the Mach install directory. The QFN does
not include the script extension. Mach will look first for ScriptQFN.mcc and if
not found, then ScriptQFN.m1s.
If the QFN is the name of a script already started by a previous call to
StartPeriodicScript(), an error condition is returned. Mach does not support
multiple periodic instances of a single script.
UpdatePeriod: The length of the time period between runs of the script.
The time units are seconds. The minimum value is 5ms, any value less than 5ms
will be ignored and the minimum value of 5ms will be used for the UpdatePeriod.
Page 88
It is recommended that periodic scripts be run with the longest UpdatePeriod
appropriate for the script’s task. This will help minimize the load on the machine
from multiple periodic scripts.
Return Value:
0 = requested function was performed successfully (script is now running).
< 0 = error, requested function was not successful (script is not running).
Error Return Values:
<tbd>
Example:
‘ Initialize a script that runs the way oiler every 30
minutes
If StartPeriodicScript(“OilerScript”, 30*60*1000) then
Msgbox “Oiler periodic script is running”
Else
Msgbox “Oiler script was not started”
End If
See also:
IsPeriodicScriptRunning, StopPeriodicScript
First Mach3 version with API:
This API was first implemented in Mach3 version 3.43.06.
It was defined as a Boolean function with
Return Value:
True = requested function was performed successfully (script is now
running).
False = error, requested function was not successful (script is not running).
This API was revised in Mach3 version 3.43.19 to be an Integer function.


StopPeriodicScript
Function StopPeriodicScript(ByVal ScriptQFN as String) as Integer
This function is used to stop a previously started periodic script.
A periodic script only stops at the end of one of the script’s UpdatePeriod time quanta (as
set by StartPeriodicScript) cycles. For example if a script is running with a 5 minute
UpdatePeriod, and the stop request is issued 2 minutes into the cycle, the script will not
stop until the current 5 minute cycle expires.
Arguments:
ScriptQFN: the string of the Qualified File Name (QFN) for the script to be
stopped. The QFN is relative to the Mach install directory.
The QFN passed must be identical to the QFN used to start the periodic script.
Attempts to stop a script that has not been started by StartPeriodicScript are
ignored (this is not an error condition as the script is “stopped” upon return from
the call).
Return Value:
0 = requested function was performed successfully (script is now running).
< 0 = error, requested function was not successful (script is not running).
Error Values:
<tbd>
Example:
‘ Stop a the running way oiler script
If StopPeriodicScript(“OilerScript”) then
Msgbox “Oiler periodic script has been stopped”
Else
Msgbox “Error, Oiler script was not stopped,
check the QFN passed.”
End If
Page 90
See also:
IsPeriodicScriptRunning, StartPeriodicScript,
First Mach3 version with API:
This API was first implemented in Mach3 version 3.43.06.
It was defined as a Boolean function with
Return Value:
True = requested function was performed successfully (script is now
running).
False = error, requested function was not successful (script is not running).
This API was revised in Mach3 version 3.43.19 to be an Integer function.



IsPeriodicScriptRunning
Function IsPeriodicScriptRunning(ByVal ScriptQFN as String) as Boolean
This function is used to determine if a periodic script has been started.
Arguments:
ScriptQFN: the string of the Qualified File Name (QFN) for the script to check.
The QFN is relative to the Mach install directory.
The QFN passed must be identical to the QFN used to start the periodic script.
Return Value:
True = the Script is running.
False = the script is not running.
Example:
‘ check if the oiler has been started
If IsPeriodicScriptRunning(“OilerScript”) then
Msgbox “Oiler script is running.”
Else
Msgbox “Oiler script is not running.”
End If
See also:
StartPeriodicScript, StopPeriodicScript,
First Mach3 version with API:
This API was first implemented in Mach3 version 3.43.06.