Hello Guest it is November 09, 2024, 12:15:41 PM

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

0 Members and 1 Guest are viewing this topic.

Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #40 on: January 01, 2018, 08:49:30 AM »
YES, I got it all working correctly.  I will post the code shortly, have to run out to the shop and look at the code.  Forgot exactly been a few days.  LOL

Russ
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #41 on: January 01, 2018, 09:19:45 AM »
Great, thank you :-)
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #42 on: January 01, 2018, 06:52:03 PM »
Sorry for the delay been buried in College Football today.  LOL


LUA Code for X DRO

local inst = mc.mcGetInstance()
local Xcoords = scr.GetProperty("droCurrentX", "value")
local hreg = mc.mcRegGetHandle (inst, string.format("Pokeys_32062 / LCD Line 1"))
Xcoords = string.format("X: %4.4f", Xcoords)
mc.mcRegSetValue(hreg, tostring (Xcoords).. "     ")


LUA Code for Y DRO

local inst = mc.mcGetInstance()
local Ycoords = scr.GetProperty("droCurrentY", "value")
local hreg = mc.mcRegGetHandle (inst, string.format("Pokeys_32062 / LCD Line 2"))
Ycoords = string.format("Y: %4.4f", Ycoords)
mc.mcRegSetValue(hreg, tostring (Ycoords).. "     ")



LUA Code for Z DRO

local inst = mc.mcGetInstance()
local Zcoords = scr.GetProperty("droCurrentZ", "value")
local hreg = mc.mcRegGetHandle (inst, string.format("Pokeys_32062 / LCD Line 3"))
Zcoords = string.format("Z: %4.4f", Zcoords)
mc.mcRegSetValue(hreg, tostring (Zcoords).. "     ")





Here is the code that goes in the main LUA loop

--------------------------------------------------------------
-- Yaskawa Pendant Clear LCD Display
--------------------------------------------------------------
function YPenLCD()
        local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_32062/LCD Line 1"))
        mc.mcRegSetValueString(hreg, "X:  0.0000          ")  -- X zero display
        local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_32062/LCD Line 2"))
        mc.mcRegSetValueString(hreg, "Y:  0.0000          ")  -- Y zero display
        local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_32062/LCD Line 3"))
        mc.mcRegSetValueString(hreg, "Z:  0.0000          ")  -- Z zero display
        local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_32062/LCD Line 4"))
        mc.mcRegSetValueString(hreg, "A:  0.0000          ")  -- A zero display
end

--function YPenLCD(Axis, Line)
--    local CurPos = scr.GetProperty("droCurrent" .. tostring(Axis), "Value")
--    CurPos = string.format("%4.4f", CurPos)
--    local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_32062/LCD Line " .. tostring(Line)))
--    mc.mcRegSetValueString(hreg, string.format(tostring(Axis) .. ":  " .. tostring(CurPos) .. "          "))
--end


Russ
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #43 on: January 02, 2018, 02:12:27 PM »
I know where to ad the DRO code, but need a hint about how to insert in the Lua main loop (novise when it comes to Mach4 scripting..)
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #44 on: January 02, 2018, 03:15:47 PM »
The first thing you do is go the the OPERATOR tab at the top of the Mach4 screen, then select "LUA SCRIPT"  it is about the forth or fifth item on the list under Operator.

This will show you the current LUA code you are running.

I have attached my code, the entire script was designed to put the DROs on my LCD inside my Yaskawa pendant.  You will not need lots of this code, but if you print this out and highlight the sections that update the LCD display you will understand what you need to add to your LUA script.  Back up your initial script before you make any changes, that way you can always go back.

The other item I should have mentioned on my DRO update code you need to change the serial number to the serial number of your POKEYS device.  You can find that under diagnostics screen you will find the POKEYS device listed.


Hope this helps.


Russ
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #45 on: January 06, 2019, 04:07:51 PM »
Hi,

I have similar problems trying to display the X and Z DRO readings on a 4x20 LCD display. I'm running a Pokeys57 card with Mach4. At start-up the LCD does display "Pokeys plugin for Mach4" and I have done all the basic checks to ensure the LCD is working.
In the screen script for the X DRO I have placed:

local inst = mc.mcGetInstance()
local Xcoords = scr.GetProperty("droCurrentX", "value")
local hreg = mc.mcRegGetHandle (inst, string.format("Pokeys_Lathe / LCD Line 1"))
Xcoords = string.format("X: %4.4f", Xcoords)
mc.mcRegSetValue(hreg, tostring (Xcoords).. "     ")

However, when I enable and run Mach4, and jogging the X axis the axis move but the X DRO stays fixed at 0.00 and I get the error message:

C:\Mach4Hobby\ScreenScript.lua 764
Bad argument #2 to 'format' (number expected, got string)
stack traceback:
[C]:\Mach4Hobby\ScreenScript.lua:764 in function C:\Mach4Hobby\ScreenScript.lua760

I have to remove the code, not only comment it out, to get the X DRO going again.

Any help will be greatly appreciated.

Danie
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #46 on: January 07, 2019, 08:20:39 AM »

This line just gets you the handle, where is the code that populates the string?

local hreg = mc.mcRegGetHandle (inst, string.format("Pokeys_Lathe / LCD Line 1"))


This line populates the Xcoords with a string.
Xcoords = string.format("X: %4.4f", Xcoords)


I am running to catch a plan this morning but will respond again with the complete program, you have something wrong...

Russ
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #47 on: January 07, 2019, 09:08:03 AM »
Hi Russ,

I'm still very new to Lua programming - your help is very much appreciated.

Thanks Danie
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #48 on: January 14, 2019, 09:19:00 AM »
Hi Russ,

I still have my set of problems to get the LCD going correctly.
If I place the simpler code as a Lua script attached to the “droCurrentZ” the following happens:

local inst = mc.mcGetInstance()

local Xcoords = scr.GetProperty("droCurrentX","Value")
local Zcoords = scr.GetProperty("droCurrentZ","Value")

local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_Lathe/LCD Line 1"))
mc.mcRegSetValueString(hreg, tostring(Xcoords))

local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_Lathe/LCD Line 3"))
mc.mcRegSetValueString(hreg, tostring(Zcoords))

The droCurrentX is displayed and updated on the LCD every time the Z axis is moved (this behaviour does make sense to me);
The droCurrentZ is displaying a zero value, even if the Z axis are moved around(?)

Then I removed all the code except for:

local inst = mc.mcGetInstance()

This line seems to be causing the droCurrentZ to be kept at zero. This is difficult for me to understand.

If I use the same lines of code above  in the droCurrentX script the effect of X and Z is reversed.

Thanks Danie
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #49 on: March 04, 2019, 08:01:33 AM »
Hi,

got to implement all the code for outputting the axis DRO values to the Pokeys56U LCD. But the values of the axis DROs and the LCD are updated only once when the axis are moved and no error messages apeared. What could be the reason for this effect?

Any help is appreciated

Kind regards
Wolfgang