[Qt-interest] Delay of code execution

Jason H scorp1us at yahoo.com
Tue Apr 13 20:14:44 CEST 2010


How do you know you've achieved the proper position?
Is there an ACK message that is received or interrupt that is raised?
Ideally, you'd use signal slots, and possibly a state machine. 

Let me give you and example. The elevator in my building is highly reliable and regular. But once in a while it does a double-bounce when you get to your floor (cable issue) and it doesn't open until the motion has stopped. You're guessing that a command completed ok with quickly lead to catastrophe if you assume it succeeded in the allotted time. 

However if I were confident, i would set a 200ms timer and have it read a command queue and just consume a command (channel, position) every 200ms. Then you just have to stuff 3 commands at once. 

Its been a while since I worked with GPIB, but I thought there was an OK message?





----- Original Message ----
From: Matthias Pospiech <matthias.pospiech at gmx.de>
To: Qt-interest <qt-interest at trolltech.com>
Sent: Tue, April 13, 2010 11:52:31 AM
Subject: Re: [Qt-interest] Delay of code execution

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.

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest



      




More information about the Qt-interest-old mailing list