Hello Guest it is March 28, 2024, 12:18:11 PM

Author Topic: PoKeys 57U, Mach4, Buttons and you.  (Read 2873 times)

0 Members and 1 Guest are viewing this topic.

PoKeys 57U, Mach4, Buttons and you.
« on: December 26, 2018, 06:32:40 PM »
Hey guys - n00b here. So, first, I tried the search function and didn't come up with anything since it's apparently broken. I did google it, and found a thread with what appears to be exactly what I need, but can't get to the thread. ugh.

So... first off, I am relatively 'technical', but LUA is confusing.

I am looking to map signals via Pokeys 57U to physical buttons for the normal stuff, like coolant/mist on/off, spindle etc. I have the simple stuff working - like cycle start/stop. I am 100000% certain this has been covered, but again, with the broken search - it's nearly impossible to locate. I'm hoping someone has a link saved, etc.

BTW, I have the PoBlog link and that got me started, but it seems very generic. If I had a working script in front of me, I could dissect and reassemble for my setup.

TIA

 -Brooks

Offline ZASto

*
  •  423 423
    • View Profile
Make no mistake between my personality and my attitude.
My personality is who I am.
My attitude depends on who you are.

Offline thosj

*
  •  532 532
    • View Profile
Re: PoKeys 57U, Mach4, Buttons and you.
« Reply #2 on: December 27, 2018, 06:11:57 PM »
Here's some code for you! You'll need to setup your inputs in your device settings and Mach4 settings then code like this goes in the Screen Start script in the Signal Library section. I included ALL of mine, but it should give you a clue where to start. There's coolant/mist, spindle on, setting speed to 1000 (Mach4 doesn't remember the last speed when shut down so this is a work around for me trying to start the spindle with no speed set!!!) It's commented so you should be able to figure some stuff out for the basics.

Tom

Code: [Select]
---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    ButtonEnable()
end,

-- PoKeys pin 9, Mach4 Input 0
-- Physical Cycle Start Button
[mc.ISIG_INPUT0] = function (state)
    if (state == 0) then
        CycleStart()
    end
end,

-- PoKeys pin 10, Mach4 Input 1
-- Physical Feed Hold Button
[mc.ISIG_INPUT1] = function (state)
    if (state == 1) then
        mc.mcCntlFeedHold (0)
    end
end,

-- PoKeys pin 11, Mach4 Input 2
-- Physical Stop Button
[mc.ISIG_INPUT2] = function (state)
    if (state == 1) then
        CycleStop()
    end
end,

--PMDX-108 Port 2 Pin 6 Mach4 Input 10
--HLFB_X ERROR
[mc.ISIG_INPUT10]= function(state)
    if (state==1) then
          mc.mcCntlCycleStop(inst)
          mc.mcCntlSetLastError(inst, "HLFB_X Servo Error")
    end
end,

--PMDX-108 Port 2 Pin 7 Mach4 Input 11
--HLFB_Y ERROR
[mc.ISIG_INPUT11]= function(state)
    if (state==1) then
          mc.mcCntlCycleStop(inst)
          mc.mcCntlSetLastError(inst, "HLFB_Y Servo Error")
    end
end,

--PMDX-108 Port 2 Pin 8 Mach4 Input 12
--HLFB_A ERROR
[mc.ISIG_INPUT12]= function(state)
    if (state==1) then
          mc.mcCntlCycleStop(inst)
          mc.mcCntlSetLastError(inst, "HLFB_A Servo Error")
    end
end,

--PMDX-108 Port 2 Pin 9 Mach4 Input 13
--HLFB_Z ERROR
[mc.ISIG_INPUT13]= function(state)
    if (state==1) then
          mc.mcCntlCycleStop(inst)
          mc.mcCntlSetLastError(inst, "HLFB_Z Servo Error")
    end
end,

----------Mach4 Input 17 PoKeys Pin 17-----
----------Toggle Coolant M8----------------
[mc.ISIG_INPUT17] = function (state)
if (state == 1) then
     local inst = mc.mcGetInstance();
     local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_COOLANTON);
     local sigState = mc.mcSignalGetState(sigh);
     if (sigState == 0) then
         local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
         mc.mcSignalSetState(OSigCool,1)
         mc.mcCntlSetLastError(inst, "Coolant On")
     else
         local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
         mc.mcSignalSetState(OSigCool,0)
         mc.mcCntlSetLastError(inst, "Coolant Off")
     end
end
   
end,

