Hello Guest it is March 29, 2024, 12:43:48 AM

Author Topic: Preload-Tool Macro  (Read 5420 times)

0 Members and 1 Guest are viewing this topic.

Preload-Tool Macro
« on: January 21, 2017, 02:08:54 PM »
Hello everybody,

I have a question and I have no clue how to deal with that problem... I hope you can help me with that:

Is there a function for looking up the next tool-number in the loaded g-code file?
I am using a PLC to control the automatic tool changer and I need to tell it what tool comes next so it can preload the next tool already.

Do you know a way of doing so?

Have a nice day!
Re: Preload-Tool Macro
« Reply #1 on: January 21, 2017, 02:45:50 PM »
Quoted from Mach4CoreAPI.chm which you will find in the C:\Mach4Hobby\Docs folder if
your system is installed in the default folders. You can view this file by simply clicking
on it. It will open a window that behaves like a Windows help file, which it is. While
the quote below has the essential information, it is difficult to read as unformatted
text and I recommend opening it as a Windows help file for clearer presentation.


mcToolGetSelected
C/C++ Syntax:
int mcToolGetSelected(
      MINSTANCE mInst,
      int *toolnum);

LUA Syntax:
toolnum, rc = mc.mcToolGetSelected(
      number mInst)

Description:
Retrieve the selected (next) tool number.

Parameters: Parameter Description
mInst The controller instance.
toolnum The address of an integer to receive the selected tool number.


Returns: Return Code Description
MERROR_NOERROR No Error.
MERROR_INVALID_INSTANCE The mInst parameter was out of range.

Notes:
None.

Usage:

// Get the selected tool number.
MINSTANCE mInst = 0;
int toolnum = 0;
int rc = mcToolGetSelected(mInst, &toolnum);




Steve Stallings
www.PMDX.com

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Preload-Tool Macro
« Reply #2 on: January 21, 2017, 05:15:44 PM »
Theres also a setting in the mach config under the tools tab that changes between m6 being tool in use or next tool to use.

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Preload-Tool Macro
« Reply #3 on: February 11, 2017, 01:51:46 PM »
That didn't quite help me that much...

My CAM software supports a preload-tool-feature, so in G-Code it prints the next tool number under the M6 command. With "next tool number" I mean the tool which is going to be used after that current toolchange.

Can I somehow "read" the next line after a M6 command? I am sure there is something like that, but I couldn't find it yet...

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: Preload-Tool Macro
« Reply #4 on: February 11, 2017, 08:02:14 PM »
N10 T10 (Load first tool)
N20 M6 (change to T10)
N30 T12 (load next tool)
...
N100 M6  (change to T12)

Something like that? 

You can accomplish the preload by making a T macro.  Call it t.mcs and drop it into your profile's macro folder. 

The file's contents:
Code: [Select]
function t(tool)
inst = mc.mcGetInstance('T macro');
local msg = "Tool Changer Selecting tool #" ..  tostring(tool)
mc.mcCntlSetLastError(inst, msg);
        -- You must do something with tool here.  Send to PLC, etc...
end

if (mc.mcInEditor() == 1) then
    t(10); --simulate T10
end

Every time the interpreter executes a block with T in it, this macro will run.

Steve
Re: Preload-Tool Macro
« Reply #5 on: February 12, 2017, 07:12:11 AM »
That's more like it, thanks!
So that problem is solved, now I have to figure out how to transfer the tool number to my PLC.

Is there a way of setting up a serial communication between mach and a slave device?
And where can I find more about that topic?

Re: Preload-Tool Macro
« Reply #6 on: February 12, 2017, 09:48:36 AM »
Most people communicate with a PLC using ModBus.

Here is an example of using a ModBus capable PLC with Mach4.

http://www.machsupport.com/forum/index.php/topic,27660.0.html

See the link to a tutorial ZIP file.
Steve Stallings
www.PMDX.com
Re: Preload-Tool Macro
« Reply #7 on: February 13, 2017, 11:07:46 AM »
That's interesting. I'll try to get that working.

Is there any more information about that topic?
Maybe is there an other way of setting up a serial communication without modbus?

Re: Preload-Tool Macro
« Reply #8 on: February 24, 2017, 03:08:32 PM »
Alright, I did some research about using Modbus and Mach4. That documentation is terrible...

Modbus is industry standard, right? And there is not a single proper tutorial of how to implement that into Mach4. Is there a other way of sending data to a simple PLC? RS232, RS485, Ethernet, IC2, SPI, anything?

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: Preload-Tool Macro
« Reply #9 on: February 24, 2017, 05:58:16 PM »
Sending data to a PLC almost ALWAYS uses Modbus.  Modbus is the protocol.  It can be used over any transport method that both the Modbus master and Modbus slave have in common.  RS232 and Ethernet are what Mach 4 supports as a Modbus master.  You can use RS485 or RS422 with the appropriate RS323 converter, if you wish. 

There are lot's of threads about Modbus and even the how-to that Steve referred to.  However, we don't attempt to document industry standards that are already very well documented.  Here is a link that summarizes Modbus quite nicely:  http://www.modbusdriver.com/doc/libmbusmaster/modbus.html  Once you understand the mechanism that is Modbus, and along with your PLC documentation, you will then have the glue to put the pieces together. 

And you never mentioned what PLC you are using.  We have no idea and can't read your mind so...  :)

Steve