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:

C hook "what's wrong" question


mvukovic
 Share

Recommended Posts

Hi,

 

this is "wannabe" C-hook programmer again. What follows is a part of testassc.c example. Before running c-hook, I created a drill operation (it is expected to exist). The question is: why don't I see any "little teapot" text in the generated .nci file?

 

Thanks,

Marko

===============

#include "m_vars.h"

#include "m_init.h"

#include "m_assoc.h"

 

static void error(const char *s) {

MessageBox(0, s, "Test", MB_ICONASTERISK);

}

 

static void test_nci_mgr (boolean *succf) {

operation op;

nci_bin n;

db_ptr_type e_ptr;

long fpos;

tl_list *tl;

 

// regenerate ALL operations that require regeneration (op.db.nci_flag == TRUE)

nci_manager (0, NCIMGR_REGEN_ALL, &n, &fpos, succf);

if (!*succf) { error("NCIMGR_REGEN_ALL"); return; }

 

// post ALL the operations

nci_manager (0, NCIMGR_POST_ALL, &n, &fpos, succf);

if (!*succf) { error("NCIMGR_POST_ALL"); return; }

 

// set binary nci file ptr to the end of the binary nci file

nci_manager (0, NCIMGR_FEND, &n, &fpos, succf);

if (!*succf) { error("NCIMGR_FEND"); return; }

 

// make a manual entry operation using the 1st tool found in the database

memset (&op, 0, sizeof (operation));

op.opcode = TP_MANUAL_ENTRY;

// get a list of tools from the database

list_manager (TL_ID, "", LSTMGR_GET, &tl);

if (tl != NULL)

{

op.tl.slot = tl->tl.op.slot; // set the tool # if you want the operation to init the tool

list_manager (TL_ID, "", LSTMGR_FREE, &tl); // free the tool list

}

// add a comment

strncpy (op.comment, "I'm a manual entry operation", COMMENT_SIZE-1);

// OPMGR_INIT_ADD writes the 'start of section' -

// no need to call nci_manager (NCIMGR_WR_SOS) - OPMGR_INIT does not write the sos

operation_manager (&op, OPMGR_INIT_ADD, &e_ptr, succf);

if (!*succf) { error("OPMGR_INIT_ADD"); return; }

 

// go to the end of the binary nci

nci_manager (0, NCIMGR_FEND, &n, &fpos, succf);

if (!*succf) { error("NCIMGR_FEND"); return; }

 

// write the start of file - sof, tool info and (if turned on) parameters

// set the rapid position to X1 Y2 Z0 for the 1002 line

memset (&n, 0, sizeof (nci_bin));

n.gcode = NCI_RAPID; // gcode for sof must be NCI_RAPID or NCI_LINEAR

n.op_idn = op.op_idn; // ALWAYS assign the parent operation's id number to all nci lines

n.tp_ent_idn = 0; // set this to 0

n.u.m0.ep1[X] = 1.0; // home position X

n.u.m0.ep1[Y] = 2.0; // home position Y

n.u.m0.ep1[Z] = 0.0; // home position Z

nci_manager (op.op_idn, NCIMGR_WR_SOF, &n, &fpos, succf);

if (!*succf) { error("NCIMGR_WR_SOF"); return; }

 

// write some comments to the binary nci

memset (&n, 0, sizeof (nci_bin));

n.gcode = NCI_COMMENTNO;

n.op_idn = op.op_idn;

n.tp_ent_idn = 0;

strncpy (n.u.m1005.comment, "I'm a little teapot short and stout", COMMENT_SIZE-1);

nci_manager (0, NCIMGR_WR, &n, &fpos, succf);

if (!*succf) { error("NCIMGR_WR 1"); return; }

strncpy (n.u.m1005.comment, "This is my handle", COMMENT_SIZE-1);

nci_manager (0, NCIMGR_WR, &n, &fpos, succf);

if (!*succf) { error("NCIMGR_WR 2"); return; }

strncpy (n.u.m1005.comment, "This is my spout", COMMENT_SIZE-1);

nci_manager (0, NCIMGR_WR, &n, &fpos, succf);

if (!*succf) { error("NCIMGR_WR 3"); return; }

 

// now write the 'end of section' marker for the new operation

memset (&n, 0, sizeof (nci_bin));

nci_manager (op.op_idn, NCIMGR_WR_EOS, &n, &fpos, succf);

if (!*succf) { error("NCIMGR_WR_EOS"); return; }

 

// or you could write the end of section with the operation_manager as shown

// operation_manager (&op, OPMGR_NCI_ACCEPT, &e_ptr, succf);

 

// let's post the new operation

nci_manager (op.op_idn, NCIMGR_POST_ONE, &n, &fpos, succf);

if (!*succf) { error("NCIMGR_POST_ONE"); return; }

}

 

void CH_ENTRY m_main(long *ptrs) {

boolean succf;

if (!open_app(ptrs))

return;

test_nci_mgr (&succf);

close_app(ptrs);

}

Link to comment
Share on other sites

Some suggestions:

 

1 - Make sure the succf flag's are returning a value of TRUE after writing the comment lines.

 

