Results 1 to 19 of 19
Thread: Virtual COM port -
Hybrid View
-
20th November 2009 20:35 #1
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
.
, ?
, ... .
-
20th November 2009 20:47 #2
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
-
20th November 2009 21:13 #3
non-overlapped - , -.
sleep. 13 .
8000 WriteFile/ReadFile .
Sleep
- , 101
.
-
20th November 2009 21:35 #4Registered User
Join Date: Dec:2007
Location: Sofia
Posts: 366
, . , ?
ReadFile() http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx overlapped IO.
-
20th November 2009 22:35 #5
-
20th November 2009 22:51 #6Registered User
Join Date: Oct:2003
Location:
Posts: 4,317
:
http://msdn.microsoft.com/en-us/libr...71(VS.85).aspx ,
, , 0 . ?
-
21st November 2009 12:54 #7
-
20th November 2009 22:51 #8
, .
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.
..
, , :
true 2021(ERROR_COLORSPACE_MISMATCH, , , ) .if( err & ERROR_IO_PENDING )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|
-
21st November 2009 13:06 #9
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|
-
21st November 2009 13:11 #10
CreateFile FILE_FLAG_OVERLAPPED. WriteFile . Event- - ...
, ReadFileEx, "-"
-
21st November 2009 13:24 #11
, 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|
-
21st November 2009 14:25 #12
:
ComInterface, -, , - Open, ReadData, WriteData...
- ReadData.
ComIntervace UsbDevice, -. MakeRequest, LPBYTE 8 , -, LPBYTE , - , CRC ..
WriteData, , ReadData. , WriteData ReadData Sleep( 100 );
, - 0 , IO_PENDING, ReadFile TRUE.
-
21st November 2009 15:26 #13
, :
.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) , , .
, ?
aut-reset, -. Manual-reset , .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;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|
-
22nd November 2009 12:29 #14
-
22nd November 2009 12:42 #15
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|
-
22nd November 2009 12:48 #16
-
23rd November 2009 16:18 #17
@Bombera: 1, - .
, ( 8 12 ), .
, 1058 . ReadFile
- ReadFile, :Code:ERROR_NOACCESS 998 (0x3E6) Invalid access to memory location.
, ReadFile. while( TRUE ) .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 ); }
, ... - Sleep( 100 ); -
.
- ... .
- @ @@@
-
23rd November 2009 16:44 #18
, 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|
-
23rd November 2009 17:07 #19




Reply With Quote


Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in