Hello Guest it is April 26, 2024, 03:06:54 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Tony Bullard

Pages: « 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 »
41
Mach4 General Discussion / Re: Mach4 Timer Script Error
« on: April 25, 2019, 04:23:53 PM »
Thank you Daz! I've been working on this all day and I just didn't see it. I feel kina bad asking for help when I should have been able to find the answer myself. Thank you again for all your help on these forums.

42
Mach4 General Discussion / Mach4 Timer Script Error
« on: April 25, 2019, 03:56:45 PM »
I’d like to set up some Mach4 timers to control a lub pump.
I believe I’ve followed Daz’s tutorial https://www.youtube.com/watch?v=wNPMqjkcJ_8 correctly. I’ve set the Mach4 Timer Script, Screen Load Script and a Button Script. This is the code.
Code: [Select]
--Timer Script:

if timer == 0 then
timer(0)
elseif timer == 1 then
timer(1)
elseif timer == 2 then
timer(2)
elseif timer == 3 then
timer(3)
elseif timer == 4 then
timer(4)
elseif timer == 5 then
timer(5)
elseif timer == 6 then
timer(6)
elseif timer == 7 then
timer(7)
elseif timer == 8 then
timer(8)
elseif timer == 9 then
timer(9)
else
mc.mcCntlSetLastError(inst, 'Timer out of range')
end

--add  TB 04-24-19
--Screen Load Script
function timer0()   --This timer is called from "Test 2" button
wx.wxMessageBox("Hello From timer 0")
end


--Button Script:
scr.StartTimer(0,2000,1)

This is the error I get when the timer runs. Any suggestions as how to fix the error? Thanks for any help
 

43
Mach4 General Discussion / Re: Missing MSVCP120.dll for script editor
« on: April 20, 2019, 10:05:56 AM »
Thank you. That did the trick. You made my day!

44
Mach4 General Discussion / Re: Missing MSVCP120.dll for script editor
« on: April 20, 2019, 09:35:13 AM »
I have reinstalled Mach4Hoby and I still get the same error with any profile.

45
Mach4 General Discussion / Missing MSVCP120.dll for script editor
« on: April 20, 2019, 08:27:57 AM »
When I try to run or debug any macro in Mach4 script editor I get a missing dll error. The missing dll shows in the Mach4Hobby directory. I've replaced it with a copy from another machine to no avail. Do I have it in the proper directory? Thanks for any help.

46
Mach4 General Discussion / Re: Mach4 with Pokeys57CNC and FRO
« on: April 20, 2019, 08:09:03 AM »
Thanks again Craig for all you do here on the forums. By starting Mach4 in edit mode I was able to remove the bad code in the PLC script. Running the code you provided in a macro with the MDI proved the code was correct. I then put the code in near the end of the PLC script and it runs smooth as silk.
Thank you!

47
Mach4 General Discussion / Re: Mach4 with Pokeys57CNC and FRO
« on: April 19, 2019, 11:17:26 AM »
Hi,

Code: [Select]
local inst=mc.mcGetInstance()
local analogRegHandle=mc.mcRegGetHandle(inst,'Analog input/PokeysCNC_41744/41')
if analogRegHandle==0 then
wx.wxMessageBox('Failed to find Register Handle')
else
local analogString=mc.mcRegGetValueString(analogRegHandle)
local percent= tonumber(analogString)*250
mc.mcCntlSetFRO(inst, percent)
end

Would this work?
Note I am not sure how the Pokeys registers are named, I am familiar with the ESS. I put a test in there so that if
a valid register handle is not found then the remainder of the code will not execute and crash Mach with an invalid handle.

Craig

Thank you Craig. This looks promising. I tried it and the handle was not found and and now I'm stuck in an endless loop with the MessageBox. I think Daz showed a way to edit the PLC script to get out of this. I'll have to find it.

Before this I tried to follow the tutorial exactly by putting the "PoKeys_analog_FRO.lua" file in the Mach4 directory and calling it from the PLC script with "dofile(“C:\\Mach4Hobby\\PoKeys_analog_FRO.lua”)".
Here's the code

Code: [Select]
--This is a lua file called from the PLC script. PoKeys_analog_FRO.lua
--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 = "PokeysCNC_41744" --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
--analogVal = tonumber(analogVal)

SetFRO(analogVal) -- Set FRO value in %

-- add ths line almost at the bottom of your PLC script:  tb
--dofile(“C:\\Mach4Hobby\\PoKeys_analog_FRO.lua”)
I don't think the registers are being found. Now it's trying to arithmetic on a null value.

48
Mach4 General Discussion / Re: Mach4 with Pokeys57CNC and FRO
« on: April 18, 2019, 02:37:43 PM »
I tried  local analog2 = tonumber(analog) as above with the same error message.

49
Mach4 General Discussion / Re: Mach4 with Pokeys57CNC and FRO
« on: April 18, 2019, 02:09:48 PM »
Thank you.
Would I do that here?
Code: [Select]
--Function to set FRO value
function SetFRO(analog)
local analog2 = tonumber(analog)
    local percent = analog2/1*250 --calculate percentage from 0% to 250%
--local percent = analog/1*250 --calculate percentage from 0% to 250%
    local inst = mc.mcGetInstance()
    mc.mcCntlSetFRO(inst, percent)
end

50
Mach4 General Discussion / Mach4 with Pokeys57CNC and FRO
« on: April 18, 2019, 01:39:05 PM »
I’m trying to set up an analog input in Mach4hobby by following this well written tutorial from Poscope.
https://blog.poscope.com/mach4-tutorial-fro-using-analog-input/   
The registers are setup and showing the analog value as 0 to 1 for 0 to 3.3 volts.
The device name = PokeysCNC_41744. Analog pin = 41.
I have this code in the screen load script.
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 = "PokeysCNC_41744" --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 %

This is the error I get when saving the screen edit. See picture

It looks like it’s trying to do arithmetic on a string. How can I correct this?

This post seems to use the same code with no problem.
https://www.machsupport.com/forum/index.php?topic=34051.msg238477#msg238477

Thanks for any help.


Pages: « 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 »