Hello Guest it is April 27, 2024, 12:23:49 AM

Author Topic: Pass variable between M3 Macro and Signal Library  (Read 2606 times)

0 Members and 1 Guest are viewing this topic.

Pass variable between M3 Macro and Signal Library
« on: February 11, 2022, 06:11:26 PM »
I have a floating head plasma torch mount with Proximity switch to be used for two purposes.  1: Sense material height during M3 Probing/start torch and 2: Use as protection against torch damage from collision during cutting. I have the following “work in progress” where I’ve added code to  signal library, and monitor the Probe/collision input signal.  The plan is to check to see if were performing an M3 move, and if we are, do nothing otherwise, do a STOPmovement().
I unsuccessfully placed a M3Probing variable in the M3 Macro to =1 when performing probing, but I can’t figure out how to get the signal Library code to see the variable.  The scripting manual says the variable has to be in a Module to share it between macros and signal library, but everything I’ve tried has failed.
Can someone point me in the right direction?
Thanks.
Code: [Select]
--Signal Library Code
[mc.ISIG_INPUT9]= function (state) -- Torch Probe/collision switch state has changed
if(state==1) then
If (M3Probing==1) then  -- THIS VARIABLE IS SUPPOSED TO BE SET BY m3() However it is not seen by this signal library code, so it does not work.
--do nothing
Else
STOPmovement() -- call function to stop movement
mc.mcCntlSetLastError(inst, "Error- Torch Collision Detected")  -- Put message in message box
End
end
end,

-- added function to bottom of screen script
function STOPmovement ()
local inst = mc.mcGetInstance()
mc.mcSpindleSetDirection(inst,0)  -- Set to 0 to turn spindle off
mc.mcCntlCycleStop(inst)  -- stops Gcode file that is running.
end
ChrisO

Mach4 Hobby
Vital Systems Hicon Controller 7866 with 77ISO board and ArcPro Plasma Profile
DYN4 DYN4-H01A2-00 AC SERVO Drives
DMM 750 Watt NEMA 34 motors
Thermal Dynamics Pak Master PCM-100XL Machine Torch with floating head
Retrofit Table: 6’x24’ linear rail and belt drive
Re: Pass variable between M3 Macro and Signal Library
« Reply #1 on: February 11, 2022, 06:47:19 PM »
Hi,
when an m3 is executed it is the Gcode interpreter and trajectory planner chunk that is operating.......when the Signal Library code is executing its the Screen code chunk which is operating.

The variable in the Screen chunk is NOT available to the Gcode/Interpreter chunk, and only one can run at a time. In practice Machs core is bouncing back and forth between the two chunks
that give the impression that that the two chunks run simultaneously.

Set up and use a register. A register can be accessed by any Lua chunk at any time and is a great way to pass data from one chunk to another.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Pass variable between M3 Macro and Signal Library
« Reply #2 on: February 11, 2022, 08:58:23 PM »
 Great!,  I will begin the journey to learn about registers.  Thanks for the insight!
ChrisO

Mach4 Hobby
Vital Systems Hicon Controller 7866 with 77ISO board and ArcPro Plasma Profile
DYN4 DYN4-H01A2-00 AC SERVO Drives
DMM 750 Watt NEMA 34 motors
Thermal Dynamics Pak Master PCM-100XL Machine Torch with floating head
Retrofit Table: 6’x24’ linear rail and belt drive
Re: Pass variable between M3 Macro and Signal Library
« Reply #3 on: February 11, 2022, 09:27:41 PM »
Hi,

1) Open the Regfile plugin
2) Assign a name, and initial value if required,a description if required and whether it will be persistent, ie saved an shut down.
3) <Apply> and close.

The register of that name now resides at iRegs0/<register name>.
To access it from a Lua script:

Code: [Select]
local registerHandle=mc.mcRegGetHandle(inst,'iRegs0/MyRegister')
local registerValue=mc.mcRegGetValue(registerHandle)

There are a number of APIs of this general type in Mach4Hobby/Docs in the Register category.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'