[VC6.0] jump out of polling loop - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

[VC6.0] jump out of polling loop

bdcbdc Posts: 5Member
How can i jump out of a loop that polls the LPT.
eg by pressing a button.

[code]
while(1)
{
poortStatus=scanLPT();
UpdateBYTES(poortStatus,S3,S6);
opdrachten(druk,S3,S6);
Sleep(10);
}
[/code]

the problem i have is that i can't press any buttons while this loop is running.
Has someone an answer to this question.

THX.

Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : How can i jump out of a loop that polls the LPT.
    : eg by pressing a button.
    :
    : [code]
    : while(1)
    : {
    : poortStatus=scanLPT();
    : UpdateBYTES(poortStatus,S3,S6);
    : opdrachten(druk,S3,S6);
    : Sleep(10);
    : }
    : [/code]
    :
    : the problem i have is that i can't press any buttons while this loop is running.
    : Has someone an answer to this question.
    :
    : THX.
    :
    [blue]The application type?
    1. Win32 API - [italic]use PeekMessage()[/italic]
    2. Win32 Console - use [italic]_kbhit()[/italic][/blue]
  • dperusodperuso Posts: 55Member
    : : How can i jump out of a loop that polls the LPT.
    : : eg by pressing a button.
    : :
    : : [code]
    : : while(1)
    : : {
    : : poortStatus=scanLPT();
    : : UpdateBYTES(poortStatus,S3,S6);
    : : opdrachten(druk,S3,S6);
    : : Sleep(10);
    : : }
    : : [/code]
    : :
    : : the problem i have is that i can't press any buttons while this loop is running.

    if you don't need to manually abort the loop why not set a condition and use "break" to abort the loop?
    : : Has someone an answer to this question.
    : :
    : : THX.
    : :
    : [blue]The application type?
    : 1. Win32 API - [italic]use PeekMessage()[/italic]
    : 2. Win32 Console - use [italic]_kbhit()[/italic][/blue]
    :

  • bdcbdc Posts: 5Member
    : : : How can i jump out of a loop that polls the LPT.
    : : : eg by pressing a button.
    : : :
    : : : [code]
    : : : while(1)
    : : : {
    : : : poortStatus=scanLPT();
    : : : UpdateBYTES(poortStatus,S3,S6);
    : : : opdrachten(druk,S3,S6);
    : : : Sleep(10);
    : : : }
    : : : [/code]
    : : :
    : : : the problem i have is that i can't press any buttons while this loop is running.
    :
    : if you don't need to manually abort the loop why not set a condition and use "break" to abort the loop?
    : : : Has someone an answer to this question.
    : : :
    : : : THX.
    : : :
    : : [blue]The application type?
    : : 1. Win32 API - [italic]use PeekMessage()[/italic]
    : : 2. Win32 Console - use [italic]_kbhit()[/italic][/blue]
    : :
    :
    :
    Thank you all for the hints,

    I found a solution using a timer and peekmessage:

    [code]
    HANDLE l_Timer;
    MSG l_Message;
    BYTE poortStatus;
    BYTE S3[2]; // array om slechts iets uitgevoerd mag worden op stijgende flank.
    //moet van de vorm [0,1] zijn.
    BYTE S6[2];
    BYTE druk;
    l_Timer = CreateWaitableTimer(NULL, FALSE, NULL);
    l_Timeout.QuadPart = -10 * 10000; // 10ms in 100ns intervals
    while(true)
    {
    // Every iteration should last 10ms
    SetWaitableTimer(l_Timer, &l_Timeout, 0, NULL, NULL, FALSE);

    poortStatus=scanLPT();
    UpdateBYTES(poortStatus,S3,S6);
    opdrachten(druk,S3,S6);

    // Process all pending messages
    while(WaitForSingleObject(l_Timer, 0) == WAIT_TIMEOUT)
    {
    if(PeekMessage(&l_Message, NULL, 0, 0, PM_REMOVE))
    {
    TranslateMessage(&l_Message);
    DispatchMessage(&l_Message);
    }
    else
    {
    // All pending messages done, now wait for the timer
    WaitForSingleObject(l_Timer, INFINITE);
    break;
    }
    }
    }


    }
    [/code]

    THX.
Sign In or Register to comment.