2 - Make sure you're writing the NCI_EOS line after those comment lines.

 

3 - The NCI result you're looking is after the binary nci has been converted to ascii. To see what's really in your nci file call up the operation manager, hold down the Ctrl and Shift keys and double-right mouse click on the title bar (or anywhere off a control) of the Operation Manager. This will give you access to a super-duper secret debugging utility known only to a chosen few where you can select and display the contents of the binary nci file. Make sure those comment lines are in there. If not, it's gotta be something simple you're overlooking.

Link to comment
Share on other sites

Thanks rculver00

 

but this did not help.

 

1&2: The c-hook segment comes from the example testassc.c from chdev directory. And as expected, it checks the return code without detecting any errors. Also, there is a call to nci_manager with NCIMGR_WR_EOS argument.

3: This did not work either. Could it be because I am using version 8?

 

Just a stupid question: if there is something in the binary nci file that does not get converted into ascii version, what is the point of having it in the binary file in the first place?

 

Marko

Link to comment
Share on other sites

Yes, I tried, but even with a double-click with the right button while holding shift and ctrl keys I still get the standard pop-up context menu. Was this feature supported in version 8 (that is what I used for my experiments)?

 

In addition to not having errors reported, I have another reason to believe that something actually gets written into the file: fpos parameter gets bigger after every write operation. Now it is just the metter of getting all this stuff back!

 

I was trying to write comments (1005) into the file because that was the simplest test, and it was already supplied as a sample. I am going to try with some real operation next, hoping that is is just the comments that do not work!

 

Marko

Link to comment
Share on other sites
  • 3 months later...

I have finally had a chance to play with this again. First of all I managed to double click "properly" and get the content of the binary nci. What I found was interesting:

 

After the C-hook terminates, this is what is in the nci file:


Contents of binary NCI file

 

* = dead sections

 

Line# Fpos Op# Gcode NCI

 

**** DIRTY NCI! *****

0 0 OP1 G-2 SOS - start of nci section

1 21 OP1 G1006 I'm a little teapot short and stout

2 152 OP1 G-3 EOS - end of nci section

 

When I regenerate toolpath, the content changes:


Contents of binary NCI file

 

* = dead sections

 

Line# Fpos Op# Gcode NCI

 

* 0 0 OP1 G-2 SOS - start of nci section

* 1 21 OP1 G1006 I'm a little teapot short and stout

* 2 152 OP1 G-3 EOS - end of nci section

 

3 170 OP1 G-2 SOS - start of nci section

4 191 OP1 G1006 Manual Entry

5 322 OP1 G-3 EOS - end of nci section

 

What has happened here?

 

And here is my simplified C-hook code:


#include

#include "m_vars.h"

#include "m_init.h"

#include "m_assoc.h"

 

static void error(const char *s, ...) {

char buffer[100];

va_list ap;

va_start(ap, s);

vsprintf(buffer, s, ap);

va_end(ap);

MessageBox(0, buffer, "Error", MB_ICONASTERISK);

}

 

static void test_nci_mgr (boolean *succf) {

operation op;

nci_bin n;

db_ptr_type e_ptr;

long fpos = 0;

 

fpos = 0;

// set binary nci file ptr to the end of the binary nci file

nci_manager (0, NCIMGR_FEND, &n, &fpos, succf);

if (!*succf) { error("NCIMGR_FEND"); return; }

 

// make a manual entry operation using the 1st tool found in the database

memset (&op, 0, sizeof (operation));

op.opcode = TP_MANUAL_ENTRY;

// add a comment

strncpy (op.comment, "I'm a manual entry operation", COMMENT_SIZE-1);

// OPMGR_INIT_ADD writes the 'start of section' -

// no need to call nci_manager (NCIMGR_WR_SOS) - OPMGR_INIT does not write the sos

operation_manager (&op, OPMGR_INIT_ADD, &e_ptr, succf);

if (!*succf) { error("OPMGR_INIT_ADD"); return; }

nci_manager (op.op_idn, NCIMGR_WR_SOS, &n, &fpos, succf);

 

// write some comments to the binary nci

memset (&n, 0, sizeof (nci_bin));

n.gcode = NCI_COMMENT;

n.op_idn = op.op_idn;

n.tp_ent_idn = 0;

strncpy (n.u.m1005.comment, "I'm a little teapot short and stout", COMMENT_SIZE-1);

nci_manager (op.op_idn, NCIMGR_WR, &n, &fpos, succf);

if (!*succf) { error("NCIMGR_WR 1"); return; }

 

// now write the 'end of section' marker for the new operation

memset (&n, 0, sizeof (nci_bin));

nci_manager (op.op_idn, NCIMGR_WR_EOS, &n, &fpos, succf);

if (!*succf) { error("NCIMGR_WR_EOS"); return; }

 

// or you could write the end of section with the operation_manager as shown

// operation_manager (&op, OPMGR_NCI_ACCEPT, &e_ptr, succf);

 

}

 

void CH_ENTRY m_main(long *ptrs) {

boolean succf;

if (!open_app(ptrs))

return;

test_nci_mgr (&succf);

close_app(ptrs);

}

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...