Results 1 to 19 of 19

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User genn's Avatar
    Join Date: Feb:2003
    Location:
    Posts: 1,215

    Virtual COM port -

    virtual COM port.
    , , / . - , , . WaitForSingleObject , , :

    Code:
    OVERLAPPED ov = {0};
    	ov.hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
    
    	LPBYTE szBuff = ( LPBYTE ) malloc( sizeof( BYTE ) * nBytesToRead );
    	if( szBuff == NULL )
    	{
    		// exception memory allocation
    	}
    
    	DWORD dwBytesRead = NULL;
    
    	BOOL bStat = ReadFile( m_hDevice, szBuff, nBytesToRead, &dwBytesRead, &ov );
    
    	if( !bStat )
    	{
    		DWORD err = GetLastError();
    
    		if( err & ERROR_IO_PENDING )
    		{
    			DWORD res = WaitForSingleObject( ov.hEvent, 2000 );
    
    			switch( res )
    			{
    			case WAIT_TIMEOUT:
    				// handle timeout
    				break;
    			case WAIT_OBJECT_0:
    				// read is complete
    				break;
    			default:
    				// do something
    				break;
    			}
    			
    		}
    		else
    		{
    			// handle unexpected error
    		}
    	}
    
    	return szBuff;
    , .
    : bStat TRUE, ReadFile . - . ReadFile FALSE, TRUE 0 . ReadFile Sleep( 100 );, ReadFile , .
    - ( ). overlapped . ReadFile , .

    SetCommMask WaitCommEvent EV_RXCHAR... - WaitCommEvent 0x00 .

    , ?
    , ... .

  2. #2
    Registered abUser ike's Avatar
    Join Date: Jul:2004
    Location: sofi
    Posts: 4,965
    sleep(100);
    ReadFile( m_hDevice, szBuff, nBytesToRead, &dwBytesRead, NULL);

    Have no fear ike iz here.
    CPU Cx486DLC@40MHz, RAM 4MB, VGA Trident 512KB, HDD Conner 160MB, Monitor 14" Color

  3. #3
    Registered User genn's Avatar
    Join Date: Feb:2003
    Location:
    Posts: 1,215
    non-overlapped - , -.
    sleep. 13 .
    8000 WriteFile/ReadFile .
    Sleep
    - , 101 .

  4. #4
    Registered User
    Join Date: Dec:2007
    Location: Sofia
    Posts: 366
    , . , ?

    ReadFile() http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx overlapped IO.

  5. #5
    Registered abUser ike's Avatar
    Join Date: Jul:2004
    Location: sofi
    Posts: 4,965
    Quote Originally Posted by genn View Post
    8000 WriteFile/ReadFile .
    while(true){
    WaitCommEvent(non-overlapped) EV_RXCHAR;
    ReadFile( m_hDevice, szBuff, 1, &dwBytesRead, NULL);
    mybuf=mybuf+szBuff;
    mybuf .
    }//while
    Have no fear ike iz here.
    CPU Cx486DLC@40MHz, RAM 4MB, VGA Trident 512KB, HDD Conner 160MB, Monitor 14" Color

  6. #6
    Registered User
    Join Date: Oct:2003
    Location:
    Posts: 4,317

  7. #7
    Registered User genn's Avatar
    Join Date: Feb:2003
    Location:
    Posts: 1,215
    Quote Originally Posted by bsb View Post
    , , ReadFile , , FALSE , ov.hEvent , .
    , , ... , .
    OVERLAPPED , ... , .... , , MSDN , OV - TRUE 0 .

    @Bombera: ... , , ReadFile ERROR_COLORSPACE_MISMATCH .
    ,

    @ike: ...

  8. #8
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    , .
    ReadFile:
    When reading from a communications device, the behavior of ReadFile is governed by the current communication time-out as set and retrieved by using the SetCommTimeouts and GetCommTimeouts functions. Unpredictable results can occur if you fail to set the time-out values. For more information about communication time-outs, see COMMTIMEOUTS.
    , ' ...!

    ..
    , , :
    if( err & ERROR_IO_PENDING )
    true 2021(ERROR_COLORSPACE_MISMATCH, , , ) .
    Last edited by Bombera; 20th November 2009 at 23:21.
    EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
    Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|

  9. #9
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    COM , CreateFile. FILE_FLAG_OVERLAPPED? , , , manual-reset, OVERLAPPED, , auto-reset event, - ., WaitForSingleObject GetOverlappedResult, -, ReadFileEx , ReadFile, - ..
    EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
    Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|

  10. #10
    Registered User genn's Avatar
    Join Date: Feb:2003
    Location:
    Posts: 1,215
    CreateFile FILE_FLAG_OVERLAPPED. WriteFile . Event- - ...
    , ReadFileEx, "-"

  11. #11
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    , OVERLAPPED . OVERLAPPED e , OVERLAPPED , . , / CancelIO . ,
    ReadFileEx -, . OVERLAPPED_COMPLETION_ROUTINE. , , . /, SleepEx WaitXXXXEx I/O . I/O , , , . . . , .
    , ? .
    Last edited by Bombera; 21st November 2009 at 13:38.
    EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
    Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|

  12. #12
    Registered User genn's Avatar
    Join Date: Feb:2003
    Location:
    Posts: 1,215
    :
    ComInterface, -, , - Open, ReadData, WriteData...

    - ReadData.
    ComIntervace UsbDevice, -. MakeRequest, LPBYTE 8 , -, LPBYTE , - , CRC ..
    WriteData, , ReadData. , WriteData ReadData Sleep( 100 );
    , - 0 , IO_PENDING, ReadFile TRUE.

  13. #13
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    , :
    If an application sets ReadIntervalTimeout and ReadTotalTimeoutMultiplier to MAXDWORD and sets ReadTotalTimeoutConstant to a value greater than zero and less than MAXDWORD, one of the following occurs when the ReadFile function is called:

    * If there are any bytes in the input buffer, ReadFile returns immediately with the bytes in the buffer.
    * If there are no bytes in the input buffer, ReadFile waits until a byte arrives and then returns immediately.
    * If no bytes arrive within the time specified by ReadTotalTimeoutConstant, ReadFile times out.
    .

    , .

    , , , . - , ( ), ( ), ( , , (EOF) - ( )). , , , , . . . , , - , , (- , ). , . , , .
    -, , ().

    - , wait-a, , . (, 2000) , , .

    , ?

    Code:
    OVERLAPPED ov = {0};
    HANDLE hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
    
    LPBYTE szBuff;
    if((szBuff = (LPBYTE) malloc(sizeof(BYTE) * nBytesToRead )) == NULL ){
    	
    }
    
    BOOL bStat;
    DWORD dwBytesRead = 0;
    DWORD dwOffset = 0;
    DWORD dwTotalBytesToRead = nBytesToRead;
    BOOL fBreak = FALSE;
    
    ov.hEvent = hEvent;
    
    // 1
    while(TRUE){
    	
    	bStat = ReadFile( m_hDevice, szBuff + uOffset, nBytesToRead, &dwBytesRead, &ov );
    	if(bStat || ((err = GetLastError) == ERROR_IO_PENDING)){
    		DWORD res = WaitForSingleObject( ov.hEvent, 2000);
    		switch(res){
    			case WAIT_TIMEOUT:
    				// handle timeout
    				// preglevda se ov.Internal - STATUS_PENDING moze da e, operacita ne e gotowa. Ako trqbwa da se izlee na wsqka cena - CancelIO
    				break;
    			case WAIT_OBJECT_0:
    				nBytesToRead -= dwBytesRead; // signed - unsigned srawnenie predpolagam!
    				dwOffset += dwBytesRead;
    				if(dwOffset == dwTotalBytesToRead)
    					fBreak = TRUE;
    				else{
    					ResetEvent(ov.hEvent);
    					ZeroMemory(ov, sizeof(OVERLAPPED)); // che po lesno
    					ov.hEvent = hEvent;
    				}
    				break;
    		}
    		if(fBreak)
    			break;
    	}
    	else
    		break;// indicate error here
    
    }
    
    //  2
    while(TRUE){
    	
    	bStat = ReadFile( m_hDevice, szBuff + uOffset, nBytesToRead, &dwBytesRead, &ov );
    	if(bStat || ((err = GetLastError) == ERROR_IO_PENDING)){
    		
    		DWORD res = SleepEx(2000, TRUE);//         GetOverlappedResult,       
    
    		switch(res){
    			case 0:
    				// handle timeout
    				// preglevda se ov.Internal - STATUS_PENDING moze da e, operacita ne e gotowa. Ako trqbwa da se izlee na wsqka cena - CancelIO
    				break;
    			case WAIT_IO_COMPLETION:
    				nBytesToRead -= dwBytesRead; // signed - unsigned srawnenie predpolagam!
    				dwOffset += dwBytesRead;
    				if(dwOffset == dwTotalBytesToRead)
    					fBreak = TRUE;
    				else{
    					ResetEvent(ov.hEvent);
    					ZeroMemory(ov, sizeof(OVERLAPPED)); // che po lesno
    					ov.hEvent = hEvent;
    				}
    				break;
    		}
    		if(fBreak)
    			break;
    	}
    	else
    		break;// indicate error here
    
    }
    
    CloseHandle(hEvent);
    
    if(dwOffset == 0){
         free(szBuff);
         return NULL;
    }
    return szBuff;
    aut-reset, -. Manual-reset , .
    Last edited by Bombera; 22nd November 2009 at 12:39.
    EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
    Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|

  14. #14
    Registered User genn's Avatar
    Join Date: Feb:2003
    Location:
    Posts: 1,215
    Quote Originally Posted by Bombera View Post
    ...
    , .
    .
    : ReadTotalTimeoutMultiplier = MAXWORD, .
    - .

  15. #15
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    ReadTotalTimeoutConstant - - MAXDWORD, .

    , , .

    ,
    EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
    Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|

  16. #16
    Registered User genn's Avatar
    Join Date: Feb:2003
    Location:
    Posts: 1,215
    " , "

  17. #17
    Registered User genn's Avatar
    Join Date: Feb:2003
    Location:
    Posts: 1,215
    @Bombera: 1, - .
    , ( 8 12 ), .
    , 1058 . ReadFile
    Code:
    ERROR_NOACCESS 998 (0x3E6) Invalid access to memory location.
    - ReadFile, :

    Code:
    COMSTAT ComStat = {0};
    
    	ClearCommError( m_hDev, &dwErrorFlags, &ComStat );
    
    	// Wait for the data to arrive
    	while( ComStat.cbInQue < dwBytesToRead )//( DWORD ) nLimit
    	{
    		ClearCommError( m_hDev, &dwErrorFlags, &ComStat );
    		//cout << ComStat.cbInQue << endl;
    		Sleep( 1 );
    	}
    , ReadFile. while( TRUE ) .
    , ... - Sleep( 100 ); - .

    - ... .

    - @ @@@

  18. #18
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    , 1058 , , ? ? , ReadFile. 4 , malloc, VirtualAlloc, -, 8, -, - . 4 , 4 , , 4 .
    , .
    , .
    EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
    Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|

  19. #19
    Registered User genn's Avatar
    Join Date: Feb:2003
    Location:
    Posts: 1,215
    , szBuff - 1058.
    250- .
    , - , .


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |