Hello Guest it is October 03, 2023, 05:49:25 PM

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

461
Mach4 General Discussion / Re: Lua Macro Parameters
« on: March 08, 2017, 05:33:29 PM »
Chaoticone, sorry for mangling your name in my previous post.  Thanks for the file, deleted the lines:

package.loaded.mcErrorCheck = nil
ec = require "mcErrorCheck"

since I don't have that module either.

Still no joy.

Code: [Select]
function m9002()
 local inst = mc.mcGetInstance()
 mc.mcCntlGcodeExecuteWait(inst,"g1F4 x1")
 if rt==nil then
    wx.wxMessageBox("rt==nil")
  else
    rt.rtMessage('Another Hello')
 end
end

if mc.mcInEditor()==1 then
  m9002()
end

When I call this macro from a button or through the mdi the dros move correctly and then I get the message rt==nil
If I call rt.rtMessage("Button Message") from a button I get 'Button Message'   so the GUI lua is loading the rtModule and seting it's rt but the load_modules.mcs for macro rt must be failing to load the same module as the screen.  How can you debug this?  

Has anyone tested this with Mach4Lathe?  

The UC100 plugin failed because they hadn't tested it with lathe so lathe must have some different code.

TIA

RT

462
General Mach Discussion / Re: Inconsistant ATC Positioning
« on: March 08, 2017, 03:26:38 PM »
I'm right there with you on the frazzle meter.  I need help with Mach4 and have been chasing my tail for 2 days.

With regards to the ref all not moving your turret, did you change the ref all button code to include homing the turret as well as X and Z?  Looks like you can't change the ref all in the lathe screen set, sorry.  They must be using OEMbutton(105).  In the ports and pins inputs is your turret axis homing enabled?

Like I said I don't have a tool changer so I'm shooting in the dark here.  From your last post when you are calling the M6 macro with a T401, my understanding is that there is a maximum number of tools at 253.  Your previous code that you posted only tests for tools 1 through 8. 

RT

463
Mach4 General Discussion / Re: Lua Macro Parameters
« on: March 07, 2017, 07:43:31 PM »
Checked all profiles' macros folders and no load_modules.mcs in any of them.  There is a moduleload.mcs in the Mach4_Industrial_Mill macros folder.

When I added your package path code to the Load_modules.mcs that I created and then load Mach4 (lathe by the way) I see a quick flash of a windows command prompt window opening and closing.  Probably showing an error message.

My head hurts so I need to call it a night.  Thanks for trying.

RT

464
Mach4 General Discussion / Re: LUA Script error in PLC, PoKeys
« on: March 07, 2017, 07:04:28 PM »
I feel your pain.  Understanding/following code for the uninitiated is really confusing and Lua lets you do anything you want and assumes you know what you are doing so it is very hard to debug since it does very little type checking.

you are correct that "45" is analogPin, when it is passed to ReadRegister it is also named analogPin.  But ReadRegister could just as easily called it aPin.  All Read register knows is that it is supposed to get a string.  ReadRegister  looks up the value stored in a register named "45" and returns a valueString (return mc.mcRegGetValueString(hreg)) to analogVal.  It then sends that string of characters to setFRO:
analogVal = ReadRegister(device, analogPin) --Save analog register value in variable
SetFRO(analogVal) -- Set FRO value in % 

setFRO takes analogVal and calls it analog now.  Still a string, convert it to a number

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 = toNumber(analog)/1*250 --calculate percentage from 0% to 250%  *****changed here******
    local inst = mc.mcGetInstance()
    mc.mcCntlSetFRO(inst, percent)
end

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

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

HTH

RT

465
General Mach Discussion / Re: Inconsistant ATC Positioning
« on: March 07, 2017, 06:52:40 PM »
No, not necessary.  G90 is what they call modal.  It stays that way until a G91 is issued changing the mode to incremental

466
General Mach Discussion / Re: Inconsistant ATC Positioning
« on: March 07, 2017, 06:31:14 PM »
Anywhere before this:

If GetSelectedTool = 1 Then
Code("G0A0")
While IsMoving()
Wend
Code("G0A-358")
While IsMoving()
Wend
SetOemDRO(803,1)

End If  

I would change to:

Code("G90")
If NEWTOOL = 1 Then
  Code("G0A0")
  While IsMoving()
  Wend
  Code("G0A-358")
  While IsMoving()
  Wend
  SetOemDRO(803,1)
End If  


467
Mach4 General Discussion / Re: LUA Script error in PLC, PoKeys
« on: March 07, 2017, 06:16:34 PM »
Not the expert here but you passed the Analog variable which contained a string of two letters a '4' and a '5' representing "45".  When passed to the function where you do the calculations you are trying to divide a a string by some numbers.  You need to convert "45" to 45.

alog=toNumber(Analog)

alog will now contain the number 45 and you can do calculations with it.

HTH

RT

468
Mach4 General Discussion / Re: Lua Macro Parameters
« on: March 07, 2017, 06:12:50 PM »
Steve,

Thanks for the explanation that there are two instances of Lua running and controlling Mach4.  I couldn't tell whether Daz was referring to two instances of rt or Lua or whatever.

As I put in my previous post:


I created, since none existed, a load_modules.mcs file and put it in the same macro folder as my profile macros 'C:\Mach4Hobby\Profiles\My4Lathe\Macros'
...
package.loaded.rtModule = nil
rt = require "rtModule"
...


Is this not accomplishing the same thing as you and Daz suggested?  The only difference is .mcs versus .lua  Are they both not compiled into the one file?


469
Mach4 General Discussion / Re: LUA Script error in PLC, PoKeys
« on: March 07, 2017, 05:49:42 PM »
When I run it I get a debug message:

attempt to perform arithmetic on local 'analog' (a string value)

change it to a number and try it then

470
Mach4 General Discussion / Re: Lua Macro Parameters
« on: March 07, 2017, 05:40:23 PM »
Daz thanks for the reply,

Mach4 has 2 instances of what?

I followed Chaticione's example to a T, at least I think I did.  I'm missing some basic concept/information on how mach/lua deals differently with screen scripts versus macro scripts.  

when to use mcCntlMDIexecute versus mcCntlScriptExecute

wx, sc and mc are just libs that have been loaded at startup and now my rt is as well.  I get that the load screen scripts instantiates my rt variable and read that lua only loads a 'lib' once even if called more than once.  Your reference to creating a functions.lua in the macro folder seems to be what the load_modules.mcs is doing now and which just seems to be loading the same lib again.

Sorry for the terseness but I'm getting dizzy and frustrated after spending hours reading and researching something that no one seems to be able to explain to people that are new to lua, and yes I have read/studied a lot on lua in the last month.  Not real fond of the compiler or the debugger.