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