@N thanks Nicklas .... with your suggest I understand a little better the code ... these is myne renewed (and more complete than the last one ... I have not entered the tedious and useless functions to understand the problem here ... but if I can finish the job for January (when my holidays are over) I will post the complete project on the forum:
using namespace std; static RCS_CMD_CHANNEL *emcCommandBuffer = 0; /* I've declared 'emcCommandBuffer' as "static" ... seems these is not right */ static RCS_STAT_CHANNEL *emcStatusBuffer = 0; EMC_STAT *emcStatus = 0; static NML *emcErrorBuffer = 0; static char error_string[NML_INTERNAL_CMS_ERROR] = ""; static int emcCommandSerialNumber = 0; int counter = 0; void QtDro::run() { double thX = 0; double thY = 0; double thZ = 0; double thA = 0; double thB = 0; double thC = 0; double thU = 0; double thV = 0; double thW = 0; QTextStream(stdout) << "First run function" << endl; const char *nmlfile = "/home/bkt/linuxcnc-dev/configs/common/linuxcnc.nml"; RCS_STAT_CHANNEL *stat = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "xemc", nmlfile); RCS_CMD_CHANNEL *cmd = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", nmlfile, 0); NML *error = new NML(emcFormat, "emcError", "xemc", nmlfile); while(1) { if((stat->peek() != EMC_STAT_TYPE) || (!stat->valid())) { QTextStream(stdout) << "while these program NOT run " << endl; break; } else { EMC_STAT *emcStatus = static_cast<EMC_STAT*>(stat->get_address()); if ((thX != emcStatus->motion.traj.position.tran.x) || (thY != emcStatus->motion.traj.position.tran.y) || (thZ != emcStatus->motion.traj.position.tran.z)) { thX = emcStatus->motion.traj.position.tran.x; thY = emcStatus->motion.traj.position.tran.y; thZ = emcStatus->motion.traj.position.tran.z; thA = 0; thB = 0; thC = 0; thU = 0; thV = 0; thW = 0; emit thXYZABCDEF(thX, thY, thZ, thA, thB, thC, thU, thV, thW); } if(counter>=50 && counter<51) { QTextStream(stdout) << "state_msg try zone" << endl; EMC_TASK_SET_STATE state_msg; QTextStream(stdout) << "spy 1" << endl; state_msg.state = EMC_TASK_STATE_OFF; QTextStream(stdout) << "spy 2" << endl; state_msg.serial_number = ++emcCommandSerialNumber; QTextStream(stdout) << "actual value of state_msg: " << state_msg.state << endl; QTextStream(stdout) << "these steps seems right .. now try to write" << endl; cmd->write(&state_msg); // emcCommandBuffer->write(&state_msg); /* these NOT work because not declare 'emcCommandBuffer' with automatic memory allocation with macro "new" */ QTextStream(stdout) << "just write on emcCommandBuffer" << endl; } counter++; } this->msleep(100); } } At these point terminal reply to my good news: bkt@bkt:~/linuxcnc-dev$ QtDro argc: 1 argv: 0x7ffd462f8b98 nmlfile: First Application Start ok First run function state_msg try zone spy 1 spy 2 spy 3 actual value of state_msg: 3 these steps seems right .. now try to write just write on emcCommandBuffer But on Axis Gui SIM that I use as test gui, nothing change .... how can I understand if Lcnc actually had my command? (Axis is active and on on .... after the EMC_TASK_STATE_OFF command I expected the button toggle to go OFF ... maybe launch the wrong command?) regards Il giorno lun 30 dic 2019 alle ore 19:08 N <nicklas.karlsso...@gmail.com> ha scritto: > > @ N *for sure problem is related to gcc version and qt *.... because > if > > run other ubuntu 18.04 with gcc 5.x all work like my develop pc that > > contains gcc 5.5. > > It could also be a coincidence, at least my myself quite often make wrong > conclusion then similar errors happen so I use to double checkt. > > > Any how now I have other problem related previous post ..... > > > > if(counter>=50 && counter<51) > > { > > QTextStream(stdout) << "state_msg try zone" << endl; > > EMC_TASK_SET_STATE *state_msg = (EMC_TASK_SET_STATE > > *)malloc(sizeof (EMC_TASK_SET_STATE)); > > QTextStream(stdout) << "spy 1" << endl; > > // state_msg->clear(); /* these not work because try to > > clear empty array? */ > > QTextStream(stdout) << "spy 2" << endl; > > state_msg->state = EMC_TASK_STATE_OFF; > > QTextStream(stdout) << "spy 3" << endl; > > state_msg->serial_number = ++emcCommandSerialNumber; > > QTextStream(stdout) << "actual value of state_msg: " << > > state_msg->state << endl; > > QTextStream(stdout) << "these steps seems right .. now > > try to write" << endl; > > emcCommandBuffer->write(state_msg); > > QTextStream(stdout) << "just write on emcCommandBuffer" > > << endl; > > free(state_msg); > > > > } > > > > counter++; > > Most often use C and more seldom C++ so I might make misstake without > compiling it for myself first. Would suggest this code to get rid of > malloc(...) function and initialize variable then declared and as a const > if not supposed to change. > > if(counter>=50 && counter<51) > { > QTextStream(stdout) << "state_msg try zone" << endl; > EMC_TASK_SET_STATE state_msg(); > > QTextStream(stdout) << "spy 1" << endl; > state_msg->clear(); /* these not work because try to clear empty > array? */ > QTextStream(stdout) << "spy 2" << endl; > state_msg->state = EMC_TASK_STATE_OFF; > QTextStream(stdout) << "spy 3" << endl; > state_msg->serial_number = ++emcCommandSerialNumber; > QTextStream(stdout) << "actual value of state_msg: " << > state_msg->state << endl; > QTextStream(stdout) << "these steps seems right .. now try to write" << > endl; > emcCommandBuffer->write(state_msg); > QTextStream(stdout) << "just write on emcCommandBuffer" << endl; > } > counter++; > > If I get it correct your code does not work because you allocate memory > but does not create object, C++ have a constructor for this which I > conclude from Linuxcnc code have no parameters. > EMC_TASK_SET_STATE *state_msg = new EMC_TASK_SET_STATE(); > ... > free(state_msg) > > As you free memory at bottom I would suggest to use local variable as in > first example above, then you will not forget to free memory, it also make > possible stack like memory allocation. > EMC_TASK_SET_STATE state_msg(); > > > I use Eclipse then finding declarations is easier even though it does not > work well for C++ or if Linuxcnc code is the problem. Codeblocks might be > another good option if it works. > > > Nicklas Karlsson > > > _______________________________________________ > Emc-developers mailing list > Emc-developers@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/emc-developers > _______________________________________________ Emc-developers mailing list Emc-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/emc-developers