Hello Guest it is April 20, 2024, 07:00:41 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 - SwiftyJ

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 »
1
Mach4 General Discussion / Re: PLC script to write to a text file
« on: March 12, 2024, 04:38:48 PM »
Try this:

Code: [Select]
-------------------------------------------------------
--  position Data
-------------------------------------------------------
local val_x = mc.mcAxisGetPos(inst, mc.X_AXIS) -- get X position
local val_y= mc.mcAxisGetPos(inst, mc.Y_AXIS) -- get Y position
WriteRegister("X_pos",val_x) -- to monitor in register diagnostics ok
WriteRegister("Y_pos",val_y) -- to monitor in register diagnostics ok

local LoadCellSignal = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT9 ) -- monitor output 9 activated by macro
local LoadCellSignalState = mc.mcSignalGetState(LoadCellSignal)

if (LoadCellSignalState == 1) then -- if output 9 is activated

local hregTime_LC = mc.mcRegGetHandle(inst, "iRegs0/Time_LC") -- get register Time_LC = 0
local LoadCellTime= mc.mcRegGetValue(hregTime_LC)

if (LoadCellTime==0) then
local Path = GetRegister(Layer_path) -- get File path from register
local MyFile = wx.wxGetCwd() .. Path -- define the file path in Mach4
file = io.open(MyFile, "a") -- open file in append mode
end


LoadCellTime = LoadCellTime+0.05 -- follow PLC cycle time as sample rate
WriteRegister("Time_LC",LoadCellTime) --  monitor in register ok


local text = string.format ("%.4f, %.4f, %.4f \n", val_x, val_y, LoadCellTime );
file:write(text ) --Write the Gcode file
file:flush() --Save written data

else
       if (file ~= nil) then
            file:close() --Close file
            file = nil
       end
end

[/code

2
Make sure none of your other macros have error in them and make sure there are no files in the macros folder that may contain other m500() function. e.g. if you have renamed a file 'm500old.lua' and it still contains an m500() function it will cause it to mess up

3
Mach4 General Discussion / Re: Upgrade problem - 4498 to 5310
« on: March 12, 2024, 04:22:38 PM »
This should fix the jog mode selection

4
Mach4 General Discussion / Re: PLC script to write to a text file
« on: March 10, 2024, 04:24:35 AM »
I think you should only close the file when you want to stop recording the data i.e. when output 9 turns off. If you close it after every time you write data you will need to open the file each time, but you are only opening it once when output 9 turns on. Something like this...

Code: [Select]
-------------------------------------------------------
--  position Data
-------------------------------------------------------
local val_x = mc.mcAxisGetPos(inst, mc.X_AXIS) -- get X position
local val_y= mc.mcAxisGetPos(inst, mc.Y_AXIS) -- get Y position
WriteRegister("X_pos",val_x) -- to monitor in register diagnostics ok
WriteRegister("Y_pos",val_y) -- to monitor in register diagnostics ok

local LoadCellSignal = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT9 ) -- monitor output 9 activated by macro
local LoadCellSignalState = mc.mcSignalGetState(LoadCellSignal)

if (LoadCellSignalState == 1) then -- if output 9 is activated

local hregTime_LC = mc.mcRegGetHandle(inst, "iRegs0/Time_LC") -- get register Time_LC = 0
local LoadCellTime= mc.mcRegGetValue(hregTime_LC)

if (LoadCellTime==0) then
local Path = GetRegister(Layer_path) -- get File path from register
local MyFile = wx.wxGetCwd() .. Path -- define the file path in Mach4
file = io.open(MyFile, "a") -- open file in append mode
end


LoadCellTime = LoadCellTime+0.05 - follow PLC cycle time as sample rate
WriteRegister("Time_LC",LoadCellTime) --  monitor in register ok


local text = string.format ("%.4f, %.4f, %.4f \n", val_x, val_y, LoadCellTime );
file:write(text ) --Write the Gcode file
file:flush() --Save written data

else
       if (file ~= nil) then
            file:close() --Close file
       end
end



[/code

5
Mach4 General Discussion / Re: Upgrade problem - 4498 to 5310
« on: March 09, 2024, 02:22:13 PM »
Here is an updated screen, I've renamed it so it won't overwrite your current screen, you can just load it through the View menu once it's copied to the Screens folder.

This should fix the wear DRO, X and Z tool offset buttons, UI jog buttons, your control panel Cycle Start and Feedhold buttons. I've tried to keep your code the same as much as possible so it's familiar to you but some of it could be optimised. I've tested with the Sim and it looks ok, but always test cautiously on the machine!

I've not changed anything to do with the your pendant stuff. I think it could do with recoding to utilise the signal library to prevent it unnecessarily running functions every time a switch state is changed.

A question regarding your pendant, does the 'Off' setting have it's own signal or are you saying it's considered off when there is no axis selected or speed selected?

Thanks

6
Mach4 General Discussion / Re: Upgrade problem - 4498 to 5310
« on: March 09, 2024, 08:20:06 AM »
If you go to Help>Support>Package Current Profile and upload the file it creates. This will include the screenset, macros, and the machine.ini file

I had a quick look at the tool wear in the default lathe screen. The DRO is set to read only, hence why you can't edit it, also the code in the On Modify script needs updating.  There's a bunch of other changes required to the X and Z offset DRO's too. Looks like DRO names were updated but the code is still referencing the old names   :(

7
Mach4 General Discussion / Re: Probing Tab Inputs
« on: March 09, 2024, 05:29:23 AM »
Which build number of Mach4 are you using? Could you upload a copy of your screenset file?

8
Mach4 General Discussion / Re: Auto Load Last GCode File on Startup
« on: March 09, 2024, 05:16:12 AM »
Put this function in your screenload script
Code: [Select]
function LoadLastGCode()
local inst = mc.mcGetInstance()

--This prevents a crash if there is already a loaded file e.g. when coming out of the screen editor
local curFile = mc.mcCntlGetGcodeFileName(inst)
if (curFile ~= "") then
do return end
end

--Mach4 already stores last loaded file in the machine.ini, this is used for the 'Load Recent File' button
--So we'll just read the file name and path from here
local fileName = mc.mcProfileGetString(inst, 'Preferences', 'MRU1', 'NO FILE')

--Load the file and check for errors
if (fileName ~= "NO FILE") then
local rc = mc.mcCntlLoadGcodeFile(inst, fileName)
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "Error loading last g-code file")
else
mc.mcCntlSetLastError(inst, "Last G-Code file successfully loaded")
end
else
mc.mcCntlSetLastError(inst, "Last loaded g-code file not found")
end
end

and then at the bottom of the PLC script there is a 'PLC First Run' section. It will look something like this, you'll have some other functions in there as well to do with the keyboard. Just add the call to the function within the 'if' statement.
Code: [Select]
-------------------------------------------------------
--  PLC First Run
-------------------------------------------------------
if (testcount == 1) then
    LoadLastGCode() --Call the function here

...

[/cpde]

9
You're getting a bit confused.. but are almost there

The Load_modules.mcs file is for loading modules into the lua chunk that exists for macros only. This is separate to the chunk that runs the screenload/PLC/signal scripts etc.

To call the module functions from a button you need to include the following at the top of the screenload script as well:

Code: [Select]
package.loaded.Test = nil
t = require "Test"  --This stores the contents of the module into table 't' or a name of your choice

Your module 'Test.lua' should look like this:

Code: [Select]
local Test = {}

function Test.PrintVal(val)
          wx.wxMessageBox("Current val="..tostring(val))
end

function Test.AnotherFunction()
           wx.wxMessageBox("This is another function")
end

return Test

Now in your button script you can call the functions like this, note the use of 't' before the function name as this is where we stored them when we 'required' the module
Code: [Select]
t.PrintVal(val)

t.AnotherFunction()


Because you have also created the Load_modules.mcs and put it in your macros folder, this will load the same module in the macro lua chunk so you can call the functions from your macros (m6, m3 etc) as well. Please note that you cannot use the module to transfer information between the GUI lua chunk and the macro lua chunk, only registers can do this.

Hopefully this helps

10
Mach4 General Discussion / Re: Upgrade problem - 4498 to 5310
« on: March 09, 2024, 04:31:14 AM »
Can you post your profile and screenset including required modules?

I thought tool wear was only enabled on Mach4 Industrial, do you have an industrial licence? I could be wrong though...
Homing is all related to the ESS and the plugin.. does Warp9 have a working plugin for 5310? Their documentation site is still saying they had problems with build 5000 onwards

Thanks

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