Hello Guest it is March 28, 2024, 11:03:52 AM

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

0 Members and 1 Guest are viewing this topic.

Offline BR549

*
  •  6,965 6,965
    • View Profile
Read write to a DRO ??
« 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))

Offline Bodini

*
  •  216 216
    • View Profile
Re: Read write to a DRO ??
« Reply #1 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  ;) )

« Last Edit: May 30, 2014, 07:49:59 PM by Bodini »

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Read write to a DRO ??
« Reply #2 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
fun times

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Read write to a DRO ??
« Reply #3 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);

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Read write to a DRO ??
« Reply #4 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)  
  
Re: Read write to a DRO ??
« Reply #5 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));
« Last Edit: May 30, 2014, 10:35:43 PM by Ya-Nvr-No »

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Read write to a DRO ??
« Reply #6 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")   
   

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Read write to a DRO ??
« Reply #7 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
fun times

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Read write to a DRO ??
« Reply #8 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)

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Read write to a DRO ??
« Reply #9 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));
« Last Edit: May 30, 2014, 11:48:39 PM by BR549 »