how to loop back for this code ?

This is a discussion on how to loop back for this code ? within the Windows Programming forums, part of the Platform Specific Boards category; why the following code cant loop for contineously reading the data and give output?? please help thank you!! Code: #include ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    117

    how to loop back for this code ?

    why the following code cant loop for contineously reading the data and give output??

    please help
    thank you!!

    Code:
    #include <windows.h>
    #include <iostream>
    #include <stdio.h>
    
    using namespace std;
    
    int main()
    {
            DCB dcb;
    		HANDLE hComm;
            char buff[9];
            DWORD size;
    
            hComm = CreateFile( 
                    "COM1",
                    GENERIC_READ | GENERIC_WRITE,
                    0,
                    0,
                    OPEN_EXISTING,
                    FILE_ATTRIBUTE_NORMAL,
                    0
                    );
    		dcb.BaudRate = 4800;
    		dcb.ByteSize = 8;
    		dcb.Parity = NOPARITY;
    		dcb.StopBits = ONESTOPBIT;
    
    
    
            if( hComm == INVALID_HANDLE_VALUE ) exit( 1 );
            while(true)
           {
            ReadFile(hComm, buff, 8, &size, NULL);
            cout << buff << endl;
            getchar();
    	}    
           return 0;
    }
    Last edited by Jasonymk; 02-28-2003 at 07:03 AM.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    while(true)
    This should guarantee an infinite loop since you have no breaks in it.
    if( hComm == INVALID_HANDLE_VALUE ) exit( 1 );
    Obviously, this fails and exits. Are you sure the file you open exists? "Com" (with no extention) isn't exatcly a normal filename.
    Last edited by Magos; 02-28-2003 at 09:49 AM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    He's opening the COM1 serial port...
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by adrianxw
    He's opening the COM1 serial port...
    Oh...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looking for a way to store listbox data
    By Welder in forum C Programming
    Replies: 20
    Last Post: 11-01-2007, 11:48 PM
  2. return to start coding?
    By talnoy in forum C++ Programming
    Replies: 1
    Last Post: 01-26-2006, 02:48 AM
  3. snippet of for loop code problem
    By rayrayj52 in forum C++ Programming
    Replies: 8
    Last Post: 10-19-2004, 02:36 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21