Hello Guest it is December 11, 2019, 07:11:10 AM

Author Topic: write to a register  (Read 260 times)

0 Members and 1 Guest are viewing this topic.

Offline Bill_O

*
  •  250 250
    • View Profile
write to a register
« 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
Re: write to a register
« Reply #1 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')
Re: write to a register
« Reply #2 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
My wife left with my best friend...
     and I miss him!

Offline Bill_O

*
  •  250 250
    • View Profile
Re: write to a register
« Reply #3 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
Re: write to a register
« Reply #4 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
My wife left with my best friend...
     and I miss him!
Re: write to a register
« Reply #5 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'))



Offline Bill_O

*
  •  250 250
    • View Profile
Re: write to a register
« Reply #6 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

Offline Chaoticone

*
  • *
  •  5,633 5,633
  • Precision Chaos
    • View Profile
Re: write to a register
« Reply #7 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))

?
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: write to a register
« Reply #8 on: February 28, 2019, 10:15:11 AM »
Been working on hardware lately and not coding LUA.  Thanks for catching that.

Offline Chaoticone

*
  • *
  •  5,633 5,633
  • Precision Chaos
    • View Profile
Re: write to a register
« Reply #9 on: February 28, 2019, 04:36:55 PM »
No problem.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!