Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Help with buffers please


Clarence L Cook
 Share

Recommended Posts

I am attempting to output the tool list in accending order, not the order of use.

 

Currently, I am using two buffers, 1 and 2. Buffer 1 stores the number information of the tool while buffer 2 stores the tool comment string.

 

I am having problems with storing the comment string. Below is the buffer delcarations and the output that I am getting.

 

I am using X3 MU1 and the post: Haas developed from MPMaster.

 

Thank you.

code:

# --------------------------------------------------------------------------

# Buffer 1 - Holds the tool table information

# --------------------------------------------------------------------------

toolnum : 0

tooltype : -1

tooldiam : 0

toollength : 0

tooloffset : 0

toolradi : 0

rc1 : 1

wc1 : 1

size1 : 0

fbuf 1 0 6 0 0 # Buffer 1

 

# --------------------------------------------------------------------------

# Buffer 2 - Holds the tool comment information

# --------------------------------------------------------------------------

strtoolstring : " "

rc2 : 1

wc2 : 1

size2 : 0

fbuf 2 0 1 0 1 # Buffer 2

 

# --------------------------------------------------------------------------

# Buffer 1 Read / Write Routines and set

# --------------------------------------------------------------------------

pinitbuff1 #initialize buffer 1

*toolnum = 1

while wc1 <= 40, #number of pockets

[

toolnum = wbuf(1, wc1)

pinitbuff2

toolnum = toolnum + 1

]

 

pwritbuf1 #write buffer 1

toolnum = t$

tooltype = tool_typ$

tooldiam = tldia$

toollength = tlngno$

tooloffset = tloffno$

toolradi = tcr$

pwritbuf2

wc1 = toolnum

toolnum = wbuf(1, wc1)

 

preadbuf1 #read buffer 1

size1 = rbuf(1,0)

while rc1 <= size1,

[

toolnum = rbuf(1,rc1)

if tooltype >=0,

[

t$ = toolnum

tool_typ$ = tooltype

tldia$ = tooldiam

tlngno$ = toollength

tloffno$ = tooloffset

tcr$ = toolradi

preadbuf2

scomm_str, *t$, ptspace, " - ", plistcomm, " - "

*tldia$, punit, " - ", *tlngno$

if tool_typ$ >= 10,

[

if tcr$ > 0, ptspace, " - ", *tloffno$, " - ", *tcr$, punit

else, ptspace, " - ", *tloffno$

]

scomm_end, e$

]

]

 

# --------------------------------------------------------------------------

# Buffer 2 Read / Write Routines and set

# --------------------------------------------------------------------------

pinitbuff2 #initialize buffer 2 from buffer 1

strtoolstring = wbuf(2, wc2)

 

pwritbuf2 #write buffer 2 from pwritbuf1

strtoolstring = strtool$

wc2 = toolnum

strtoolstring = wbuf(2, wc2)

 

preadbuf2 #read buffer 2 from preadbuf2

rc2 = toolnum

strtoolstring = rbuf(2, rc2)

strtool$ = strtoolstring

 

O0001 (HAMMER 2ND)

(-MATERIAL------------------------)

