Hello Guest it is April 18, 2024, 11:49:47 PM

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

0 Members and 1 Guest are viewing this topic.

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #20 on: December 07, 2016, 02:57:02 AM »
Chaotione is right, lose the Number it should be just hReg, and also moving to havin a function in the screen load script would be much cleaner, it could be called from the dro update with (axis,lcd) and also set to run on 1st loop of the plc.

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #21 on: December 07, 2016, 08:33:28 AM »
Yeah that was a cut and paste error I only had hreg in the actual code.  I will play with this stuff again this morning.  Thanks

RUss
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #22 on: December 07, 2016, 08:36:49 AM »
Daz,
I did not actually have the number in the real code just hreg.  As soon as I get it to blank a line on the screen correctly, I will modify what is current in the dro update code and move that to screen load and have dro update code call that code.  I am not sure how to do the PLC aspect for one time do you just put a loop counter inside the PLC script?

I will confirm the details as soon as I get a line on the LCD to clear.  The current code does update the LCD correctly so now I have all three axis update when running gcode or jogging.

Russ
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #23 on: December 07, 2016, 09:23:22 AM »
Guys,

Here is the code that actually works to clear a line on the LCD.

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

You can use mcRegSetValue and then try and send a string that just gives LUA errors.

I also tried other variations to clean it up for a function and they failed.

I tried, but this gives a LUA error when executed.

local clrlcd = "                  "

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

I also tried to get the handle as follows in lines above the actual setvaluestring code.  But this approach also fails.

local hlcd1, rc = mc.mcRelogGetHandle(inst, string.format("PoKeys_32062/LCD Line 1"))
                       mc.mcRegSetValueString(hlcd1, "                    ")


LUA seems to be very picky about certain things.  I wrote in C for years and things that worked in C do not work in LUA.  So this is a big learning experience.

Now that I have some code to clear a line on the LCD I will attempt to turn this into a function in the screen load script.

Really appreciate your help guys.

Russ


« Last Edit: December 07, 2016, 09:27:02 AM by cncman172 »
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #24 on: December 07, 2016, 11:33:30 AM »
Chaoticone, DazTheGas

I wrote an LCD initialize function in the Screen load script.   Guys thanks for all your suggestions, hopefully this will help anyone else attempting to get an LCD to work with a pokeys device.

Russ


--------------------------------------------------------------
-- 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

Then I added a function call in the PLC script that runs one time.  This basically clears the screen and shows each axis set at 0.0000, and if something other than 0.0000 was saved when you exit Mach4 it updates that when the machine comes up so this is working much better.  I can probably clean up the xDRO update scripts and do all of that in the screen load script as Daz suggested as well.

for name,number in pairs (DROTable) do -- for each paired name (key) and number (value) in the DRO table
        local droName = (DROTable[name]) -- make the variable named droName equal the name from the table above
        --wx.wxMessageBox (droName)
        local val = mc.mcProfileGetString(inst, "PersistentDROs", (droName), "NotFound") -- Get the Value from the profile ini
        if(val ~= "NotFound")then -- If the value is not equal to NotFound
            scr.SetProperty((droName), "Value", val) -- Set the dros value to the value from the profile ini
        end -- End the If statement
    end -- End the For loop
    ---------------------------------------------------
    YPenLCD() -- initialize the Yaskawa LCD display when you first start.

end
-------------------------------------------------------

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #25 on: December 07, 2016, 03:21:09 PM »
Good, glad your making progress.

This might work too.

Put this in your screen load script....

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

This in you PLCs first run....
YPenLCD(X, 1)
YPenLCD(Y, 2)
YPenLCD(Z, 3)
YPenLCD(A, 4)

This in your X DRO update event.......
YPenLCD(X, 1)

This in your Y DRO update event.......
ThiYPenLCD(Y, 2)

etc, ect. for Z and A DROs
;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 #26 on: December 07, 2016, 03:41:53 PM »
Chaoticone,

Thanks, actual this was next on my agenda.  LOL   Passing the axis and line int he function is a great idea.  The only thing not working on the pendant at this point is the LED matrix, which apparently in a bug in the pokeys plugin for Mach4.  I will get this implemented and then let you know if all works as expected.  Thanks again you are fantastic.

Russ

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #27 on: December 08, 2016, 05:47:58 PM »
NP, that may not be exactly right (I did not get to test it) but you get the idea. Would make it a lot cleaner.
;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 #28 on: December 11, 2016, 04:07:34 PM »
Chaoticone,
I did not get a chance to test it this weekend was gone out of state for the last four days.  Will get this all tested tomorrow after I recover from my trip.  LOL

Russ
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #29 on: December 15, 2016, 04:34:31 PM »
Chaoticone,

Well I tested your suggestion and what happens is each line of the LCD gets updated with

nil:
nil:
nil:
nil:

Seems like it is putting the nil return value on the screen.  This must be the line of code that is causing the issue.  You ask for the property of the droCurrent and that must be return Value of nil would be my guess.

Russ



 local CurPos = scr.GetProperty("droCurrent" .. tostring(Axis), "Value")