----------Mach4 Input 14 PoKeys Pin 14--
----------Toggle Mist M7----------------
[mc.ISIG_INPUT14] = function (state)
if (state == 1) then
     local inst = mc.mcGetInstance();
     local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_MISTON);
     local sigState = mc.mcSignalGetState(sigh);
     if (sigState == 0) then
         local OSigMist = mc.mcSignalGetHandle (inst,mc.OSIG_MISTON)
         mc.mcSignalSetState(OSigMist,1)
         mc.mcCntlSetLastError(inst, "Mist On")
     else
         local OSigMist = mc.mcSignalGetHandle (inst,mc.OSIG_MISTON)
         mc.mcSignalSetState(OSigMist,0)
         mc.mcCntlSetLastError(inst, "Mist Off")
     end
end
   
end,

------------Mach4 Input 8 PoKeys Pin 8----------------
------------Toggle SpinCW-----------------------------
[mc.ISIG_INPUT8] = function (state)
if (state == 1) then
     local inst = mc.mcGetInstance();
     local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
     local sigState = mc.mcSignalGetState(sigh);
     if (sigState == 1) then
         mc.mcSpindleSetDirection(inst, 0);
     else
         SpinCW()
     end
end

end,

------------Mach4 Input 7 PoKeys Pin 7------------
------------Set S1000-----------------------------
[mc.ISIG_INPUT7] = function (state)
    if (state == 1) then   
        mc.mcCntlGcodeExecuteWait(inst, "S1000");
mc.mcCntlSetLastError(inst, 'Speed Set to 1000')
    else
        --mc.mcCntlFeedHold (0)
    end

end,

--sample input use that was originally in here!!
[mc.ISIG_INPUT60] = function (state)
   -- if (state == 1) then   
--        CycleStart()
--    --else
--        --mc.mcCntlFeedHold (0)
--    end

end,
--
Tom
Re: PoKeys 57U, Mach4, Buttons and you.
« Reply #3 on: December 27, 2018, 09:28:40 PM »
Awesome! Thanks a million guys!
Re: PoKeys 57U, Mach4, Buttons and you.
« Reply #4 on: March 24, 2019, 09:37:33 AM »
Here's some code for you! You'll need to setup your inputs in your device settings and Mach4 settings then code like this goes in the Screen Start script in the Signal Library section. I included ALL of mine, but it should give you a clue where to start. There's coolant/mist, spindle on, setting speed to 1000 (Mach4 doesn't remember the last speed when shut down so this is a work around for me trying to start the spindle with no speed set!!!) It's commented so you should be able to figure some stuff out for the basics.

Tom

Code: [Select]
---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    ButtonEnable()
end,

-- PoKeys pin 9, Mach4 Input 0
-- Physical Cycle Start Button
[mc.ISIG_INPUT0] = function (state)
    if (state == 0) then
        CycleStart()
    end
end,

-- PoKeys pin 10, Mach4 Input 1
-- Physical Feed Hold Button
[mc.ISIG_INPUT1] = function (state)
    if (state == 1) then
        mc.mcCntlFeedHold (0)
    end
end,

-- PoKeys pin 11, Mach4 Input 2
-- Physical Stop Button
[mc.ISIG_INPUT2] = function (state)
    if (state == 1) then
        CycleStop()
    end
end,

--PMDX-108 Port 2 Pin 6 Mach4 Input 10
--HLFB_X ERROR
[mc.ISIG_INPUT10]= function(state)
    if (state==1) then
          mc.mcCntlCycleStop(inst)
          mc.mcCntlSetLastError(inst, "HLFB_X Servo Error")
    end
end,

--PMDX-108 Port 2 Pin 7 Mach4 Input 11
--HLFB_Y ERROR
[mc.ISIG_INPUT11]= function(state)
    if (state==1) then
          mc.mcCntlCycleStop(inst)
          mc.mcCntlSetLastError(inst, "HLFB_Y Servo Error")
    end
end,

--PMDX-108 Port 2 Pin 8 Mach4 Input 12
--HLFB_A ERROR
[mc.ISIG_INPUT12]= function(state)
    if (state==1) then
          mc.mcCntlCycleStop(inst)
          mc.mcCntlSetLastError(inst, "HLFB_A Servo Error")
    end
end,

--PMDX-108 Port 2 Pin 9 Mach4 Input 13
--HLFB_Z ERROR
[mc.ISIG_INPUT13]= function(state)
    if (state==1) then
          mc.mcCntlCycleStop(inst)
          mc.mcCntlSetLastError(inst, "HLFB_Z Servo Error")
    end
end,

