Hello Guest it is April 16, 2024, 04:40:31 PM

Author Topic: Help with Mach4 simple button - dro script  (Read 1632 times)

0 Members and 1 Guest are viewing this topic.

Help with Mach4 simple button - dro script
« on: June 10, 2020, 10:04:23 PM »
Hi,

With Mach4 screen editor I create a button that I called setCamOffset and two dros called droCamX and droCamY.

When I click the button I want the actual XY coordinates of the tool to be copied to my dros like:

droCurrentX --> droCamX

droCurrentY ==> droCamY

I wrote the following script for the button (without the line numbering):

1. local inst = mc.mcGetInstance()
2. local Xcoords = scr.GetProperty("droCurrentX","Value")
3. local Ycoords = scr.GetProperty("droCurrentX","Value")
4. scr.SetProperty(inst,"droCamX",tostring(Xcoords))
5. scr.SetProperty("droCamY",tostring(Ycoords))

Problem:  Nothing is being written to my dros .

What is wrong with this script? Do I even use the right functions for the job?

Thanks for your time,
Gaston

--

http://public.fotki.com/Gaston-Gagnon/
Re: Help with Mach4 simple button - dro script
« Reply #1 on: June 11, 2020, 03:06:24 AM »
Hi,
you are using the 'scr.GetProperties(…)' functions and that is not their purpose.
You can indeed read the a DRO using scr.GetPropeties….but you are reading the graphic screen element, not the underlying Mach variable
that holds the true numeric value.

For example, this a one of Machs API's that 'reads' or otherwise retrieves the position of an axis:

Code: [Select]
LUA Syntax:
pos, rc = mc.mcMotionGetPos(
number mInst,
number motorId)

Or you could read a register with:

Code: [Select]
LUA Syntax:
value, rc = mcRegGetValue(
number hReg)

Or read a pound variable:

Code: [Select]
LUA Syntax:
value, rc = mc.mcCntlGetPoundVar(
number mInst,
number param)

Likewise when you want to set a specific value you should use the API's that address and update the register or pound variable designated to store
that data rather than just writing some alpha-numeric characters to the screen, are you even sure for instance that writing a value to the screen
would actually be stored in a Mach register or variable at all?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Help with Mach4 simple button - dro script
« Reply #2 on: June 11, 2020, 01:25:50 PM »
Hi Craig,
If my understanding is correct, there is a register automatically associated with each dro that I added to my panel with the screen editor.  And when I write to that register, the content of the dro changes accordingly. Is this correct?

Then how do I know the number of the register that was automatically associated with my DROs ?
Gaston
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline bcoop

*
  •  61 61
    • View Profile
Re: Help with Mach4 simple button - dro script
« Reply #4 on: June 13, 2020, 08:11:22 AM »
I have this set in a button script,  get the value of X/Y positions and write them to my X/Y Cam Offset DROs and write them to # Vars 5201 & 5202  which are Mach work shift vars. for droMScopeXOffset & droMScopeYOffset  I created Instance Registers in Mach Register Plugin,  and set the persistence check box so values are retained.
here are is a screen shot of my setup which is working well for me right now.

local inst = mc.mcGetInstance();
local Xpos = mc.mcAxisGetPos(inst, 0) 
local Ypos = mc.mcAxisGetPos(inst, 1)
scr.SetProperty('droMScopeXOffset', 'Value', tostring(Xpos))
scr.SetProperty('droMScopeYOffset', 'Value', tostring(Ypos))



mc.mcCntlSetPoundVar(inst,5201, Xpos)  --WORK SHIFT X    #5201
mc.mcCntlSetPoundVar(inst,5202, Ypos) -- WORK SHIFT Y    #5202

Bob
Bob
Re: Help with Mach4 simple button - dro script
« Reply #5 on: June 14, 2020, 10:15:09 PM »
Thank you Bob and Craig, with your help I finally begin to see the light at the end of the tunnel  :)
Gaston
Re: Help with Mach4 simple button - dro script
« Reply #6 on: June 14, 2020, 10:28:35 PM »
Hi,
Lua is a bit of a learning curve, in fact its not really Lua but more Mach4's structure and API.
Notwithstanding the effort required to get to the point of writing your own code the combination
of Machs structure, API and the surprisingly flexible functionality of Lua is very powerful, and to master it
is very rewarding.

Keep up the good work.

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