consider the following:
void FuelSystem
::DSLFL_DataReceive(QByteArray data
) {
/* 4)Lower sensor 5)upper Sensor 6)water sensor */
if(data.at(3) == FUEL_SYSTEM)
{
if(data.at(4) == 0x01)
{
FuelPump_start();
command_SV15.append(FUEL_SYSTEM);
command_SV15.append(DSLFL_ST_SV_15);
command_SV15.append(0x01);
emit DSLFL_SendToRS485(command_SV15);
delay(_DELAY_MSEC);
}
else if(data.at(5) == 0x01)
{
FuelPump_stop();
command_HV14.append(FUEL_SYSTEM);
command_HV14.append(DSLFL_HT_SV_14);
command_HV14.append((char) 0x00);
emit DSLFL_SendToRS485(command_HV14);
delay(_DELAY_MSEC);
}
if((data.at(6) == 0x01) && (pumpStat == OFF))
{
command_FTWL_SV9.append(FUEL_SYSTEM);
command_FTWL_SV9.append(DSLFLWaterEvacuate_SV_9);
command_FTWL_SV9.append(0x01);
emit DSLFL_SendToRS485(command_FTWL_SV9);
delay(_DELAY_MSEC);
waterEvacuateTimer->start();
}
}
}
void FuelSystem::delay(int msec){
QTimer::singleShot(msec,
&loop,
NULL);
loop.exec();
}
void FuelSystem::DSLFL_DataReceive(QByteArray data)
{
/* 4)Lower sensor 5)upper Sensor 6)water sensor */
QByteArray command_SV15;
QByteArray command_HV14;
QByteArray command_FTWL_SV9;
if(data.at(3) == FUEL_SYSTEM)
{
if(data.at(4) == 0x01)
{
FuelPump_start();
command_SV15.append(FUEL_SYSTEM);
command_SV15.append(DSLFL_ST_SV_15);
command_SV15.append(0x01);
emit DSLFL_SendToRS485(command_SV15);
delay(_DELAY_MSEC);
}
else if(data.at(5) == 0x01)
{
FuelPump_stop();
command_HV14.append(FUEL_SYSTEM);
command_HV14.append(DSLFL_HT_SV_14);
command_HV14.append((char) 0x00);
emit DSLFL_SendToRS485(command_HV14);
delay(_DELAY_MSEC);
}
if((data.at(6) == 0x01) && (pumpStat == OFF))
{
command_FTWL_SV9.append(FUEL_SYSTEM);
command_FTWL_SV9.append(DSLFLWaterEvacuate_SV_9);
command_FTWL_SV9.append(0x01);
emit DSLFL_SendToRS485(command_FTWL_SV9);
delay(_DELAY_MSEC);
waterEvacuateTimer->start();
}
}
}
void FuelSystem::delay(int msec){
QEventLoop loop;
QTimer::singleShot(msec, &loop, NULL);
loop.exec();
}
To copy to clipboard, switch view to plain text mode
As I send a packet to PLC, I need to delay for some time, waiting for the result of PLC operations. Here, I cannot use sleep() as it is a system call and it will suspend all other
QTimers and the whole program. what I want is to only delay the current particular thread or object for 2 seconds everytime I connect to PLC.
I hope this is clear now. : )
Bookmarks