Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Bill_O on February 27, 2019, 10:08:07 AM
-
Ok.
Yesterday I had a script that would read a register then set another register.
I realized that is not what I needed and deleted it.
Now I need to read a dro then write the value to a register.
Of course it is not working so I am once again asking for help.
The script editor is telling me the problem is the last line.
Here is the code:
--read value from dro
local EncScale = scr.GetProperty('droEncScale', 'Value')
--set register handle
local hreg = mc.mcRegGetHandle(inst, 'iRegs0/EncScale')
--set register
local mc.mcRegSetValue(hreg,'EncScale')
BTW how to do this will be written down this time.
Thanks,
Bill
-
did you test the value in EncScale that returned? Was it a double?
Did you test the value returned to hReg, rc= mc.mcRegGetHandle(inst, 'iRegs0/EncScale')?
What value was returned by rc = mc.mcRegSetValue(hreg,'EncScale')
-
Hi,
you have coded:
local mc.mcRegSetValue(hreg,'EncScale')
So you have attempted to put in a register which is expecting a value (numeric) with a string "EncScale".
I have already posted:
Note all this and more is covered in the Mach4 Scripting Manual chapter 4, in Mach4Hobby/Docs folder.
Have you read it?
Craig
-
craig,
yes i have read it.
i thought the 'EncScale' was a variable
the largest problem i am having with this script is the line "local hreg = mc.mcRegGetHandle(inst, 'iRegs0/EncScale')"
this is the exact same line i have in another script "local hreg = mc.mcRegGetHandle(inst, 'Encoder_0')"
the second works the first does not
both are registers
bill
-
Hi,
that was the purpose that I explicitly pictured and posted a shot of the Regfile Diagnostic panel so that
you could see the naming tree.
If you wish or need to address a register for the purposes of getting its handle use the diagnostic panel.
Craig
-
Sometimes it is pretty easy to get lost in coding and miss details.
EnScale is a variable but when you tried to set the 'iRegs0/EncScale' register you passed the string 'EncScale' not the variable EncScale
local mc.mcRegSetValue(hreg,'EncScale')<----the string
local mc.mcRegSetValue(hreg,EncScale) <----the variable value
which for safety sake:
local mc.mcRegSetValue(hreg,asnumber(EncScale'))
-
rhtuttle,
thanks
i knew it was something simple in how i typed it but did not know what.
thanks again,
Bill
-
which for safety sake:
local mc.mcRegSetValue(hreg,asnumber(EncScale'))
Did you mean
local mc.mcRegSetValue(hreg,tonumber(EncScale))
?
-
Been working on hardware lately and not coding LUA. Thanks for catching that.
-
No problem.