Hello Guest it is April 26, 2024, 07:24:24 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 - DazTheGas

461
Mach4 General Discussion / Re: Huge feedrate error
« on: June 13, 2016, 04:11:51 AM »
Have you ever considered using the registry plugin (also can be persistent) and assign a register to your dro, this can then be retrieved from within the macro.

DazTheGas

462
Mach4 General Discussion / Re: change motor counts with lua
« on: June 09, 2016, 02:21:53 PM »
The series of events need to be in a certain order and can only be done in an idle state so you will prob need to run mc.mcCntlEnable(inst, 0) before writing to the ini, then re-enable with mc.mcCntlEnable(inst, 1)

Code: [Select]
local inst = mc.mcGetInstance()
mc.mcCntlEnable(inst, 0) -- disable controller
mc.mcProfileWriteInt(inst, "Motor0", "CountsPerUnit", 1000 ) -- what we require in our ini
mc.mcProfileFlush(inst) -- force the changes to be written
mc.mcProfileReload(inst) -- reload the changes
mc.mcCntlEnable(inst, 1) -- re - enable controller

Although the above code works fine, there are other factors to take into account like the motion controller will need to know that your settings have changed  ( take a look at mcCntlConfigStart and mcCntlConfigStop ) about this.

DazTheGas

463
Mach4 General Discussion / Re: Adding sound in Mach4 m-code
« on: June 08, 2016, 03:39:37 PM »
not 100% sure on this but the macros will run within a different instance than the gui so what is assigned there will not show.

DazTheGas

464
Mach4 General Discussion / Re: script and mach 4
« on: June 08, 2016, 03:06:15 AM »
Go for the startup script there is an example in there called sigLib, this is where is best to put your scripts for external buttons

DazTheGas

465
Mach4 General Discussion / Re: Run From Here
« on: June 02, 2016, 05:55:20 PM »
Multitask the Run From Here button, just add what code you also need in the left up script and then both script and command will both execute at same time.

DazTheGas

466
Mach4 General Discussion / Re: Using Modules
« on: May 30, 2016, 03:44:46 PM »
I have just copied your myClass and made new module exactly the same in my modules directory and run this code

Code: [Select]
local inst = mc.mcGetInstance()
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.mcs;"

message = require "newClass"

message.test()

which as expected displayed a messagebox with "Nothing to see here"

If i try to access message.test2() then it gives an error

So this is working correctly as it should.

DazTheGas

467
Mach4 General Discussion / Re: Using Modules
« on: May 30, 2016, 06:10:09 AM »
Let me try and clear this one up about modules before you awake........

Modules in Lua - wxLua are like other languages classes, now these classes hold functions (class of functions). Now when declaring these Modules wx or lua need to know where to look, this is where the package.path comes in.

Like all other languages you declare the path which is "global" so no need to keep declaring all over the place.

Code: [Select]
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;"

So lets break this down to what wxlua  sees when we require a module called newClass, first lets look in  "Mach4Hobby\Profiles\"current profile name"\Modules and look for newClass.lua  and if not found then lets look in Mach4Hobby\Modules for newClass.lua - so does it have to be .lua extension?? - nope it can be anything you want

Code: [Select]
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.mcs;"

The above will look in the same directories but also look in the last directory for newClass.mcs  - so now we can find modules lets look at the module


Code: [Select]
local myClass = {}

function myClass.test()
    wx.wxMessageBox("Nothing to see here")
end

function test()
    wx.wxMessageBox("Still Nothing to see here")
end

return myClass

The above will create a class called myClass and declare myClass.test() as available to public to use, however the function test() is private and can only be used by the class.

Now lets load the class from mach4, first make an instance of the class and call it what you like

message = require "newClass" - wxlua will now search our path from earlier for the newClass file and make a new instance of the class called myClass contained in the file, now to use a function in the class we need to call it with the instance of the class we created "message", so to run the test function we would use message.test() - this will now run and in this case show a messagebox.

If wanted you can use many instances of the same class
message = require "newClass"
message2 = require "newClass"

each one of the buttons or dro`s etc in the editor create an instance of a class for example.

DazTheGas

Time for coffee and biccy now

468
Mach4 General Discussion / Re: Using Modules
« on: May 29, 2016, 06:43:11 PM »
Oh and the extension needs to be .lua

469
Mach4 General Discussion / Re: Using Modules
« on: May 29, 2016, 06:41:38 PM »
Out of curiosity insert this before you do sw = require('Module1') and have your module in the Mach4Hobby\Modules directory, the debug info means it cant find the file, this is already in the startup script but just incase whatever your doing cant see it??

Code: [Select]
   local profile = mc.mcProfileGetName(inst)
    local path = mc.mcCntlGetMachDir(inst)
    package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;"

DazTheGas

470
Mach4 General Discussion / Re: Using Modules
« on: May 29, 2016, 04:24:43 PM »
You need to rename your function so it is tied to the Module1 table

Code: [Select]
local Module1 = {}

function Module1.theFunction()
wx.wxMessageBox('Module Test')
end

return Module1

As a norm the modules should be placed in the Mach4Hobby/Modules directory

DazTheGas