Hello Guest it is March 28, 2024, 08:04:25 PM

Author Topic: Reading dro value in macro  (Read 1153 times)

0 Members and 1 Guest are viewing this topic.

Reading dro value in macro
« on: October 22, 2019, 05:40:36 AM »
Hello people,

I try to read a dro value from a custom screen inside a macro. I use this code: scr.GetProperty('buttonname', 'Value')

But my macro file crashes when i use this. When i make to line a comment the macro runs fine.
Could someone help me please.

Thanks in advance,
Jelle

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Reading dro value in macro
« Reply #1 on: October 22, 2019, 08:48:09 AM »
Screens and macros are in 2 different chunks. Neither can be seen by the other.

If the value being displayed in the DRO can be retrieved by an API call (such as... val, rc = mc.mcAxisGetMachinePos(number mInst, number axisId)) use that in your macro instead of trying to get the value of a screen entity.

If no API exist to the get the value from the DRO that means it is very likely something custom. In that case create a Register and link your DRO to that register. Screens, macros, modules, etc. can all get and/or set registers. Assuming of course they are readable/writeable. The ones you create will be. Some hardware manufacturers display some registers that are read only. Registers are the only thing that is truly global.
;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: Reading dro value in macro
« Reply #2 on: October 22, 2019, 09:55:54 AM »
Thanks for the reply. how would I put that dro value in a register?

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Reading dro value in macro
« Reply #3 on: October 22, 2019, 10:16:41 AM »
First go to Configure/Plugins/RegFile and add your custom register. Then open the screen with screen editor and in the Register property of that DRO select the register you created from the dropdown.

I would probably close and reopen Mach then.

Open Diagnostic/Regfile and find the register you created. From diagnostics you can also set the value of the register and the DRO should update to the new value. Entering a new value in the DRO should update the register. Right clicking the register name from the Regfile diagnostic will also give you the full path of that register you can copy to use in your macro script. Will look something like this.........

iRegs0/MyCustomRegisterName

Use that in the API call to get the register handle then the handle to get or set the register value.

local inst, hReg, value, rc
inst = mc.mcGetInstance()
hReg, rc = mc.mcRegGetHandle(inst, "iRegs0/MyCustomRegisterName")
value, rc = mc.mcRegGetValue(hReg)
rc = mc.mcRegSetValue(hReg, 126)

Registers can be different data types (Value, Value Long, String). It's type is determined by the type data you enter in it's value when creating it. Each type has its own API calls (all covered in the API help file).

« Last Edit: October 22, 2019, 10:19:28 AM by Chaoticone »
;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: Reading dro value in macro
« Reply #4 on: October 22, 2019, 12:39:25 PM »
Thanks Chaoticone for the quick responses and the clear explanations. The macro can now read the dro from the register and i can monitor the value easier.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Reading dro value in macro
« Reply #5 on: October 22, 2019, 01:23:44 PM »
 :)
;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!