Hello Guest it is July 06, 2020, 05:50:01 AM

Author Topic: scr.getProperty – Macro Parameters – Registers  (Read 1425 times)

0 Members and 1 Guest are viewing this topic.

scr.getProperty – Macro Parameters – Registers
« on: February 09, 2018, 03:42:12 PM »
Since I don’t use a CAM program often I find myself writing macros and always need to know what settings are current.

I’m not very good at remembering which parameters and letters are supposed to be sent for macros that I created awhile ago.  You know, m6875 D.25 L1.5 P15…which did d, l and  P stand for?  And in your macro having to grab the values from the param list.

if (hVars ~= nil) then
    local DFlag = mc.mcCntlGetLocalVarFlag(inst, hVars, mc.SV_D)
    if(DFlag == 1) then
      local dia = mc.mcCntlGetLocalVar(inst, hVars, mc.SV_D)
    end
    local LFlag = mc.mcCntlGetLocalVarFlag(inst, hVars, mc.SV_L)
    if(LFlag == 1) then
      local length = mc.mcCntlGetLocalVar(inst, hVars, mc.SV_L)
    end
    local DFlag = mc.mcCntlGetLocalVarFlag(inst, hVars, mc.SV_P)
    if(PFlag == 1) then
      local DOC= mc.mcCntlGetLocalVar(inst, hVars, mc.SV_P)
    end
  end

Wouldn’t it be nice if you could just read the values from the panel dro’s, led’s,… from your macro
function m6875()
local dia=myModule.getProperty(‘droDia’,’Value’)
local length=myModule.getProperty(‘txtLength’,’Value’)
local DOC=myModule.getProperty(‘droDia’,’Value’)

end

With the following additions you can get/set screen properties.  Concept:

Create 4 gRegs0 registers:
gRegs0:gpFlag
gRegs0:gpComponentName
gRegs0:gpComponentAttribute
gRegs0:gpComponentResult

Macro calls for getting/setting a component’s property through a module function that sets registers and sets a register flag to request the action. Then waits for the flag to indicate that it is finished.
PLC monitors a register to determine if a get or set property has been called by a macro, when requested, calls the function in the Load Script
Load script function reads the component name and component property from registers and either gets/sets the property.  Posts the result in a register and sets the flag that it is finished.

PLC monitor

Code: [Select]
------------------------------------------------------------------
--PLC script addition
------------------------------------------------------------
-- checks to see if macro/module has requested a screen property --myChangeProperty()
------------------------------------------------------------

local hReg,rc= mc.mcRegGetHandle(inst,'gRegs0/gpFlag')
if hReg~=nil then
  local flag=mc.mcRegGetValue(hReg)
  if flag==0 then return end      --no request
  if flag==1 then                 --new request to get a property
    mc.mcRegSetValueLong(hReg,2)  --set flag to processing request
    myGetProperty()               --get the requested data and set result and set flag to 0
  end
  if flag==3 then                 --new request to set a property
    mc.mcRegSetValueLong(hReg,2)  --set flag to processing request
    mySetProperty()               --set the requested property and set result and set flag to 0
  end
end

Screen Load Functions

Code: [Select]
------------------------------------------------
--Add to Screen Load Script
------------------------------------------------
function myGetProperty()
  local hflag=mc.mcRegGetHandle(inst,'gRegs0/gpFlag')
  local hcmp=mc.mcRegGetHandle(inst,'gRegs0/gpComponentName')
  local hattr=mc.mcRegGetHandle(inst,'gRegs0/gpComponentAttribute')
  local hrslt=mc.mcRegGetHandle(inst,'gRegs0/gpComponentResult')
 
  local Cname=mc.mcRegGetValueString(hcmp)
  local Cattr=mc.mcRegGetValueString(hattr)
  local Rslt,rc=scr.GetProperty(Cname,Cattr)

  if (rc == mc.MERROR_NOERROR) then
    mc.mcRegSetValueString(hrslt,tostring(Rslt))
    mc.mcRegSetValueString(hcmp,'')
    mc.mcRegSetValueString(hattr,'')
    mc.mcRegSetValue(hflag,0)
  elseif rc~=nil then
    mc.mcRegSetValueString(hrslt,'')
    mc.mcRegSetValue(hflag,rc)
  end
end 
 
