Hello Guest it is April 16, 2024, 02:02:20 PM

Author Topic: Read write to a DRO ??  (Read 13848 times)

0 Members and 1 Guest are viewing this topic.

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Read write to a DRO ??
« Reply #10 on: May 31, 2014, 12:05:56 AM »
OK I just realized something these scripts MONKEY with the XML is THAT a good idea. ???

Can it be done another way that does not involve the XML.

(;-) TP

Offline Bodini

*
  •  216 216
    • View Profile
Re: Read write to a DRO ??
« Reply #11 on: May 31, 2014, 12:11:38 AM »
OOps, I'm late to the party but here you go.

Gets var, Sets dro

Code: [Select]
inst = mc.mcGetInstance()
local SNv = mc.mcCntlGetPoundVar(inst,590) --gets #var
scr.SetProperty('udro18', 'Value', tostring(SNv)) --sets dro

Gets dro, Sets Var

Code: [Select]
local droval = scr.GetProperty('udro18', 'Value') --gets dro
mc.mcCntlSetPoundVar(inst, 590, tonumber(droval)) --set #var

Note how you switch a string to a number (tonumber) and reverse(tostring).

  Also, any time you want to see what type something is in lua (http://lua-users.org/wiki/LuaTypesTutorial), try:
Code: [Select]
print(type(YOUR_VARIABLE)  --inserting the variable you want to know about
Hit F5 and then F11 to step through it, and watch the console at the bottom of Lua.

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Read write to a DRO ??
« Reply #12 on: May 31, 2014, 12:47:26 AM »
Thanks Bodini  your script works fine. I see the problem I had with the converting the String to Number.  A Case usage on the U in udro18 had me for a moment but when it kept coming up <nil> I figured it out.

The print function does not do anything here ????

Thanks again, (;-) TP

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Read write to a DRO ??
« Reply #13 on: May 31, 2014, 12:55:50 AM »
AH OK it does work here I was expecting something else. It tells you if it is a string ,number,etc

Cool, (;-) TP

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Read write to a DRO ??
« Reply #14 on: May 31, 2014, 01:10:25 AM »
ALL RIGHT a fully functional sequential S/N engraving function that is call from a G65 Macro call. Each time it runs it increments the S/N by 1. When it gets to 999999 it rolls over back to 1. You can reset the S/N start point from the program screen.

Next is to try and MAKE the S/N and var update themselves as each changes.

Thanks To everyone.

(;-) TP

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Read write to a DRO ??
« Reply #15 on: May 31, 2014, 07:44:24 AM »
Next is to try and MAKE the S/N and var update themselves as each changes.

like I said in my earlier post, pop it in your PLC script...
Also, just curious but the one I showed you, is exactly what bodini showed you... except for UDRO20.... with the "Set" and "Get" property calls, you have to look at the "Properties" of the object and look very carefully at the property you wanting to do something with.
i.e.  Value, and value are not the same.... etc. 

further:  tostring(), tonumber(), type(var), and the native lua string functions are your friends, it is worth learning about them.

glad you got it working, I knew you would!

Scott
fun times

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Read write to a DRO ??
« Reply #16 on: May 31, 2014, 02:05:44 PM »
OK it works fine with a couple of exceptions I am working on.   The screen PLC script does a fine job of updating the DRO whenever the #VAR changes . TOO WELL to be exact(;-). I elected to go with a Button to update the S/N DRO. You input the new S/N into the DRO and press the button and it updates the #var.

In testing you could not have the 2 scripts in the PLC at the same time. Then seemed to fight each other for control over the DRO. Nothing worked SO the one that updates the DRO won the prize and got to stay in the PLC script.

BUT, yes there is always a but in there somewhere(not me of course). WHEN you Input the new S/N into the DRO and press ENTER  the PLC script changes it right back to the old number (;-) Just doing it's job .

To make it work you have to enter the s/n BUT do not press enter. Then press the Button to update. THEN it works perfect and does its job.

NOW THE PROBLEM is we beat into the operators head that the order of value entry on ANY controller is ENTER VALUE and PRESS ENTER.  

SO any ideas on how to make that work ?? I know I can either use 2 buttons or USE 2 dros . But that would be just working for the machine , not it working for you.  


IN the screen editor looking a the button options there is an  ON update  script selection and a  on modify script selection. DOES anyone know how they work or exactly what they do?

(;-) TP


« Last Edit: May 31, 2014, 02:15:19 PM by BR549 »

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Read write to a DRO ??
« Reply #17 on: May 31, 2014, 02:24:11 PM »
OK THAT was easy. I just took a chance and jumped down the rabbit hole and tested each dro script option.  THE on modify was the trick. I used the script from the button.

NOW when I enter the new S/N and press enter it updates teh #var correctly .

SO NOW it is 99.99% perfect.

(;-) TP

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Read write to a DRO ??
« Reply #18 on: June 02, 2014, 12:22:34 AM »
Damn!!!!  Now that was using your head!  Hmm...  Me thinks you are getting good at this Terry.

You can use the OnUpdate and OnModifiy scripts to display and edit scaled values too.  Used if a DRO doesn't show you something the way you want it too. 

Steve

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Read write to a DRO ??
« Reply #19 on: June 02, 2014, 01:03:33 AM »
OK Next question, In Mach3 we had a AskQuestion box. You input the question string and got back what was typed into the box. I can't find anything like that in LUA so far.

I do see some things that craig posted they were wxlua fuctions BUT there are no explanations to what they really do or how to use them

Does anyone know HOW to make it work in lua. I think you have to program th ebox and add stuff. OR IS there a WX substitute??

I need an example if possible or a link to an example. Working on a simple password function to set teh attrb to read only to protect teh Gcodes and subs and macros.

STEVE have you any more thoughts on the tool table ??

(;-) TP