Hello Guest it is April 19, 2024, 05:17:44 AM

Author Topic: Pokeys Mach4 plugin LUA reference for LCD  (Read 26714 times)

0 Members and 1 Guest are viewing this topic.

Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #50 on: March 14, 2019, 02:46:35 PM »
Hi,

I went to the Screen Editor, clicked on the X DRO value – the variable droCurrentX highlighted on the LHS. Then I clicked on Properties -> Events, went to RHS (….) of On Update Script, then a new Lua file opened.
I typed the following code in this new LUA file:
local inst = mc.mcGetInstance()
local Xcoords = scr.GetProperty("droCurrentX","Value")
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_Lathe"))
mc.mcRegSetValueString(hreg, tostring(Xcoords))
where PoKeys_Lathe is the name of my Pokeys57 card.

I then saved and exited the screen editor. After enabling Mach4 I moved the X-axis – the axis moved as before but the DRO X stayed constant on the value displayed previously. Fur debugging purposes I removed lines 2 to 4 (leaving only local inst = mc.mcGetInstance()) but the problem persisted.

At this point I'm stuck, any help will be very much appreciated,

Kind regards

Danie
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #51 on: March 16, 2019, 04:36:12 AM »
Hi,

same effect to me...

Even 2 hyphens as comment in this code section of the On Update Scripts are inhibiting the update of the DRO values. It seems, that this is a more as a matter of principle.
At the moment I'm working with Mach4Home build 4095 which is licensed.

Maybe some of the experts have an idea what could be wrong?

Thank you in advance,

Kind regards
Wolfgang
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #52 on: March 20, 2019, 09:25:04 AM »
Hello all,

Try adding the code below (thanks to Brett for the code!) to your On Update Script, with your custom stuff in the middle:


local val = select(1,...) -- Get the system value.
val = tonumber(val) -- The value may be a number or a string. Convert as needed.

--Do your stuff here
local inst = mc.mcGetInstance()
mc.mcCntlSetLastError(inst, "On update ran")

return val -- the script MUST return a value, otherwise, the control will not be updated.

^^ that last line is the most important. This was tested in our latest development version (4124) and worked like a dream, though you will need to add in your custom scripts and test it with your setup as well.

Hope that helps!

-Bryanna
Newfangled Solutions Helpdesk: http://support.machsupport.com
YouTube Support Channel: https://www.youtube.com/c/MachSupportOfficial
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #53 on: March 22, 2019, 11:23:07 AM »
Hello,

with the recommendations of Bryanna the output of the DRO to the LCD of the PoKeys is working.

What I've found is the fact, that the values on the LCD are lagging the DRO values when I use this code:
local Xcoords = scr.GetProperty("droCurrentX","Value")

The correct value which is identical to the DRO on screen is val by itself.
So we can simply write:
local Xcoords = val

Sometimes the changes in the On Update Script are showing no effect after saving and leaving the editor.
Only when closing and restarting Mach4 the changes in the code where recognized.

Hope this is of help for somebody.

Wolfgang


Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #54 on: March 24, 2019, 04:26:11 AM »
Dear All,

Thank you for all your help thus far.

As indicated above, starting and ending the Update Script (droCurrentX) in the correct way seems to be very important. I replaced my initial code with the following:

local val = select(1,...)
val = tonumber(val)
local inst = mc.mcGetInstance()
local Xcoords = val
local hreg = mc.mcRegGetHandle(inst,string.format("Pokeys_Lathe/LCD Line 1"))
mc.mcRegGetValueString(hreg,tostring(Xcoords))
return val

Now when I move the axis of the lathe, the droCurrentX continuously update on my Mac4 screen but my LCD still only indicates "Pokeys for Mach4" - thus the register does not seem to be updating? But when I go to Diagnostic -> RegFile -> Pokeys_Lathe - LCD Line 1, I am able to enter a value and the value is displayed on the 1st line of my LCD.

Any suggestions will be highly appreciated,

Kind regards Danie


Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #55 on: March 27, 2019, 12:01:44 PM »
Hello Danie,

the code  of the On Update Script which is working seemlessly on my machine looks like here:

local val = select(1,...)
Xcoords = val
val = tonumber(val)
local inst = mc.mcGetInstance()
mc.mcCntlSetLastError(inst, "On update ran")
local Xcoords = string.format("X:% 10.4f", Xcoords)
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_34497/LCD Line 1"))
mc.mcRegSetValueString(hreg, Xcoords.."        ")
return val

Not too much differences to your code. Maybe this helps a little.

Kind regards
Wolfgang

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #56 on: March 28, 2019, 01:31:53 AM »
What version of Mach4 are you running?

The reason I ask is DROs have had the capacity to be linked to a register in Dev. versions for a while. That would eliminate the need for any of the code if I'm not overlooking something. Linking it in the screen if the DRO value changes the register updates. If the register value changes it updates the DRO. If your just doing a one-one no code needed. The only time you need to do and scripting to write to the register would be if you wanted to do some math or formatting or something.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #57 on: March 28, 2019, 01:23:19 PM »
At the moment I'm using Build 4132.

Kind regards,
Wolfgang

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #58 on: March 28, 2019, 01:54:26 PM »
At the moment I'm using Build 4132.

Kind regards,
Wolfgang

OK, try this. Comment out all of your on update and on modify script for that DRO. In the properties tab for that DRO towards the bottom of the list you will see Register. Use the dropdown to select the register you want the DRO linked to. Should be all there is to it.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #59 on: March 28, 2019, 02:38:27 PM »
Did what you recommended. I've completely removed the code in the On Update Script and linked the DRO register to the PoKeys LCD register from the drop down list. But the LCD doesn't update when moving the axis.