function mySetProperty()
  local hflag=mc.mcRegGetHandle(inst,'gRegs0/gpFlag')
  local hcmp=mc.mcRegGetHandle(inst,'gRegs0/gpComponentName')
  local hattr=mc.mcRegGetHandle(inst,'gRegs0/gpComponentAttribute')
  local hrslt=mc.mcRegGetHandle(inst,'gRegs0/gpComponentResult')
 
  local Cname=mc.mcRegGetValueString(hcmp)
  local Cattr=mc.mcRegGetValueString(hattr)
  local Rslt=mc.mcRegGetValueString(hrslt)
  local rc=scr.SetProperty(Cname,Cattr,Rslt)
  if (rc == mc.MERROR_NOERROR) then
    mc.mcRegSetValueString(hrslt,Rslt)
    mc.mcRegSetValueString(hcmp,'')
    mc.mcRegSetValueString(hattr,'')
    mc.mcRegSetValue(hflag,0)
  elseif rc~=nil then
    mc.mcRegSetValueString(hrslt,'')
    mc.mcRegSetValueString(hflag,rc)
  end
end 

Module Code

Code: [Select]
------------------------------------------------------------------
--Module definition
------------------------------------------------------------------
local rtModule = {}
  function rtModule.rtChangeProperty(cName,cAttr,getSet,vlu)
  local hflag=mc.mcRegGetHandle(inst,'gRegs0/gpFlag')
  local hcmp=mc.mcRegGetHandle(inst,'gRegs0/gpComponentName')
  local hattr=mc.mcRegGetHandle(inst,'gRegs0/gpComponentAttribute')
  local hrslt=mc.mcRegGetHandle(inst,'gRegs0/gpComponentResult')
   
  mc.mcRegSetValueString(hcmp,cName)
  mc.mcRegSetValueString(hattr,cAttr)
  mc.mcRegSetValue(hflag,getSet)
  mc.mcRegSetValueString(hrslt,tostring(vlu))
  wx.wxMilliSleep(200)
  while mc.mcRegGetValue(hflag)==2 do
    wx.wxMilliSleep(100)
  end
  local Rslt,rc=mc.mcRegGetValueString(hrslt)
  return Rslt
end 

function rtModule.rtGetProperty(cName,cAttr)
  return rtModule.rtChangeProperty(cName,cAttr,1)
end;

function rtModule.rtSetProperty(cName,cAttr,vlu)
  if vlu==nil then wx.wxMessageBox('Invalid Value') return end
  return rtModule.rtChangeProperty(cName,cAttr,3,vlu)
end;

return rtModule

Macro

Code: [Select]
-------------------------------------------------------------------------
--Macro for testing
--------------------------------------------------------------------------

function m995() 
--  local rslt=rt.rtGetProperty('ledMeasOnly','Value')
--  local rslt=rt.rtSetProperty('ledMeasOnly','Value',1)
 -- local rslt=rt.rtSetProperty('btn(70)','Label','new test')
--  local rslt=rt.rtSetProperty('droProbeDia','Value',0.665)

  wx.wxMessageBox('In 995: '..tostring(rslt))
end

Obviously this can be used for many other tasks beside an alternate way of getting macro parameters.

HTH

Re: scr.getProperty – Macro Parameters – Registers
« Reply #1 on: February 19, 2018, 12:09:00 PM »
edit:

this line needs to be removed from the PLC script:

--  if flag==0 then return end      --no request


Offline smurph

*
  • *
  •  1,270 1,270
  • "That there... that's an RV."
    • View Profile
Re: scr.getProperty – Macro Parameters – Registers
« Reply #2 on: February 25, 2018, 06:33:09 PM »
The latest builds of Mach can provide this functionality.  There is a new DLL in the Modules directory called screenipc.dll.  

