Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Bill_O on February 27, 2019, 10:08:07 AM

Title: write to a register
Post 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
Title: Re: write to a register
Post by: rhtuttle on February 27, 2019, 10:46:21 AM
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')
Title: Re: write to a register
Post by: joeaverage on February 27, 2019, 12:49:50 PM
Hi,
you have coded:

Code: [Select]
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:
Quote
Note all this and more is covered in the Mach4 Scripting Manual chapter 4, in Mach4Hobby/Docs folder.
Have you read it?

Craig
Title: Re: write to a register
Post by: Bill_O on February 27, 2019, 01:56:51 PM
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
Title: Re: write to a register
Post by: joeaverage on February 27, 2019, 02:37:15 PM
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
Title: Re: write to a register
Post by: rhtuttle on February 27, 2019, 03:46:41 PM
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'))



Title: Re: write to a register
Post by: Bill_O on February 28, 2019, 08:12:29 AM
rhtuttle,

thanks
i knew it was something simple in how i typed it but did not know what.

thanks again,
Bill
Title: Re: write to a register
Post by: Chaoticone on February 28, 2019, 08:44:03 AM

which for safety sake:
local mc.mcRegSetValue(hreg,asnumber(EncScale'))





Did you mean

local mc.mcRegSetValue(hreg,tonumber(EncScale))

?
Title: Re: write to a register
Post by: rhtuttle on February 28, 2019, 10:15:11 AM
Been working on hardware lately and not coding LUA.  Thanks for catching that.
Title: Re: write to a register
Post by: Chaoticone on February 28, 2019, 04:36:55 PM
No problem.