(ACETAL 3.8125" X 1.575" X .75" XYZ)

(-SETUP---------------------------)

(-TOOLS---------------------------)

(T19 - 1/2 FLAT ENDMILL GARR - D0.5000" - H19 - D19)

(T20 - 2 1/2" SECO SHELL MILL - D2.5000" - H20 - D20 - R0.0313")

(T17 - .062 RAD CORNER - D0.0625" - H17 - D17 - R0.0620")

(sorted tools)

(T17 - ÅÜÄA - D0.0625" - H17 - D17 - R0.0620")

(T19 - Ÿ - D0.5000" - H19 - D19)

(T20 - Ÿ - D2.5000" - H20 - D20 - R0.0313")

(-TOOL PROJECTIONS----------------)

(-NOTES---------------------------)

(-REV CHANGE NOTES----------------)

(OVERALL MIN - Z2.0625)

 


Link to comment
Share on other sites

With some experimentations, it appears that for an X post, the 3rd parameter is the number of characters you want in your string. It appears that you can set it to anything you want, but I imagine that some controls have a hard time with more than 80 characters. The 5th parameter sets the buffer for numeric or string (0 and 1 respectively).

 

I figured the problem had to be something simple and a problem with the way I set it up.

Link to comment
Share on other sites

I know that this is long but, I tried to keep it as on topic as best that I could.

 

My goal was to sort the tool list in accending order.

 

Below is a sample header for with unsorted tools and sorted tools.

 

code:

O0001 (TEST)

(-MATERIAL------------------------)

(6061 T6 8.375" X .82" X .75" XYZ)

(-SETUP---------------------------)

(-TOOLS---------------------------)

(T20 - 2 1/2" SECO SHELL MILL - D2.5000" - H20 - D20 - R0.0313")

(T19 - 3/4 FLAT ENDMILL GARR - D0.7500" - H19 - D19)

(T1 - 1/4 X 120 SPOT DRILL - D0.2500" - H1)

(T2 - #34 DRILL - D0.1110" - H2)

(T12 - #38 DRILL - D0.1015" - H12)

(T18 - 1/4 FLAT ENDMILL GARR - D0.2500" - H18 - D18)

(T17 - 1/8 FLAT ENDMILL - D0.1250" - H17 - D17)

(T16 - 1/4 90 DEG CHAMFER MILL - D0.2500" - H16 - D16)

(sorted tools)

(T1 - 1/4 X 120 SPOT DRILL - D0.2500" - H1)

(T2 - #34 DRILL - D0.1110" - H2)

(T12 - #38 DRILL - D0.1015" - H12)

(T16 - 1/4 90 DEG CHAMFER MILL - D0.2500" - H16 - D16)

(T17 - 1/8 FLAT ENDMILL - D0.1250" - H17 - D17)

(T18 - 1/4 FLAT ENDMILL GARR - D0.2500" - H18 - D18)

(T19 - 3/4 FLAT ENDMILL GARR - D0.7500" - H19 - D19)

(T20 - 2 1/2" SECO SHELL MILL - D2.5000" - H20 - D20 - R0.0313")

(-TOOL PROJECTIONS----------------)

(-NOTES---------------------------)

(-REV CHANGE NOTES----------------)

(OVERALL MIN - Z-.4574)

To acheive the sorting requires two buffers. Buffer 1 for numerical data and

Buffer 2 for the Tool Comment Data (string data)

 

code:

# --------------------------------------------------------------------------

# Buffer 1 - Holds the tool table information

# --------------------------------------------------------------------------

toolnum : 0

tooltype : -1

tooldiam : 0

toollength : 0

tooloffset : 0

toolradi : 0

rc1 : 1

wc1 : 1

size1 : 0

fbuf 1 0 6 0 0 # Buffer 1

 

# --------------------------------------------------------------------------

# Buffer 2 - Holds the tool comment information

# --------------------------------------------------------------------------

strtoolstring : snull

rc2 : 1

wc2 : 1

size2 : 0

fbuf 2 0 80 0 1 # Buffer 2

I will give all the parameters of fbuf for completeness. I had to do a lot of

looking to get a resonably complete picture.

 

Parameter 1 - The buffer number (Limited to 10 buffers max)

 

Parameter 2 - Keep flag (=1 to save. This flag outputs the contents of the buffer

to a file. In my case the file is in mill/nci and named test.tx2 (program name?,

and the tx + buffer number therefore tx2)

 

Parameter 3 - Number of records (If numerical data, then the number of variables

to be stored in the buffer. If string data, then the number of characters you

wish to store, but only one variable aka string.)

 

Parameter 4 - Initialize flag (I haven't used it yet.)

 

Parameter 5 - Buffer type (0 = numeric, 1 = string)

 

The above parameters I got from Roger Martin's post from Recalling Comments thread.

 

In order to get the tools in accending order, I had to initialize the buffers

to some size with dummy variables, ie since I have 20 tools in the carosels, I

went up to 40 sets of numerical variables (buffer 1) and string variables (buffer 2)

 

code:

pinitbuff1   #initialize buffer 1

toolnum = 1

while wc1 <= 40, #number of pockets

[

toolnum = wbuf(1, wc1)

pinitbuff2

toolnum = toolnum + 1

]

 

pinitbuff2 #initialize buffer 2 from buffer 1

strtoolstring = wbuf(2, wc2)

wc1 and wc2 are initialized to 1 in the buffer delcarations. That appears to be

the only time you will know the value of those variable and when they are used,

they will increment themselves by 1.

 

If you need to jump around to different record in the buffer, you will need to

set these values. I had to do this when writing to the buffers because the

tools are in order of use, so placed the tool information in the buffer according

to the tool number as demonstrated below.

 

code:

pwritbuf1   #write buffer 1

toolnum = t$

tooltype = tool_typ$

tooldiam = tldia$

toollength = tlngno$

tooloffset = tloffno$

toolradi = tcr$

pwritbuf2

wc1 = toolnum <----

toolnum = wbuf(1, wc1)

 

pwritbuf2 #write buffer 2 from pwritbuf1

strtoolstring = strtool$

wc2 = toolnum <----

strtoolstring = wbuf(2, wc2)

If a tool is called multiple times in different parts of the program, it isn't

a problem because the information will be over written and since it is the same

information there isn't a problem.

 

Then I just read out the buffer in accending order and the tools are sorted.

 

code:

preadbuf1   #read buffer 1

size1 = rbuf(1,0)

while rc1 <= size1,

[

toolnum = rbuf(1,rc1)

if tooltype >=0,

[

t$ = toolnum

tool_typ$ = tooltype

tldia$ = tooldiam

tlngno$ = toollength

tloffno$ = tooloffset

tcr$ = toolradi

preadbuf2

scomm_str, *t$, ptspace, " - ", plistcomm, " - "

*tldia$, punit, " - ", *tlngno$

if tool_typ$ >= 10,

[

if tcr$ > 0, ptspace, " - ", *tloffno$, " - ", *tcr$, punit

else, ptspace, " - ", *tloffno$

]

scomm_end, e$

]

]

 

preadbuf2 #read buffer 2 from preadbuf2

rc2 = toolnum

strtoolstring = rbuf(2, rc2)

strtool$ = strtoolstring

My next challenge will be to get the comments from the tool plane, so I can parse

this string and arrange it into a format of my choosing. The wonderful thing, is

that I don't need another buffer to do it.

Link to comment
Share on other sites

I found a glaring error. I was resetting t$ to the last tool in my list. Below is some of what I had to change to remove this error. There are some other errors that I am working on.

 

John. Yes, I remember the size1=rbuf(1,0) to reset the rc1 back to 1. I would probably need something for the wc1 because as is, I lose the location of the end of the file. Thanks, I will keep that in mind and try to make a little more bullet proof code. Thanks.

 

code:

preadbuf1   #read buffer 1

size1 = rbuf(1,0)

while rc1 <= size1,

[

toolnum = rbuf(1,rc1)

if tooltype >=0,

[

preadbuf2

scomm_str, toolnum, ptspacecust, " - ", plistcomm, " - "

tooldiam, punit, " - ", toollength

if tooltype >= 10,

[

if toolradi$ > 0, [ptspacecust, " - ", tooloffset, " - ", toolradi, punit]

else, [ptspace, " - ", tooloffset]

]

scomm_end, e$

]

]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...