these pieces of code seems to run quite good ... every time "stat" break
while loop (sometime EMC_TASK_SET_STATE show issuing messages ... in that
moment "stat" break while loop ... at the end example of ISSUING messages
from terminal)

#include "QtDro.h"



using namespace std;

// the NML channels to the EMC task
RCS_CMD_CHANNEL *emcCommandBuffer ;
RCS_STAT_CHANNEL *emcStatusBuffer ;
EMC_STAT *emcStatus;
EMC_CMD_MSG *emcCmd;

// the NML channel for errors
static NML *emcErrorBuffer = 0;
static char error_string[NML_INTERNAL_CMS_ERROR] = "";

// the current command numbers, set up updateStatus(), used in main()
static int emcCommandSerialNumber = 0;

int counter = 0;



QtDro::~QtDro()
{
  //  inifile.Close();
    this->Stop;

}


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/sim/axis/emc.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);
    NML *error = new NML(emcFormat, "emcError", "xemc", nmlfile);

    //************ try to connect to EMC cmd
  /*  if (emcCommandBuffer == 0) {
        emcCommandBuffer =  new RCS_CMD_CHANNEL(emcFormat, "emcCommand",
"xemc", nmlfile, 0);
        QTextStream(stdout) <<  "cmd buffer is valid  " << endl;
    if (!emcCommandBuffer->valid()) {
        delete emcCommandBuffer;
        emcCommandBuffer = 0;
        QTextStream(stdout) <<  "cmd buffer is NOT valid  " << endl;
        return;
    }
}*/



    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());
            //EMC_CMD_MSG *emcCmd =
static_cast<EMC_CMD_MSG*>(cmd->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>=80 && counter<81)
            {

                 QTextStream(stdout) <<  "state_msg try zone" << endl;
                 EMC_TASK_SET_STATE  state_msg;
                // EMC_TASK_PLAN_PAUSE emc_task_plan_pause_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(&emc_task_plan_pause_msg);
                 cmd->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 = 0;

            }

            counter++;

        }

         this->msleep(100);
    }


}


*ISSUING mESSAGES FROm TERMINAL*




*Issuing EMC_TRAJ_LINEAR_MOVE -- (  +220,+128,
 
+0,4.656469,0.324366,0.118110,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,
   +1,4.000000,4.000000,100.000000,    +0,    -1,)Issuing
EMC_TASK_SET_STATE -- (  +505,+24,  +140,    +3,)Issuing
EMC_TASK_PLAN_SYNCH -- (  +516,+24,    +0,)*


*in these moment "stat" break while loop .... if someone have an ideas ...
welcome*


*bkt*

Il giorno gio 2 gen 2020 alle ore 15:17 theman whosoldtheworld <
[email protected]> ha scritto:

> @bkt ... nothings appens because (after start linuxcnc from terminal ...)
>
> **********************************************************
> * Current Directory = /home/bkt/linuxcnc-dev/configs/sim/axis
> *
> **********************************************************
> * BufferName = emcCommand
> * BufferType = 0
> * ProcessName = emc
> * Configuration File =
> /home/bkt/linuxcnc-dev/configs/sim/axis/emc.nml                       /*
> write emc.nml or linuxcnc.nml seems the same things but file is different
> ... not know why  */
> * CMS Status = -3 (CMS_INTERNAL_ACCESS_ERROR: An error occured during an
> internal access function. )
> * Recent errors repeated:
>
> CMS:(emcCommand) Message size of 9288674231451648 exceeds maximum of 8120
>
>
>
> * BufferLine: B emcCommand            SHMEM   localhost       8192    0
>     0       1       16 1001 TCP=5005 xdr
> * ProcessLine: P emc           emcCommand      LOCAL   localhost       RW
>      0       1.0     0       0
> * error_type = 5 (NML_INTERNAL_CMS_ERROR)
> ************************************************************
>
> libnml/cms/cms_in.cc 708:* CMS:(emcCommand) Message size of
> 9288674231451649 exceeds maximum of 8120*
>
>
> or in QtDro terminal:
>
> libnml/cms/cms_xup.cc 303: CMS_XDR_UPDATER: Can't rewind because
> current_stream is NULL.
> libnml/cms/cms_xup.cc 279: CMS_XDR_UPDATER: Required pointer is NULL.
> libnml/cms/cms_xup.cc 279: CMS_XDR_UPDATER: Required pointer is NULL.
>
>
>
> *Seems stream is null so it impossible "write" sometings .... but *
>
> emcStatus->motion.traj.position.tran.x;
> emcStatus->motion.traj.position.tran.y;
> emcStatus->motion.traj.position.tran.z;
>
> Work great in any case ....
>
> bkt
>
> Il giorno mar 31 dic 2019 alle ore 09:10 theman whosoldtheworld <
> [email protected]> ha scritto:
>
>> @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 <[email protected]>
>> 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
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/emc-developers
>>>
>>

_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to