Hello Guest it is January 21, 2022, 09:44:38 PM

Author Topic: Mach4 Pokeys 57E with FRO  (Read 1500 times)

0 Members and 1 Guest are viewing this topic.

Mach4 Pokeys 57E with FRO
« on: February 26, 2019, 12:57:39 PM »
I got the following code from a very well written example in the Pokeys Pluglins manual here:

https://www.poscope.com/wp-content/uploads/downloads/Pokeys/LibrariesAndPlugins/Mach4%20plugin%20user%20manual%20(5.2.2017).pdf

The code is from here:
blog.poscope.com/wp-content/uploads/2016/04/PoKeys_analog_FRO.zip

Code: [Select]
--Function to read value from analog register
function ReadRegister(device, analogPin)
    local inst = mc.mcGetInstance()
    local hreg = mc.mcRegGetHandle(inst, string.format("%s/Analog input %s", device, analogPin))
    return mc.mcRegGetValueString(hreg)
end

--Function to set FRO value
function SetFRO(analog)
    local percent = analog/1*250 --calculate percentage from 0% to 250%
    local inst = mc.mcGetInstance()
    mc.mcCntlSetFRO(inst, percent)
end

--Main
local device = "CNC controller" --Change this to the name of your PoKeys device
local analogPin = "41" --Analog input pin number

analogVal = ReadRegister(device, analogPin) --Save analog register value in variable
SetFRO(analogVal) -- Set FRO value in %

The instructions say to put this code almost at the end of the PLC script.
If all is set up properly in Mach4 does this code look like it might work? I’m new to coding but the variables don’t seem to match and the math is incorrect among other things.
Any help would be appreciated.
Re: Mach4 Pokeys 57E with FRO
« Reply #1 on: February 26, 2019, 01:28:03 PM »
I see now the that the analog value is 0 to 1, not the 12 bit  value of 0 to 4096 so the math is correct.

But what about the last two lines are they VB script for Mach3?
Re: Mach4 Pokeys 57E with FRO
« Reply #2 on: February 26, 2019, 04:31:34 PM »
Hi,
that is not VB, that is Lua....this has been written for Mach4.

Craig
My wife left with my best friend...
     and I miss him!
Re: Mach4 Pokeys 57E with FRO
« Reply #3 on: February 26, 2019, 04:45:14 PM »
Thank you Craig. I see now that SetFRO is the call to the function.
Re: Mach4 Pokeys 57E with FRO
« Reply #4 on: May 22, 2020, 04:50:37 PM »
this ist old with the manual pasting of code. in the newest version i suggest to use a encoder as FRO. watch here: https://youtu.be/iPAwvuvKkXk turn the subtitles on