Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: bcoop on April 26, 2020, 07:50:09 AM
-
Need some guidance, trying to read any of the ENUM signals and always get the same result of 0.0 in the message box. what am I doing wrong?
any help is greatly appreciated!
local inst= mc.mcGetInstance()
local hReg= mc.mcSignalGetHandle(inst, mc.VAL_CYCLE_TIME)
local val=mc.mcRegGetValue(hReg)
wx.wxMessageBox(tostring(val))
-
Bob,
When I have a bit of time, I'll come back and do some research, but at first glance, I question if mc.VAL_CYCLE_TIME is correct. I don't remember needing to include the "mc." in front of my signal names.
I think you program is failing to get the correct path to the data. Thus, "val" always has a value of 0.
Mike
-
I would appreciate that, I have tried every way i can think of, I either get Zero or invoke some type of error.
wondering, are the enumerated values considered Signals or Registers or Mach Core values. or something else. maybe I'm just not using the correct Api function to get to the data.
any help is greatly appreciated,
-
Hi,
yes you do need the 'mc.' in front. In Lua that syntax refers to a table, Lua's one and only data structure.
The sequence of events is that Lua looks in table 'mc' for an entry [VAL_CYCLE_TIME] and that table entry contains the handle.
local hReg= mc.mcSignalGetHandle(inst, mc.VAL_CYCLE_TIME) is not correct, mc.VAL_CYCLE_TIME is not a SIGNAL, it is a register.
Try:
local hReg=mc.mcRegGetHandle(inst, mc.VAL_CYCLE_TIME) instead.
Craig
-
Craig, thanks for the info, I have tried
local hReg=mc.mcRegGetHandle(inst, mc.VAL_CYCLE_TIME) but received the following error
---------------
Lua: Error while running chunk
C:\Mach4Hobby\ScreenScript.lua:961: wxLua: Expected a 'string' or 'wxString' for parameter 2, but got a 'number'.
Function called: 'mcRegGetHandle(number, number)'
01. mcRegGetHandle(number, string, lightuserdata)
stack traceback:
[C]: in function 'mc.mcRegGetHandle'
-------------------
looks like the API calls for string,
hReg, rc = mc.mcRegGetHandle(
number mInst,
string path)
------------
so I tried the following, but still only get a value of 0.0
local inst= mc.mcGetInstance();
local hReg=mc.mcRegGetHandle(inst, "mc.VAL_CYCLE_TIME")
local val=mc.mcRegGetValue(hReg)
wx.wxMessageBox(tostring(val))
-----
Bob
-
Hi,
my apologies, now that I am home and I have checked what I posted you are correct.
This is the syntax of the RegGetHandle() API:
hReg, rc = mc.mcRegGetHandle(
number mInst,
string path)
So the path is a string, not a number.
Try this instead:
value, rc = mc.mcCntlGetPoundVar(
number mInst,
number param)
the param here is a number and mc.VAL_CYCLE_TIME is an Enum of a number.
Have a look at:
https://www.machsupport.com/forum/index.php?topic=40051.msg271116#msg271116 (https://www.machsupport.com/forum/index.php?topic=40051.msg271116#msg271116)
Try running this little bit of code:
function m301()
local inst=mc.mcGetInstance()
local num=mc.VAL_CYCLE_TIME
wx.wxMessageBox(tostring(num))
end
if (mc.mcInEditor()==1)then
m301()
end
It should result in the number 2007 being displayed being the value of VAL_CYCLE_TIME.
So it would be useful to have the register diagnostic window open (and pinned to the top) to
display pound variables in the range 2000 to 2020 for instance.
Craig
-
Craig thanks for all the help and information,
i was able to get 2007 but what i was expecting was the value of the machine cycle time as displayed on the standard mach4 screen sets.
so it appears that the register mc.VAL_CYCLE_TIME is a pointer to the pound variable 2007. is that correct.?
If 2007 is indeed the #var for mc.VAL_CYCLE_TIME then shouldn't it match the display, cycle time?
I found that cycle time display comes from ...
local cycletime = mc.mcCntlGetRunTime(inst, time)
scr.SetProperty("CycleTime", "Label", SecondsToTime(cycletime))
but i don't see where it that value is assigned to #2007
-
Craig,
Thanks for looking into this!
Bob,
I didn't get a chance to dig into this last night. Why don't you open the screen editor and try to understand the display element and backing code that makes the cycle timer work on the normal screen set? I had to dig into it in the part. I think the code is in the PLC script. You should be able to copy their code or at least see how it works.
Mike
-
Mike, I did dig into that in my earlier post,
... I found that cycle time display comes from ...
local cycletime = mc.mcCntlGetRunTime(inst, time)
scr.SetProperty("CycleTime", "Label", SecondsToTime(cycletime))
But I am still interested into why the enum value and or the #var 2007 is always zero, just trying to learn a little more about mach and lua.
Bob
-
cycletime, rc = mc.mcCntlGetValue(inst, mc.VAL_CYCLE_TIME, 0);
mc.VAL_CYCLE_TIME isn't really an enumeration. It is a constant.
Anything that begins with mc.VAL_ is a constant and it is to be used with mc.mcCntlGetValue() or mc.mcCntlSetValue().
2007 isn't a #var location, it is a constant number that is assigned in the API header file. See the snippet below.
// System values.
#define VAL_ACTIVE_TOOL 2000
#define VAL_AXIS_MACHINE_POS 2001
#define VAL_AXIS_POS 2003
#define VAL_AXIS_VEL 2004
#define VAL_BLOCK_DELETE 2005
#define VAL_CONTROLLER_MODE 2006
#define VAL_CYCLE_TIME 2007
#define VAL_DIA_REG 2008
#define VAL_DIST_TO_GO 2009
...
Steve