Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: BR549 on May 30, 2014, 03:06:56 PM

Title: Read write to a DRO ??
Post by: BR549 on May 30, 2014, 03:06:56 PM
How would one read or write to a USER DRO on the screen.

I need to read a #var(I can do that) and update an onscreen DRO(dro18)  . That part I cannt do as I do not find any langeage to create the function.

In mach3 it would be    SetUserDRO(18,  GetVar(590))

ALSO same the otherway around. I need to update a #var(#590) from  DRO value of (DRO18)

in Mach3 it would be SetVar(590, GetUserDro(18))
Title: Re: Read write to a DRO ??
Post by: Bodini on May 30, 2014, 07:32:31 PM
I just sent you an email with an image regarding your question (couldn't upload the image at the moment).  Hopefully it's what you are looking for.  -Nick

And super quick here out of my notes:

Sending a Property called 'value' to a DRO called 'udro101' with a variable called 'Passval'
Code: [Select]
Passval = 100
scr.SetProperty('udro101', 'Value', tostring(Passval))

*Addendum*  Finally gained access to photobucket.  ::)  I made this quck image for my own purposes.  (As in, i wont remember in a month  ;) )

(http://i1082.photobucket.com/albums/j364/nlapensee773/Mach/th_Dro-settingvariables.jpg) (http://s1082.photobucket.com/user/nlapensee773/media/Mach/Dro-settingvariables.jpg.html)
Title: Re: Read write to a DRO ??
Post by: poppabear on May 30, 2014, 08:12:09 PM
*** reposted from the bug thread...

Terry,

Place a "dro" on your screen, the User Dro you want, for this example Name it:  UDRO20 in its properties window.

then in a button, put this code:

   local inst = mc.mcGetInstance();
   local rc = 0;
   local MyVarVal = 0;
   local MyStgVal = "";

   MyVarVal, rc  = mc.mcCntlGetPoundVar(inst, 590);

   if rc ~= 0 then
      mc.mcSetMachError(inst, "get # err");
   else
      MyStgVal = tostring(MyVarVal);
      rc = scr.SetProperty('UDRO20', 'Value',  MyStgVal );--sets your UDRO to your Param value on the push
   end

--the opposite procedure would go the other way, load your User Dro to your param...
--further, if you want these two things to happen as mach runs automatically, drop them in the PLC scripter, but PLEASE make --sure they run without error before you do

--Scott

Simpson36,

     I did publish some down and dirty "User Manual" for McLua stuff............  while true I am not the "OEM" picked to do an official manual, it should serve to get ya started.

Scott
Title: Re: Read write to a DRO ??
Post by: BR549 on May 30, 2014, 09:34:19 PM
Scott could you show an example of the reverse ??

I have been trashing with it sense your earlier response with no luck. I cannot even get this to work. It wants num,num,num  and says I am giving it num,num,string  I have tried about 20 differrnt ways with no luck so far


mc.mcCntlSetPoundVar(inst, 590,123456);
Title: Re: Read write to a DRO ??
Post by: BR549 on May 30, 2014, 10:22:36 PM
OK i am down to basics here

local inst = mc.mcGetInstance();

SNv  = scr.GetProperty('UDRO20', 'Value' );
wx.wxMessageBox( SNv)

--- At this point I do NOT get a value for the SNv. It is empty no 0 nothing so there is nothing to pass on  AND what there is is a STRING value format.

 mc.mcCntlSetPoundVar(inst, 590, 'SNv' );

-- This call WANTS a number value NOT a string  (SNv). HOW do I conver the string into a NUMBER before I feed it into the call.

 wx.wxMessageBox( SNv)  
  
Title: Re: Read write to a DRO ??
Post by: Ya-Nvr-No on May 30, 2014, 10:32:07 PM
 --read
    local inst = mc.mcGetInstance();
     local varvalue;
     local val = 0;
     varvalue = mc.mcProfileGetDouble(inst , 'drovar1' , '1', val)
     mc.mcCntlSetPoundVar(inst, 1, varvalue)

--write
     local inst = mc.mcGetInstance();
     varvalue = mc.mcCntlGetPoundVar(inst, 1);
     mc.mcProfileWriteDouble(inst ,'drovar1','1',varvalue)

--getpound setdro
     local inst = mc.mcGetInstance();
    varvalue = mc.mcCntlGetPoundVar(inst, 1);
    scr.SetProperty('drovar1', 'Value', tostring(varvalue));
Title: Re: Read write to a DRO ??
Post by: BR549 on May 30, 2014, 10:58:45 PM
Thnaks Craig I will chew on that.

Here I try it this way BUT it does not make sense of what happens

local inst = mc.mcGetInstance();
SN = "987654"
    wx.wxMessageBox( SN)

    --SNv  = scr.GetProperty('UDRO20', 'Value' );
    --wx.wxMessageBox( SNv)

SNv = tonumber(SN)

wx.wxMessageBox( SNv)

--ERROR::  wxLua: Expected a 'string' or 'wxString' for parameter 1, but got a 'number'.

--OK Lua says that SNv IS a number RIGHT ? GREAT we are set(;-) BUT not so fast buckshot

 mc.mcCntlSetPoundVar(inst, 590, 'SNv' );

--THis call errored with wxLua: Expected a 'number' for parameter 3, but got a 'string'.
--HOW can "SNv" be a number and a String at the same time?  I don't get it.

 wx.wxMessageBox( "Complete")   
   

Title: Re: Read write to a DRO ??
Post by: poppabear on May 30, 2014, 11:08:50 PM
no,

 --SNv  = scr.GetProperty('UDRO20', 'Value' );
    --wx.wxMessageBox( SNv)

the reason your getting an error is your GetProperty of value, returns a Number so your SNv is a number,
wx.wxMessageBox needs SNv to be a string so........

SNv  = scr.GetProperty('UDRO20', 'Value' );
wx.wxMessageBox( tostring(SNv));

Scott
Title: Re: Read write to a DRO ??
Post by: BR549 on May 30, 2014, 11:24:02 PM
SCOTT I understand that I used the Messagebox to TEST the VALUES as to IF it is a Number or String  IF it excepts the value it is a string otherwiise the error tells you it is a number.


Craig this does not work here. It sets the #var 590 to 0.0000 when the DRO value is 112233.0000

local inst = mc.mcGetInstance();
     local varvalue;
     local val = 0;
     varvalue = mc.mcProfileGetDouble(inst , 'Udro20' , '590', val)
     mc.mcCntlSetPoundVar(inst, 590, varvalue)
Title: Re: Read write to a DRO ??
Post by: BR549 on May 30, 2014, 11:44:59 PM
HIYA Craig, THis works correctly THANK YOU very much. Just a though one should not use #1 as #vars 1-34 are local Vars reserved for G65 mcaro calls. YANEVERKNOW what you may get in return when used outside of the G65 call.  (;-)

--getpound setdro
     local inst = mc.mcGetInstance();
    varvalue = mc.mcCntlGetPoundVar(inst, 590);
    scr.SetProperty('Udro20', 'Value', tostring(varvalue));
Title: Re: Read write to a DRO ??
Post by: BR549 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
Title: Re: Read write to a DRO ??
Post by: Bodini 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.

Title: Re: Read write to a DRO ??
Post by: BR549 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
Title: Re: Read write to a DRO ??
Post by: BR549 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
Title: Re: Read write to a DRO ??
Post by: BR549 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
Title: Re: Read write to a DRO ??
Post by: poppabear 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
Title: Re: Read write to a DRO ??
Post by: BR549 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


Title: Re: Read write to a DRO ??
Post by: BR549 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
Title: Re: Read write to a DRO ??
Post by: smurph 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

Title: Re: Read write to a DRO ??
Post by: BR549 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
Title: Re: Read write to a DRO ??
Post by: BR549 on June 02, 2014, 03:57:20 PM
Here is the answer to THAT question(;-)

local Pword = "FrogLog"
local Pnum = 0

while Pnum <3 do
local Panswer = wx.wxGetPasswordFromUser("What is the Password ? ")
if Panswer == Pword then
            wx.wxMessageBox("The Password is " ..Panswer)
else
            wx.wxMessageBox("Wrong Password")
            Pnum =(Pnum+1)
    end

 end
wx.wxMessageBox(" Call YOUR Supervisor for HELP! ") 
Title: Re: Read write to a DRO ??
Post by: machiner on September 22, 2014, 04:21:37 PM
sorry to 'interrupt'  but i have a question about . . .

re : drop them in the PLC scripter . . .


where is this 'scripter'.

on my system i can READ the lua script under the operator menu  , but can't find it with the LUA editor.
Title: Re: Read write to a DRO ??
Post by: smurph on September 22, 2014, 06:20:54 PM
Edit the screen set and click on the top item in the tree.  Then click on the event icon in the properties.  It will let you edit the PLC script.

Steve
Title: Re: Read write to a DRO ??
Post by: machiner on September 23, 2014, 09:00:49 AM
thanks for info on writing to PLC script

if they published Mach4 for Dummies, i would have to buy  . . .
Title: Re: Read write to a DRO ??
Post by: machiner on September 23, 2014, 02:04:31 PM
re: PLC Script
thanks again for the hint. 
i owe you and many others here a big 'Thank You'

Say . . .if someone was so dumb , that they saved a PLC script with a bug in it  (lets say an endless loop with a wxMessageBox command)
of course i  know the program would lock up , and the backups would not work for some reason.
how would they locate that file to destroy it , or edit it.

of course that person would have looked everywhere and opened everything with no luck  . .  .
would that dummy have any way to stop the PLC script ?
Title: Re: Read write to a DRO ??
Post by: Ya-Nvr-No on September 23, 2014, 02:22:20 PM
looks like your not one to read all the fine details I and others have posted, lol

http://www.machsupport.com/forum/index.php/topic,27162.msg191822.html#msg191822


but you might also try a adding a     -e   to the end of the autoload  it goes into the edit mode first.

C:\Mach4Hobby1953\Mach4GUI.exe /p Mach4Mill -e
Title: Re: Read write to a DRO ??
Post by: smurph on September 23, 2014, 02:23:13 PM
That is truly the definition of getting stuck between a rock and a hard place.  :)

Start Mach4GUI in edit mode.  Mach4GUI /p <ProfileName> /e

Replace ProfileName with the name of your profile.  
Title: Re: Read write to a DRO ??
Post by: machiner on September 24, 2014, 08:28:37 AM
thanks, that did it.