scr = require("screenipc)
scr.scIpcInit('127.0.0.1")

Then all of the screen API functions are available to the macros.  Put that line (and also making sure that cpath and path will see the Modules directory) in a file by itself in the Macros driectory.  I think Brett had an example for loading modules for all macros (loadmodules.mcs) or something.  

The screen API is already available in the PLC script, since the PLC script is part of the screen.  Looks like you were using the PLC script just for stuffing values from the screen into registers...  I saw scr.GetProperty() in use.  

But anyway, you can now use scr.GetProperty() and friends directly in the macros.  :)

Steve
Re: scr.getProperty – Macro Parameters – Registers
« Reply #3 on: February 25, 2018, 07:08:25 PM »
Steve,

Thanks for that.  I posted a suggestion for this in mach4 feature request on January 18th.

It would seem that as a 'best practices' policy that the feature request post be monitored weekly and have your group respond with:

Not going to happen
Will be in the next revision
Already exists
Here is a solution

MTCW

RT

Offline smurph

*
  • *
  •  1,270 1,270
  • "That there... that's an RV."
    • View Profile
Re: scr.getProperty – Macro Parameters – Registers
« Reply #4 on: February 25, 2018, 07:37:09 PM »
I read the feature requests.  And I sometimes respond to them.  But most of the time I can better use the time that I would take posing to actually work on something.  If the support people want to comment on them, I guess they could.  But there is one recent one in there, for example, about UNICODE characters.  I don't respond to some of them because I really don't want to get into a discussion of the nitty gritty of why it is the way it is.  But rest assured, I read each and every one of them.  And then I make it look like they were my ideas!  LOL  Seriously though, I like the fact that the feature request thread is more like a list than a discussion.

I did read your post about it.  I had already had plans to do exactly that because of another project in the works.  In fact, I had already been working on it a bit  But I really had no idea when I would get time to finish it.  So I didn't mention it because the next question would have been "When can we have it?" and I would not know.  :( And I won't mention what the other project is for that same reason.  But just know it will be really cool and it will hopefully help a lot of people out. 

Steve
Re: scr.getProperty – Macro Parameters – Registers
« Reply #5 on: February 26, 2018, 05:47:47 PM »
In case anyone else is struggling to get Steve's code working, as I was, here is the content of the file screenipc.mcs that I placed in my macros directory:

Code: [Select]
inst = mc.mcGetInstance()
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
package.path = path .. "\\Modules\\?.lua;" .. path .. "\\Profiles\\" ..  profile .. "\\Modules\\?.lua;"
package.cpath = package.cpath .. ";./Modules/?.dll;"


scr = require("screenipc")
scr.scIpcInit('127.0.0.1')


Many thanks for this Steve: it works a treat. I too was previously setting registers in a macro and then polling them in the PLC script only to update screen elements, so this is a much better way to achieve the desired result.

Allan
« Last Edit: February 26, 2018, 05:50:26 PM by Fledermaus »
Re: scr.getProperty – Macro Parameters – Registers
« Reply #6 on: March 16, 2018, 12:24:26 AM »
The latest builds of Mach can provide this functionality.  There is a new DLL in the Modules directory called screenipc.dll. 
...

Steve

Steve, are there any docs for the ScreenIPC API yet?  I'm hoping I can lookup a UI control by name and see what properties are supported by the control.

I have a problem where I'm using a background image on a notebook tab. The image is a representation of the work area of the machine and probing operations that can be done on it. I'm using transparent bitmap buttons to overlay the control areas of the image that you can use to select probing operations. There is an odd shift in the image (up and to the left) by two pixels along the edge of the area of the transparent image. The effect is to cause the background image to look like it's jagged and messy. I have reported it as a bug, and Brianna said that it was a know issue. I suspect it's a border effect that has been applied to the button and causing the shift. I was hoping to overcome the problem by setting the appropriate property of the bitmap buttons.

-Freeman
I'm not a complete idiot...
    there are some parts missing.

Offline smurph

*
  • *
  •  1,270 1,270
  • "That there... that's an RV."
    • View Profile
Re: scr.getProperty – Macro Parameters – Registers
« Reply #7 on: March 16, 2018, 11:57:03 AM »
No docs yet.  :(  And there is nothing that will list the properties of a control.  But there is a function to enumerate the controls of the screen.  But only in the very latest builds of Mach. 

For all controls that have a background image, there is a scale method property.  When a screen is built, you choose a resolution.  But the screen may not be actually run at that resolution.  Therefore, all of the controls and images are scaled accordingly.  Scaling controls is easy.  But scaling images is a bit harder.  Especially if the scaled image is BIGGER than the original image because pixels have to be added!  So that isn't a good thing at all.  The fix for that is make the image bigger (pixel wise) than it will ever be displayed scaled.  That way, the image is always scaled down.  But even scaling an image down has it's issues.  Now we are going from more pixels to less.  So there are multiple formulas (scale methods) that accomplish this in different ways.  Some images will look better when scaled with certain scale methods.  You have to choose the one that looks best for your image. 

In the hobby version, the buttons are standard Windows controls.  And they do things that I may never be able to "undo".  In the industrial versions, I wrote my own button that I have complete control over (Advnaced GUI controls).


Now, buttons with transparencies are problematic.  Because when the button is pressed, it does move up and to the left to give the effect of being pressed.  This is not an issue on an opaque image or regular button because all of the background is repainted.  But the background is transparent!  So that part of the background is NOT repainted.  It is not a bug, per say, but just how the windows operating system works.  In the hobby version, the buttons are standard Windows controls.  And they do things that I may never be able to "undo".  In the industrial versions, I wrote my own button that I have complete control over (Advnaced GUI controls).  I would need to see your screen set to determine what is going on.  If it is an actual bug or if it is the Windows stock button issue.  But I think from your description that it is the stock windows button issue.  So make a ticket with Bryanna and attach your profile package (Help -> Support -> Package Current Profile).  Tell her to send it to me. 

Steve