Hello Guest it is May 09, 2021, 09:03:42 PM

Author Topic: Lua Script and reading register's Help  (Read 665 times)

0 Members and 1 Guest are viewing this topic.

Re: Lua Script and reading register's Help
« Reply #10 on: January 21, 2021, 05:14:59 PM »
What values are you getting for Phreg and Ehreg (from your message boxes)? My guess is you're not getting a valid reg handle (hreg) in your if statement, which causes mc.mcRegGetValue(hreg) to return 0.0.

Also, tonumber() returns the string converted to a number, so you'd need to do something like:
Code: [Select]
Phreg = tonumber(Phreg)
Re: Lua Script and reading register's Help
« Reply #11 on: January 23, 2021, 08:53:19 AM »
Man I had a hard time finding this thread!
Anyway, Gary  Good news your problem with your crashing after edit was found! It was an error in the wxTranslation code so you could localization on your screen. Not that your ever going to do that for yourself :) . Because you didn't have the file it was causing a pointer to go out in memory and stomp on memory! On my PC it will messing with my OpenGL and crashing the machine. Steve found the issue (took days and he is REALLY good) and he patched it up and rebuilt the libs. So next version you should be all good. The latest Dev version has what you need if you want to try it. Wanted everyone to know it was fixed and that you helped to delay release LOL . We have started release testing over AGAIN because of this. The QA part of getting software out takes longer than making the code I think! Mach4 is a MASSIVE project with so many ways to use / customize it that it takes a lot of pokes to see if everything is working as it should.

Okay I have rambled enough, long story longer , check out the new version.
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com

Offline gorf23

*
  •  165 165
    • View Profile
Re: Lua Script and reading register's Help
« Reply #12 on: January 23, 2021, 02:11:14 PM »
Thanks Brian

Glad you found it, I know how had it is to fine crap in the code, i'm always having problems with simple scripts...

And to jbuehn

I think i have found a way to get it working I changed the if,  to something like this below  and put this code in a function, that returns the hreg value and it seems to working so far at least with the pokeys57CNC, i am going to try it on the ESS tomorrow and see how that go's.
   
if  (mc.mcRegGetHandle(inst,"PoKeys_40548/PoKeysConnected") == 1)  then               -- The Pokeys57CNC Connected register   

Thanks gary

Offline gorf23

*
  •  165 165
    • View Profile
Re: Lua Script and reading register's Help
« Reply #13 on: January 24, 2021, 05:36:09 PM »
Just an update

It does work with both the pokeys and ESS so looks good now...

I tested a new plugin last week for the pokeys and looks like the register values are working for probing like the ESS now..
Don't know when it will be posted for download, but looks good anyway...

Gary

Offline gorf23

*
  •  165 165
    • View Profile
Re: Lua Script and reading register's Help
« Reply #14 on: January 31, 2021, 02:56:11 PM »
Brian Think this one you maybe to answer.?

So i am reading the register for the value 's to see if the ESS or pokeys are running. Works fine but i have to do it in all my button calls or macros..

Can i read the register once and store the value in a global variable from the PLC or the screen load script?. and use it everywhere.
Do the plugins load before the PLC and screen load script? and are the registers set first.

I tried it in the PLC but wasn't getting the correct global value if i then checked it in a button script.

Thanks Gary
Re: Lua Script and reading register's Help
« Reply #15 on: February 01, 2021, 06:14:59 AM »
The registers are your global variables and can be seen from all instance of Lua and they are also thread safe.
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com

Offline gorf23

*
  •  165 165
    • View Profile
Re: Lua Script and reading register's Help
« Reply #16 on: February 01, 2021, 07:28:02 PM »
Brian

I think i understand that part, what i am trying to do is set a flag once of my own var, and just use that var everywhere in in my buttons and macros
so i don't have to read the registers in all my buttons and macros, i just set the var once in the screen load script or the plc and then i don't have to write the code to read the same register in all my scripts, once the register is set when Pokeys or ESS plugin is loaded it will not change endless you swap controllers..

Hope it makes more sense i do have a hard time explaining my thoughts !, most likely old age

Thanks gary   
Re: Lua Script and reading register's Help
« Reply #17 on: February 01, 2021, 08:33:26 PM »
The screen script is global, you will have to check when you open. New chunk. I don’t think I understand :( sorry I don’t think I am helping ..
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com

Offline gorf23

*
  •  165 165
    • View Profile
Re: Lua Script and reading register's Help
« Reply #18 on: February 02, 2021, 12:36:48 PM »
Thanks Brian

I don't think its you but more likely my explanation...

Here is a sample of the code it only needs to run once, and the hreg and probestate values global. so i can use anytime..
of course there will be no return's needed

Code: [Select]
function myZprobe.ConnectedDevice()
local hreg = 0
local ProbeState = 0
local Ereg  = mc.mcRegGetHandle(inst,"ESS/Connected")
local Preg = mc.mcRegGetHandle(inst,"PoKeys_40548/DeviceConnected")
if (mc.mcRegGetValue(Preg) == 1) then
     hreg  = mc.mcRegGetHandle(inst,"PoKeys_40548/ProbeStatus")
ProbeState = -4
return hreg, ProbeState
      elseif (mc.mcRegGetValue(Ereg) == 1) then
       hreg  = mc.mcRegGetHandle(inst,"ESS/Probing_State")
   ProbeState = -1
   return hreg, ProbeState
end
end


Thanks gary
Re: Lua Script and reading register's Help
« Reply #19 on: February 02, 2021, 01:31:47 PM »
You want to have something that will run one time at startup ... We can do that many ways. A global screen var saying that you have doneInit = false and set it to true when you have done it. Then you will never run it again. Also you can do a scr.IsLoaded() to make sure that the screen set is fully up.
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com