----------Mach4 Input 17 PoKeys Pin 17-----
----------Toggle Coolant M8----------------
[mc.ISIG_INPUT17] = function (state)
if (state == 1) then
     local inst = mc.mcGetInstance();
     local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_COOLANTON);
     local sigState = mc.mcSignalGetState(sigh);
     if (sigState == 0) then
         local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
         mc.mcSignalSetState(OSigCool,1)
         mc.mcCntlSetLastError(inst, "Coolant On")
     else
         local OSigCool = mc.mcSignalGetHandle (inst,mc.OSIG_COOLANTON)
         mc.mcSignalSetState(OSigCool,0)
         mc.mcCntlSetLastError(inst, "Coolant Off")
     end
end
   
end,

----------Mach4 Input 14 PoKeys Pin 14--
----------Toggle Mist M7----------------
[mc.ISIG_INPUT14] = function (state)
if (state == 1) then
     local inst = mc.mcGetInstance();
     local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_MISTON);
     local sigState = mc.mcSignalGetState(sigh);
     if (sigState == 0) then
         local OSigMist = mc.mcSignalGetHandle (inst,mc.OSIG_MISTON)
         mc.mcSignalSetState(OSigMist,1)
         mc.mcCntlSetLastError(inst, "Mist On")
     else
         local OSigMist = mc.mcSignalGetHandle (inst,mc.OSIG_MISTON)
         mc.mcSignalSetState(OSigMist,0)
         mc.mcCntlSetLastError(inst, "Mist Off")
     end
end
   
end,

------------Mach4 Input 8 PoKeys Pin 8----------------
------------Toggle SpinCW-----------------------------
[mc.ISIG_INPUT8] = function (state)
if (state == 1) then
     local inst = mc.mcGetInstance();
     local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
     local sigState = mc.mcSignalGetState(sigh);
     if (sigState == 1) then
         mc.mcSpindleSetDirection(inst, 0);
     else
         SpinCW()
     end
end

end,

------------Mach4 Input 7 PoKeys Pin 7------------
------------Set S1000-----------------------------
[mc.ISIG_INPUT7] = function (state)
    if (state == 1) then   
        mc.mcCntlGcodeExecuteWait(inst, "S1000");
mc.mcCntlSetLastError(inst, 'Speed Set to 1000')
    else
        --mc.mcCntlFeedHold (0)
    end

end,

--sample input use that was originally in here!!
[mc.ISIG_INPUT60] = function (state)
   -- if (state == 1) then   
--        CycleStart()
--    --else
--        --mc.mcCntlFeedHold (0)
--    end

end,

Thank you Tom I see how Pokeys pins are associated with and read as Mach4 I/O pins but Mach only has 64 pins. If I had 80 pins on my Pokeys devices how would one read input pin 75?

Thanks for any help.
Tony

« Last Edit: March 24, 2019, 09:45:54 AM by Tony Bullard »

Offline thosj

*
  •  532 532
    • View Profile
Re: PoKeys 57U, Mach4, Buttons and you.
« Reply #5 on: March 24, 2019, 10:41:37 AM »
Tony,

PoKeys inputs don't have to match Mach4 inputs. You can assign whatever PoKeys input to any of the available Mach4 inputs. I guess you won't be able to use all 75 PoKeys inputs, but 64 at least!! I have a 57E so only 55 inputs, not 75, but nonetheless.......

So in Mach4, Config/Plugins/Pokeys, configure pin 75, back to Config/Control, inputs tab and set that to whatever Mach4 input you like. Then write your code.

If I misunderstand, well, that's pretty normal:)

Tom

--
Tom
Re: PoKeys 57U, Mach4, Buttons and you.
« Reply #6 on: March 24, 2019, 11:15:01 AM »
Thanks Tom,
I just noticed in the Mach4 API there is 150 output and 185 input "pins". I guess I could use an unused function like ISIG_MOTOR31_HOME ,Motor 31 Home, for a custom function. I'm just trying to understand all this before I buy the Pokeys57E, PMDX424 controller, 4 Gecko G320X servo drives and Mach4 license.

Edit: Or is there a way in code to set and get the state of the Pokeys device pin directly? Example please.
« Last Edit: March 24, 2019, 11:22:32 AM by Tony Bullard »

Offline thosj

*
  •  532 532
    • View Profile
Re: PoKeys 57U, Mach4, Buttons and you.
« Reply #7 on: March 24, 2019, 12:36:19 PM »
You passed me up now. No idea about all those inputs/outputs or functions!!

Sorry,
Tom
--
Tom