[Qt-interest] Delay of code execution

Matthias Pospiech matthias.pospiech at gmx.de
Tue Apr 13 17:52:31 CEST 2010


Andre Somers schrieb:
> Perhaps you should talk about the issue you want to resolve by using a 
> delay, instead of the question on how to create a delay. 
I use delay in many cases:

Here a few examples:

(1)
    piezoController->selectChannel(0);
    piezoController->setPosition(center_pos);
    delay(200);

    piezoController->selectChannel(1);
    piezoController->setPosition(center_pos);
    delay(200);

    piezoController->selectChannel(2);
    piezoController->setPosition(center_pos);
    delay(200);

The delay time may be exaggerated, but is there to ensure that the 
controller
which is connected via serial bus has finished the last command.

(2)
Here I measure the power in different positions. The RotationStage is 
connected via USB (fast),
and the AgilentPowerSensor which requires arbitrary delay times 
typically in the order of  100 ms.
Additionaly I have to wait for the Sensor to finish the last measurement.

    for (int i=0; i < iArraySize; i++)
    {   
        if(stopped) {
            break;
        }
        RotationStage->PowerOn();
        RotationStage->move(Array[i].position / 
RotationStage->CountsToDegree());       
        RotationStage->WaitForPositionReached(Array[i].position / 
RotationStage->CountsToDegree());
       
        delay(AgilentPowerSensor->AvergingTime());
        Array[i].power = AgilentPowerSensor->Power();       
    }


(3) Here a part of the GPIB communction, which is based on C-code:
The delay is required because the device requires a few 10 ms up to 
several 100 ms
time to recieve, generate and send the answer.

long GPIB_Device::GPIB_GetReply(char *command, char *response)
{
    if(ibcntl < 0) return 0;
    GPIB_Out(command);
    delay (m_GPIB_AnswerDelay);
    GPIB_In((unsigned char *)response,500);
    
response[ibcntl+1]=0;                                                    
    return ibcntl;
}

I all this cases I am talking to external devices and work with external 
libraries or communication over Serial Bus.

Hope this gives a better idea for what I require a delay.

Matthias

EDIT: Yes maybe the QxtSignalWaiter could be a solution. But 
nevertheless I would like to be sure that
all other trivial examples are not solving the problem.




More information about the Qt-interest-old mailing list