Write tool info at run time

Discussion of various (CNC related) topics which are not product support issues.
Calum
Posts: 18
Joined: Thu Feb 14, 2013 12:59 pm

Write tool info at run time

Post by Calum »

Hi Dave,

Is there a way that I could write tool diameter and description from my Gcode to the tool table at run time? I would like to get the tool info from my CAM into the tool table for each part I want to machine to help me with manual tool changes.

Cheers
Calum
User avatar
DaveCVI
Site Admin
Posts: 798
Joined: Mon Feb 04, 2013 3:15 pm
Contact:

Re: Write tool info at run time

Post by DaveCVI »

Hi,
Calum wrote: Is there a way that I could write tool diameter and description from my Gcode to the tool table at run time?
Well.. almost/maybe.... I'll explain.

The tool table data you called out (Diam and tool description) can be written to the tool table from a mach script.
See the programmers ref manual and look up "SetToolParam" - that is how you set the diameter value in the mach tool table.
To set the description there is a special MSM call to use: MSMAPI_SetToolDesc
See section 15.9.3.2 in the MSM mill manual for the technical description of this interface.

OK, those are the references needed to set diam and description from a script.

But you asked about doing this from gcode....
You can create a user M code to run a mach script. So you could create (for example) M1201 to set the diameter.
The M1201 would need take some parameters so that you can pass in the tool # and diam values. You can do that with the Param1, Param2 and Param3 script calls.

Next you would naturally do the same and make a M1202 (just an example number for the mcode) to set the description. Alas, the description is where things get stuck.... Gcode is oriented around numbers and not strings. I don't know a way to pass a text string to an mcode - so I don't see a way to easily pass the tool description via gcode in so that the script can set the description in the tool table. I also don't know how you'd would get the text description from CAM into the gcode - you'll have to probably modify the CAM post processor to do that step.

Now there may be other ways to solve this... it all depends on how the info is available from your cam program.
For example: If the CAM tool info can be put into a file, then you could write a script to read the file contents and load that into the mach tool table. Then you could just make one user mcode that was run at the beginning of each gcode program - it would read the file and load the mach tool table etc.

I don't have a ready to use solution for you, but this should get you started thinking about that tools you have that you can use to get the job done.

Dave
Productivity Software for Personal CNC Machinists
http://www.CalypsoVentures.com
Calum
Posts: 18
Joined: Thu Feb 14, 2013 12:59 pm

Re: Write tool info at run time

Post by Calum »

Hi Dave,

Thanks for your comprehensive reply. I have done pretty much what you suggest with a M script and can get the tool diameter into the tool table but getting the description is where I get stuck. I was trying to find a way to access the Status history in the script, I can get this info into the gcode via my post processor as a message, but no luck so far.

I think writing the tool table info into a file could be done in a gcode header created by the post processor, I need to look into how to read a file from a script.

Is there any way to write tool info to the MSM tool table rather than via Mach?

I can live with getting just the tool diam for each tool, the description is just the cherry on top. All the info is avaliable I would like to us it.

Cheers
Calum
User avatar
DaveCVI
Site Admin
Posts: 798
Joined: Mon Feb 04, 2013 3:15 pm
Contact:

Re: Write tool info at run time

Post by DaveCVI »

HI Calum,
Calum wrote:Hi Dave,

