0

I am communicating with a FESTO controller at FHPP mode as already mentionned in my earlier question Qt/C++ communication with CMMO-ST-C5-1-LKP Festo controller over Modbus TCP , I'm trying to elaborate a continuous Modbus TCP communication. I created a function Send_data(), that allows to send a Modbus TCP packet, to make it a continuous communication I used a global QTimer, and made it fire this function every 100 milliseconds :

m_timer->start(100) connect(m_timer, &QTimer::timeout, [this]() { Send_Data(); });

There is no problem when the configuration bits are fixed to 0 or 1, I can then change my global variable QString Data packet and it will send that. The problem is when a bit (configuration or positioning) must be triggered as a rising or falling edge. This creates reassembled TCP segments (as shown in the figure below) when I try to do this :

void Stepper::trigger_bit(bit bitName){
switch (bitName) {
case(RES): {    
    activer_reset();break;
}
case(HOM): {
    activer_homing();
    break;
}
case(START): {
    activer_start();
    break;
}
case(CLEAR): {
    activer_clear();
    break;
}
case(HALT): {
    desactiver_halt();
    break;
}
}
connect(m_timer, &QTimer::timeout, [this]() {
    Send_Data();
});
switch (bitName) {
    case(RES): {
    desactiver_reset();break;
}
case(HOM): {
    desactiver_homing();
    break;
}
case(START): {
    desactiver_start();
    break;
}
case(CLEAR): {
    desactiver_clear();
    break;
}
case(HALT): {
    activer_halt();
    break;
}
}
connect(m_timer, &QTimer::timeout, [this]() {
    Send_Data();
});} 

(These methods inside of the trigger_bit(bit bitName) modify the bits in the QString Data variable.)

enter image description here

At a stage when I try to move the motor for a second time, I need to re-trigger the START bit, I do that but it's not triggered and the command doesn't execute by the motor. I'm pre assuming that the reassembled TCP segment is the problem, because each time I press the move button (I trigger the START bit with a different position) one or more TCP segment is added to the packet sent. Normally it means that the Send_Data() function keeps triggering with it's old calling but always triggering with the new QString Data. Is there a solution to avoid this problem? like creating a mutex variable on the Send_Data() function.

Khaled
  • 81
  • 1
  • 14

1 Answers1

0

I do not fully understand your question but I want to clarify that TCP does not guarantee that the sent packets are received at the other end with the same chunks with which it was sent.

It is possible that 100 + 100 bytes will be sent and at the other end a 200 byte chunk will be received or two pieces one of 150 and another of 50 will be received. There is no way to prevent this for happening, TCP works this way

The receiving program must be prepared to recompose the fragments.

from56
  • 3,976
  • 2
  • 13
  • 23