Hello Guest it is April 26, 2024, 02:53:58 AM

Author Topic: Adding field for value input  (Read 1135 times)

0 Members and 1 Guest are viewing this topic.

Offline DAAD

*
  •  103 103
    • View Profile
Adding field for value input
« on: November 19, 2020, 07:31:31 AM »
At the moment i have a probe height point on my table to setup quickly correct height of my tools.
But if i flycut my table, i need to adjust the value into my module each time.

Would there be a way to put a field inside my screenset where i can put the value into so that my module can pick it up?

It would save me some hassle of editing the module each time.

Keep Safe,

Adam

Re: Adding field for value input
« Reply #1 on: November 19, 2020, 10:58:27 AM »
Yes.  See bryanna's video on screen set editing.  Add a dro where you want and name it. in the events for that dro either update a register that you create or write the value to a profile string.  In the startup script or in the macro read either the register or the profile value.

HTH

RT

Offline DAAD

*
  •  103 103
    • View Profile
Re: Adding field for value input
« Reply #2 on: November 20, 2020, 01:13:14 AM »
thanks, will study the vid this weekend!

Offline DAAD

*
  •  103 103
    • View Profile
Re: Adding field for value input
« Reply #3 on: November 27, 2020, 07:35:09 AM »
I'm still learning to get on with lua...

I, was able to make an dro to put in a value.
But when i close the program i lose the Number

Here is what i did load into the screen load script:
Code: [Select]
--local inst = mc.mcGetInstance()
local droVal = mc.mcProfileGetInt(inst, "Preferences", "ToolSetHeigth", 0)
scr.SetProperty("droToolset", "Value",tostring(droVal))

And here is what i put in the unload script:
Code: [Select]
--Save dro Toolsetter Height to .ini
local droVal = scr.GetProperty('droToolset','Value')
mc.mcProfileWriteString(inst, "ToolSetHeigth","MachineBedOffset", droVal)

If i look into the ini file i can't seem to find back the info that schould have been written...
If i can load unload the dor i can use it to get data in an lua module i use.

Adam
Re: Adding field for value input
« Reply #4 on: November 27, 2020, 11:51:29 AM »
You are writing the value to one place "ToolSetHeigth","MachineBedOffset" and then reading it from somewhere else "Preferences", "ToolSetHeigth". Make these the same and it should work

Offline DAAD

*
  •  103 103
    • View Profile
Re: Adding field for value input
« Reply #5 on: November 27, 2020, 12:35:15 PM »
I've made an error while pasting the code.
I've double checked, my code and both parameters are the same.

Still not saving the dro when i close and open mach 4...

Offline jbuehn

*
  •  101 101
    • View Profile
Re: Adding field for value input
« Reply #6 on: November 27, 2020, 01:09:15 PM »
Is it saving the value correctly in the screen unload portion? You could check by looking in the actual Machine.ini file after you've closed Mach4.

If it is saving the value correctly, but not loading it, then I'd try moving the code that's in your screen load script to the portion of the PLC script that only executes on the first run. At the bottom of the PLC script, I think there's a comment that says "PLC First Run".

Sometimes all the screen elements aren't loaded yet if you try to change their values in the screen load script.

Offline DAAD

*
  •  103 103
    • View Profile
Re: Adding field for value input
« Reply #7 on: November 27, 2020, 01:55:08 PM »
Hello,

Thanks for the tip,

Searched the ini file and no parameter or value is saved...
I've double checked the spelling of the dro and all seems correct.

do i need to do something specific for saving the data to the ini file?
Re: Adding field for value input
« Reply #8 on: November 27, 2020, 02:39:49 PM »
rc = mc.mcProfileFlush(number mInst)
rc = mc.mcProfileSave(number mInst)

I see you are saving the value as a string and then reading it back as an int but setting the value of the DRO as a string.
Have you checked the droVal returned by the getProperty?  Is it a string or a number?

I think the preferred method is to not write to the profile but to create gReg entry (Config->Plugins->RegFile, Global Registers Tab) and mark it as persistent. It will be read and saved automatically and you can access its value as needed.  Set the 'Register' property of the DRO to be that variable.

HTH

RT

Offline DAAD

*
  •  103 103
    • View Profile
Re: Adding field for value input
« Reply #9 on: November 28, 2020, 10:26:36 AM »
rc = mc.mcProfileFlush(number mInst)
rc = mc.mcProfileSave(number mInst)

I see you are saving the value as a string and then reading it back as an int but setting the value of the DRO as a string.
Have you checked the droVal returned by the getProperty?  Is it a string or a number?

I think the preferred method is to not write to the profile but to create gReg entry (Config->Plugins->RegFile, Global Registers Tab) and mark it as persistent. It will be read and saved automatically and you can access its value as needed.  Set the 'Register' property of the DRO to be that variable.

HTH

RT

The above with the registers worked perfectly!

Thanks!