Thanks for your comprehensive reply. I have done pretty much what you suggest with a M script and can get the tool diameter into the tool table but getting the description is where I get stuck.
Yeah, the problem is that the only way to pass stuff to a mcode is via a P, Q, R word - and they are defined as numbers - so not much use for passing a string.
Calum wrote:I was trying to find a way to access the Status history in the script,
I'm unsure what you are referring to there - is this the Mach status line at the top of the page or the mach history file (called lasterrors.txt on disk) that the MSM hist button opens?
Calum wrote:I can get this info into the gcode via my post processor as a message, but no luck so far.
Does this mean that the string shows up as a comment in the gcode?
If so that gets the info into the program, but there is no easy way to thenh get the infro from the gcode to a mach script (without opening and parsing the gcode program...).
Calum wrote: I think writing the tool table info into a file could be done in a gcode header created by the post processor, I need to look into how to read a file from a script.
Once you have the info in a file, then you can get it most anywhere else that you want.
The cypress basic manul has some info re calls to deal with text files etc. You can also go from cypress to windows and use windows system calls for file handling.
Calum wrote: Is there any way to write tool info to the MSM tool table rather than via Mach?
In reality, internal to mach there is only one tool table - and it belongs to mach. MSM puts extra info that mach does not normally store in the table - the mechanism that does that is why there is a special MSM API for set and get of the tool description. The tool table files that MSM saves are XML encoded versions of the mach table contents + the additional info that MSM uses. If you feel adventurous, I suppose you could write and MSM format XML tool table file and then load into MSM... but I didn't provide any interfaces for that as a supported part of MSM.
Calum wrote: I can live with getting just the tool diam for each tool, the description is just the cherry on top. All the info is avaliable I would like to us it.

Cheers
Calum
Dave
Productivity Software for Personal CNC Machinists
http://www.CalypsoVentures.com
Calum
Posts: 18
Joined: Thu Feb 14, 2013 12:59 pm

Re: Write tool info at run time

Post by Calum »

Thanks Dave you are always helpful. I have plenty to think about now.

Yes I was refering to the Mach Status info as you thought.

I can get almost anything into the gcode via the post processor, getting at it is another thing altogeather. I will pursue the Cypress file calls and see how far I get.

Cheers
Calum
User avatar
DaveCVI
Site Admin
Posts: 798
Joined: Mon Feb 04, 2013 3:15 pm
Contact:

Re: Write tool info at run time

Post by DaveCVI »

If you want, I can grab some of the file routines I use in MSM for you to look at as examples.
Dave
Productivity Software for Personal CNC Machinists
http://www.CalypsoVentures.com
Calum
Posts: 18
Joined: Thu Feb 14, 2013 12:59 pm

Re: Write tool info at run time

Post by Calum »

Hi Dave,

That would be appreciated and ,if I have the abblity, fast track what im trying to do. I have been looking through some of the scripts in your app to see what I can learn.

Let me know if there is anything I need to do to enable this to happen.

Calum
User avatar
DaveCVI
Site Admin
Posts: 798
Joined: Mon Feb 04, 2013 3:15 pm
Contact:

Re: Write tool info at run time

Post by DaveCVI »

Calum,
Here are some misc bits to help out.
I find it easier to use the windows file system objects than to use the file handling calls built into the cypress basic interpreter inside mach.

The win file system object info can be found here:
http://msdn.microsoft.com/en-us/library ... 84%29.aspx

Attached is the source to the script that checks for the existence of the mach history (lasterrors.txt) file and then opens it (if it exists) with the MSM non-gcode editor. This shows hoow to create a file system object, use it to see if a file exists etc and then de-allocate the object before exiting the routine (so we don't leak resources).

Dave
Attachments
History.m1s
MSM hist button script
(1.91 KiB) Downloaded 927 times
Productivity Software for Personal CNC Machinists
http://www.CalypsoVentures.com
Calum
Posts: 18
Joined: Thu Feb 14, 2013 12:59 pm

Re: Write tool info at run time

Post by Calum »

Thanks Dave, now I have some home work. ;)

Cheers
Calum
Calum
Posts: 18
Joined: Thu Feb 14, 2013 12:59 pm

Re: Write tool info at run time

Post by Calum »

Great thanks Dave I got this working with the info you provided. I can now get the next tool description and diameter into the tool table at run time. I guess there is no way to unset the empty flag associated with each tool other than via the xml file but this isn't a problem, I can just make the first 10 or so tool position not empty manually.

Cheers
Calum
Post Reply