2005-06-24 18:19:40 +00:00
/*
2001-03-31 01:17:30 +00:00
* COPYRIGHT : See COPYING in the top level directory
* PROJECT : ReactOS system libraries
* FILE : lib / kernel32 / misc / comm . c
* PURPOSE : Comm functions
* PROGRAMMER : Ariadne ( ariadne @ xs4all . nl )
* modified from WINE [ Onno Hovers , ( onno @ stack . urc . tue . nl ) ]
2002-10-03 18:26:53 +00:00
* Robert Dickenson ( robd @ mok . lvcom . com )
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
* Saveliy Tretiakov ( saveliyt @ mail . ru )
2005-06-24 18:19:40 +00:00
* Dmitry Philippov ( shedon @ mail . ru )
2001-03-31 01:17:30 +00:00
* UPDATE HISTORY :
* Created 01 / 11 / 98
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
* RDD ( 30 / 09 / 2002 ) implemented many function bodies to call serial driver .
* KJK ( 11 / 02 / 2003 ) implemented BuildCommDCB & BuildCommDCBAndTimeouts
2005-05-09 01:46:57 +00:00
* ST ( 21 / 03 / 2005 ) implemented GetCommProperties
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
* ST ( 24 / 03 / 2005 ) implemented ClearCommError . Corrected many functions .
2005-04-06 17:40:25 +00:00
* ST ( 05 / 04 / 2005 ) implemented CommConfigDialog
2005-06-24 18:19:40 +00:00
* DP ( 11 / 06 / 2005 ) implemented GetCommConfig
* DP ( 12 / 06 / 2005 ) implemented SetCommConfig
2008-12-26 22:09:38 +00:00
* KJK ( 26 / 12 / 2008 ) reimplemented BuildCommDCB & BuildCommDCBAndTimeouts elsewhere
2005-05-09 01:46:57 +00:00
*
2001-03-31 01:17:30 +00:00
*/
2003-01-15 21:24:36 +00:00
# include <k32.h>
2007-01-26 07:22:19 +00:00
# undef SERIAL_LSRMST_ESCAPE
# undef SERIAL_LSRMST_LSR_DATA
# undef SERIAL_LSRMST_LSR_NODATA
# undef SERIAL_LSRMST_MST
# undef SERIAL_IOC_FCR_FIFO_ENABLE
# undef SERIAL_IOC_FCR_RCVR_RESET
# undef SERIAL_IOC_FCR_XMIT_RESET
# undef SERIAL_IOC_FCR_DMA_MODE
# undef SERIAL_IOC_FCR_RES1
# undef SERIAL_IOC_FCR_RES2
# undef SERIAL_IOC_FCR_RCVR_TRIGGER_LSB
# undef SERIAL_IOC_FCR_RCVR_TRIGGER_MSB
# undef SERIAL_IOC_MCR_DTR
# undef SERIAL_IOC_MCR_RTS
# undef SERIAL_IOC_MCR_OUT1
# undef SERIAL_IOC_MCR_OUT2
# undef SERIAL_IOC_MCR_LOOP
2008-11-26 19:04:55 +00:00
# undef IOCTL_SERIAL_LSRMST_INSERT
2007-01-26 07:22:19 +00:00
# include <ntddser.h>
2002-10-03 18:26:53 +00:00
2003-01-15 21:24:36 +00:00
# define NDEBUG
2007-09-02 19:42:22 +00:00
# include <debug.h>
2002-10-03 18:26:53 +00:00
2008-12-26 22:09:38 +00:00
static const WCHAR lpszSerialUI [ ] = {
2008-04-03 10:50:57 +00:00
' s ' , ' e ' , ' r ' , ' i ' , ' a ' , ' l ' , ' u ' , ' i ' , ' . ' , ' d ' , ' l ' , ' l ' , 0 } ;
2003-07-10 18:50:51 +00:00
/*
* @ implemented
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
ClearCommBreak ( HANDLE hFile )
2001-03-31 01:17:30 +00:00
{
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
DWORD dwBytesReturned ;
2005-05-09 01:46:57 +00:00
return DeviceIoControl ( hFile , IOCTL_SERIAL_SET_BREAK_OFF ,
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
NULL , 0 , NULL , 0 , & dwBytesReturned , NULL ) ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
* @ implemented
2003-07-10 18:50:51 +00:00
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
ClearCommError ( HANDLE hFile , LPDWORD lpErrors , LPCOMSTAT lpComStat )
2001-03-31 01:17:30 +00:00
{
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
BOOL status = FALSE ;
2002-10-03 18:26:53 +00:00
DWORD dwBytesReturned ;
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
SERIAL_STATUS SerialStatus ;
2005-05-09 01:46:57 +00:00
status = DeviceIoControl ( hFile , IOCTL_SERIAL_GET_COMMSTATUS , NULL , 0 ,
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
& SerialStatus , sizeof ( SERIAL_STATUS ) , & dwBytesReturned , NULL ) ;
2005-05-09 01:46:57 +00:00
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
if ( ! NT_SUCCESS ( status ) )
{
return status ;
}
2005-05-09 01:46:57 +00:00
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
if ( lpErrors )
{
* lpErrors = 0 ;
if ( SerialStatus . Errors & SERIAL_ERROR_BREAK )
* lpErrors | = CE_BREAK ;
if ( SerialStatus . Errors & SERIAL_ERROR_FRAMING )
* lpErrors | = CE_FRAME ;
if ( SerialStatus . Errors & SERIAL_ERROR_OVERRUN )
* lpErrors | = CE_OVERRUN ;
if ( SerialStatus . Errors & SERIAL_ERROR_QUEUEOVERRUN )
* lpErrors | = CE_RXOVER ;
if ( SerialStatus . Errors & SERIAL_ERROR_PARITY )
* lpErrors | = CE_RXPARITY ;
}
2005-05-09 01:46:57 +00:00
if ( lpComStat )
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
{
ZeroMemory ( lpComStat , sizeof ( COMSTAT ) ) ;
2005-05-09 01:46:57 +00:00
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
if ( SerialStatus . HoldReasons & SERIAL_TX_WAITING_FOR_CTS )
lpComStat - > fCtsHold = TRUE ;
if ( SerialStatus . HoldReasons & SERIAL_TX_WAITING_FOR_DSR )
lpComStat - > fDsrHold = TRUE ;
if ( SerialStatus . HoldReasons & SERIAL_TX_WAITING_FOR_DCD )
lpComStat - > fRlsdHold = TRUE ;
if ( SerialStatus . HoldReasons & SERIAL_TX_WAITING_FOR_XON )
lpComStat - > fXoffHold = TRUE ;
if ( SerialStatus . HoldReasons & SERIAL_TX_WAITING_XOFF_SENT )
lpComStat - > fXoffSent = TRUE ;
2005-05-09 01:46:57 +00:00
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
if ( SerialStatus . EofReceived )
lpComStat - > fEof = TRUE ;
2005-05-09 01:46:57 +00:00
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
if ( SerialStatus . WaitForImmediate )
lpComStat - > fTxim = TRUE ;
lpComStat - > cbInQue = SerialStatus . AmountInInQueue ;
lpComStat - > cbOutQue = SerialStatus . AmountInOutQueue ;
2002-10-03 18:26:53 +00:00
}
return TRUE ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
2005-04-06 17:40:25 +00:00
* @ implemented
2003-07-10 18:50:51 +00:00
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
CommConfigDialogA ( LPCSTR lpszName , HWND hWnd , LPCOMMCONFIG lpCC )
2001-03-31 01:17:30 +00:00
{
2005-04-07 18:01:29 +00:00
PWCHAR NameW ;
2005-07-29 13:50:05 +00:00
DWORD result ;
2005-05-09 01:46:57 +00:00
2005-04-07 18:01:29 +00:00
/* don't use the static thread buffer so operations in serialui
don ' t overwrite the string */
if ( ! ( NameW = FilenameA2W ( lpszName , TRUE ) ) )
2005-04-06 17:40:25 +00:00
{
return FALSE ;
}
2005-05-09 01:46:57 +00:00
2005-04-07 18:01:29 +00:00
result = CommConfigDialogW ( NameW , hWnd , lpCC ) ;
RtlFreeHeap ( RtlGetProcessHeap ( ) , 0 , NameW ) ;
2005-05-09 01:46:57 +00:00
2005-04-06 17:40:25 +00:00
return result ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
2005-04-06 17:40:25 +00:00
* @ implemented
2003-07-10 18:50:51 +00:00
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
CommConfigDialogW ( LPCWSTR lpszName , HWND hWnd , LPCOMMCONFIG lpCC )
2001-03-31 01:17:30 +00:00
{
2008-11-30 11:42:05 +00:00
DWORD ( WINAPI * drvCommDlgW ) ( LPCWSTR , HWND , LPCOMMCONFIG ) ;
2005-04-06 17:40:25 +00:00
HMODULE hSerialuiDll ;
2005-07-29 13:50:05 +00:00
DWORD result ;
2005-05-09 01:46:57 +00:00
2005-04-06 17:40:25 +00:00
//FIXME: Get dll name from registry. (setupapi needed)
if ( ! ( hSerialuiDll = LoadLibraryW ( L " serialui.dll " ) ) )
{
DPRINT ( " CommConfigDialogW: serialui.dll not found. \n " ) ;
return FALSE ;
}
2005-05-09 01:46:57 +00:00
2008-11-30 11:42:05 +00:00
drvCommDlgW = ( DWORD ( WINAPI * ) ( LPCWSTR , HWND , LPCOMMCONFIG ) )
2005-07-29 13:50:05 +00:00
GetProcAddress ( hSerialuiDll , " drvCommConfigDialogW " ) ;
2005-05-09 01:46:57 +00:00
2005-04-06 17:40:25 +00:00
if ( ! drvCommDlgW )
{
DPRINT ( " CommConfigDialogW: serialui does not export drvCommConfigDialogW \n " ) ;
FreeLibrary ( hSerialuiDll ) ;
return FALSE ;
}
2005-05-09 01:46:57 +00:00
2005-04-06 17:40:25 +00:00
result = drvCommDlgW ( lpszName , hWnd , lpCC ) ;
2005-07-29 13:50:05 +00:00
SetLastError ( result ) ;
2005-04-06 17:40:25 +00:00
FreeLibrary ( hSerialuiDll ) ;
2008-12-26 22:09:38 +00:00
2005-07-29 13:50:05 +00:00
return ( result = = ERROR_SUCCESS ? TRUE : FALSE ) ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
* @ implemented
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
EscapeCommFunction ( HANDLE hFile , DWORD dwFunc )
2001-03-31 01:17:30 +00:00
{
2004-01-23 17:18:16 +00:00
BOOL result = FALSE ;
2002-10-03 18:26:53 +00:00
DWORD dwBytesReturned ;
switch ( dwFunc ) {
2005-05-09 01:46:57 +00:00
case CLRDTR : // Clears the DTR (data-terminal-ready) signal.
2002-10-03 18:26:53 +00:00
result = DeviceIoControl ( hFile , IOCTL_SERIAL_CLR_DTR , NULL , 0 , NULL , 0 , & dwBytesReturned , NULL ) ;
break ;
2005-05-09 01:46:57 +00:00
case CLRRTS : // Clears the RTS (request-to-send) signal.
2002-10-03 18:26:53 +00:00
result = DeviceIoControl ( hFile , IOCTL_SERIAL_CLR_RTS , NULL , 0 , NULL , 0 , & dwBytesReturned , NULL ) ;
break ;
2005-05-09 01:46:57 +00:00
case SETDTR : // Sends the DTR (data-terminal-ready) signal.
2002-10-03 18:26:53 +00:00
result = DeviceIoControl ( hFile , IOCTL_SERIAL_SET_DTR , NULL , 0 , NULL , 0 , & dwBytesReturned , NULL ) ;
break ;
2005-05-09 01:46:57 +00:00
case SETRTS : // Sends the RTS (request-to-send) signal.
2002-10-03 18:26:53 +00:00
result = DeviceIoControl ( hFile , IOCTL_SERIAL_SET_RTS , NULL , 0 , NULL , 0 , & dwBytesReturned , NULL ) ;
break ;
2005-05-09 01:46:57 +00:00
case SETXOFF : // Causes transmission to act as if an XOFF character has been received.
2002-10-03 18:26:53 +00:00
result = DeviceIoControl ( hFile , IOCTL_SERIAL_SET_XOFF , NULL , 0 , NULL , 0 , & dwBytesReturned , NULL ) ;
break ;
2005-05-09 01:46:57 +00:00
case SETXON : // Causes transmission to act as if an XON character has been received.
2002-10-03 18:26:53 +00:00
result = DeviceIoControl ( hFile , IOCTL_SERIAL_SET_XON , NULL , 0 , NULL , 0 , & dwBytesReturned , NULL ) ;
break ;
2005-05-09 01:46:57 +00:00
case SETBREAK : // Suspends character transmission and places the transmission line in a break state until the ClearCommBreak function is called (or EscapeCommFunction is called with the CLRBREAK extended function code). The SETBREAK extended function code is identical to the SetCommBreak function. Note that this extended function does not flush data that has not been transmitted.
2002-10-03 18:26:53 +00:00
result = DeviceIoControl ( hFile , IOCTL_SERIAL_SET_BREAK_ON , NULL , 0 , NULL , 0 , & dwBytesReturned , NULL ) ;
break ;
2005-05-09 01:46:57 +00:00
case CLRBREAK : // Restores character transmission and places the transmission line in a nonbreak state. The CLRBREAK extended function code is identical to the ClearCommBreak function.
2002-10-03 18:26:53 +00:00
result = DeviceIoControl ( hFile , IOCTL_SERIAL_SET_BREAK_OFF , NULL , 0 , NULL , 0 , & dwBytesReturned , NULL ) ;
break ;
default :
DPRINT ( " EscapeCommFunction() WARNING: unknown function code \n " ) ;
SetLastError ( ERROR_CALL_NOT_IMPLEMENTED ) ;
break ;
}
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
return result ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
2005-06-24 18:19:40 +00:00
* @ implemented
2003-07-10 18:50:51 +00:00
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
GetCommConfig ( HANDLE hCommDev , LPCOMMCONFIG lpCC , LPDWORD lpdwSize )
2001-03-31 01:17:30 +00:00
{
2005-06-24 18:19:40 +00:00
BOOL ReturnValue = FALSE ;
2005-06-26 12:51:17 +00:00
LPCOMMPROP lpComPort ;
2005-06-24 18:19:40 +00:00
DPRINT ( " GetCommConfig(%d, %p, %p) \n " , hCommDev , lpCC , lpdwSize ) ;
2005-06-26 12:51:17 +00:00
lpComPort = RtlAllocateHeap ( hProcessHeap ,
HEAP_ZERO_MEMORY ,
sizeof ( COMMPROP ) + 0x100 ) ;
2005-06-24 18:19:40 +00:00
if ( NULL = = lpComPort ) {
DPRINT ( " GetCommConfig() - ERROR_NOT_ENOUGH_MEMORY \n " ) ;
SetLastError ( ERROR_NOT_ENOUGH_MEMORY ) ;
return FALSE ;
}
2008-12-26 22:09:38 +00:00
if ( ( NULL = = lpdwSize )
2005-06-24 18:19:40 +00:00
| | ( NULL = = lpCC ) ) {
DPRINT ( " GetCommConfig() - invalid parameter \n " ) ;
2005-06-24 18:28:22 +00:00
SetLastError ( ERROR_INVALID_PARAMETER ) ;
2005-06-24 18:19:40 +00:00
ReturnValue = FALSE ;
}
else
{
lpComPort - > wPacketLength = sizeof ( COMMPROP ) + 0x100 ;
lpComPort - > dwProvSpec1 = COMMPROP_INITIALIZED ;
ReturnValue = GetCommProperties ( hCommDev , lpComPort ) ;
if ( ReturnValue )
{
lpCC - > dwSize = sizeof ( COMMCONFIG ) ;
lpCC - > wVersion = 1 ;
lpCC - > wReserved = 0 ;
lpCC - > dwProviderSubType = lpComPort - > dwProvSubType ;
lpCC - > dwProviderSize = lpComPort - > dwProvSpec2 ;
if ( 0 = = lpComPort - > dwProvSpec2 ) {
lpCC - > dwProviderOffset = 0 ;
} else {
lpCC - > dwProviderOffset = ( ULONG_PTR ) & lpCC - > wcProviderData [ 0 ] - ( ULONG_PTR ) lpCC ;
}
if ( ( lpCC - > dwProviderSize + lpCC - > dwSize ) > * lpdwSize ) {
2005-06-24 18:28:22 +00:00
DPRINT ( " GetCommConfig() - ERROR_INSUFFICIENT_BUFFER \n " ) ;
SetLastError ( ERROR_INSUFFICIENT_BUFFER ) ;
2005-06-24 18:19:40 +00:00
ReturnValue = FALSE ;
} else {
RtlCopyMemory ( lpCC - > wcProviderData , lpComPort - > wcProvChar , lpCC - > dwProviderSize ) ;
ReturnValue = GetCommState ( hCommDev , & lpCC - > dcb ) ;
}
2006-07-10 08:33:02 +00:00
* lpdwSize = lpCC - > dwSize + lpCC - > dwProviderSize ;
2005-06-24 18:19:40 +00:00
}
}
RtlFreeHeap ( hProcessHeap , 0 , lpComPort ) ;
return ( ReturnValue ) ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
* @ implemented
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
GetCommMask ( HANDLE hFile , LPDWORD lpEvtMask )
2001-03-31 01:17:30 +00:00
{
2002-10-03 18:26:53 +00:00
DWORD dwBytesReturned ;
2005-05-09 01:46:57 +00:00
return DeviceIoControl ( hFile , IOCTL_SERIAL_GET_WAIT_MASK ,
2002-10-03 18:26:53 +00:00
NULL , 0 , lpEvtMask , sizeof ( DWORD ) , & dwBytesReturned , NULL ) ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
* @ implemented
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
GetCommModemStatus ( HANDLE hFile , LPDWORD lpModemStat )
2001-03-31 01:17:30 +00:00
{
2002-10-03 18:26:53 +00:00
DWORD dwBytesReturned ;
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
return DeviceIoControl ( hFile , IOCTL_SERIAL_GET_MODEMSTATUS ,
2002-10-03 18:26:53 +00:00
NULL , 0 , lpModemStat , sizeof ( DWORD ) , & dwBytesReturned , NULL ) ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
2005-03-21 10:32:15 +00:00
* @ implemented
2003-07-10 18:50:51 +00:00
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
GetCommProperties ( HANDLE hFile , LPCOMMPROP lpCommProp )
2001-03-31 01:17:30 +00:00
{
2005-03-21 10:32:15 +00:00
DWORD dwBytesReturned ;
2005-05-09 01:46:57 +00:00
return DeviceIoControl ( hFile , IOCTL_SERIAL_GET_PROPERTIES , 0 , 0 ,
2005-03-21 10:32:15 +00:00
lpCommProp , sizeof ( COMMPROP ) , & dwBytesReturned , 0 ) ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
* @ implemented
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
GetCommState ( HANDLE hFile , LPDCB lpDCB )
2001-03-31 01:17:30 +00:00
{
2004-01-23 17:18:16 +00:00
BOOL result = FALSE ;
2002-10-03 18:26:53 +00:00
DWORD dwBytesReturned ;
SERIAL_BAUD_RATE BaudRate ;
SERIAL_HANDFLOW HandFlow ;
SERIAL_CHARS SpecialChars ;
SERIAL_LINE_CONTROL LineControl ;
DPRINT ( " GetCommState(%d, %p) \n " , hFile , lpDCB ) ;
if ( lpDCB = = NULL ) {
2008-04-03 10:50:57 +00:00
SetLastError ( ERROR_INVALID_PARAMETER ) ;
2002-10-03 18:26:53 +00:00
DPRINT ( " ERROR: GetCommState() - NULL DCB pointer \n " ) ;
return FALSE ;
}
2008-04-03 10:50:57 +00:00
if ( ! DeviceIoControl ( hFile , IOCTL_SERIAL_GET_BAUD_RATE ,
2009-01-18 13:56:09 +00:00
NULL , 0 , & BaudRate , sizeof ( BaudRate ) , & dwBytesReturned , NULL ) | |
2008-04-03 10:50:57 +00:00
! DeviceIoControl ( hFile , IOCTL_SERIAL_GET_LINE_CONTROL ,
2009-01-18 13:56:09 +00:00
NULL , 0 , & LineControl , sizeof ( LineControl ) , & dwBytesReturned , NULL ) | |
2008-04-03 10:50:57 +00:00
! DeviceIoControl ( hFile , IOCTL_SERIAL_GET_HANDFLOW ,
2009-01-18 13:56:09 +00:00
NULL , 0 , & HandFlow , sizeof ( HandFlow ) , & dwBytesReturned , NULL ) | |
2008-04-03 10:50:57 +00:00
! DeviceIoControl ( hFile , IOCTL_SERIAL_GET_CHARS ,
2009-01-18 13:56:09 +00:00
NULL , 0 , & SpecialChars , sizeof ( SpecialChars ) , & dwBytesReturned , NULL ) )
2008-04-03 10:50:57 +00:00
return FALSE ;
2005-05-09 01:46:57 +00:00
2008-04-03 10:50:57 +00:00
memset ( lpDCB , 0 , sizeof ( * lpDCB ) ) ;
lpDCB - > DCBlength = sizeof ( * lpDCB ) ;
2002-10-03 18:26:53 +00:00
2008-04-03 10:50:57 +00:00
lpDCB - > fBinary = 1 ;
lpDCB - > fParity = 0 ;
2002-10-03 18:26:53 +00:00
lpDCB - > BaudRate = BaudRate . BaudRate ;
2008-04-03 10:50:57 +00:00
lpDCB - > StopBits = LineControl . StopBits ;
lpDCB - > Parity = LineControl . Parity ;
lpDCB - > ByteSize = LineControl . WordLength ;
2002-10-03 18:26:53 +00:00
if ( HandFlow . ControlHandShake & SERIAL_CTS_HANDSHAKE ) {
lpDCB - > fOutxCtsFlow = 1 ;
}
if ( HandFlow . ControlHandShake & SERIAL_DSR_HANDSHAKE ) {
lpDCB - > fOutxDsrFlow = 1 ;
}
if ( HandFlow . ControlHandShake & SERIAL_DTR_CONTROL ) {
lpDCB - > fDtrControl = 1 ;
}
if ( HandFlow . ControlHandShake & SERIAL_DTR_HANDSHAKE ) {
lpDCB - > fDtrControl = 2 ;
}
if ( HandFlow . ControlHandShake & SERIAL_RTS_CONTROL ) {
lpDCB - > fRtsControl = 1 ;
}
if ( HandFlow . ControlHandShake & SERIAL_RTS_HANDSHAKE ) {
lpDCB - > fRtsControl = 2 ;
}
if ( HandFlow . ControlHandShake & SERIAL_DSR_SENSITIVITY ) {
lpDCB - > fDsrSensitivity = 1 ;
}
if ( HandFlow . ControlHandShake & SERIAL_ERROR_ABORT ) {
lpDCB - > fAbortOnError = 1 ;
}
if ( HandFlow . FlowReplace & SERIAL_ERROR_CHAR ) {
lpDCB - > fErrorChar = 1 ;
}
if ( HandFlow . FlowReplace & SERIAL_NULL_STRIPPING ) {
lpDCB - > fNull = 1 ;
}
if ( HandFlow . FlowReplace & SERIAL_XOFF_CONTINUE ) {
lpDCB - > fTXContinueOnXoff = 1 ;
}
2007-01-26 07:22:19 +00:00
lpDCB - > XonLim = ( WORD ) HandFlow . XonLimit ;
lpDCB - > XoffLim = ( WORD ) HandFlow . XoffLimit ;
2002-10-03 18:26:53 +00:00
result = DeviceIoControl ( hFile , IOCTL_SERIAL_GET_CHARS ,
NULL , 0 , & SpecialChars , sizeof ( SpecialChars ) , & dwBytesReturned , NULL ) ;
if ( ! NT_SUCCESS ( result ) ) {
DPRINT ( " ERROR: GetCommState() - DeviceIoControl(IOCTL_SERIAL_GET_CHARS) Failed. \n " ) ;
return FALSE ;
}
lpDCB - > EofChar = SpecialChars . EofChar ;
lpDCB - > ErrorChar = SpecialChars . ErrorChar ;
// = SpecialChars.BreakChar;
lpDCB - > EvtChar = SpecialChars . EventChar ;
lpDCB - > XonChar = SpecialChars . XonChar ;
lpDCB - > XoffChar = SpecialChars . XoffChar ;
result = DeviceIoControl ( hFile , IOCTL_SERIAL_GET_LINE_CONTROL ,
NULL , 0 , & LineControl , sizeof ( LineControl ) , & dwBytesReturned , NULL ) ;
if ( ! NT_SUCCESS ( result ) ) {
DPRINT ( " ERROR: GetCommState() - DeviceIoControl(IOCTL_SERIAL_GET_LINE_CONTROL) Failed. \n " ) ;
return FALSE ;
}
lpDCB - > StopBits = LineControl . StopBits ;
lpDCB - > Parity = LineControl . Parity ;
lpDCB - > ByteSize = LineControl . WordLength ;
DPRINT ( " GetCommState() - COMPLETED SUCCESSFULLY \n " ) ;
return TRUE ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
* @ implemented
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
GetCommTimeouts ( HANDLE hFile , LPCOMMTIMEOUTS lpCommTimeouts )
2001-03-31 01:17:30 +00:00
{
2002-10-03 18:26:53 +00:00
DWORD dwBytesReturned ;
if ( lpCommTimeouts = = NULL ) {
return FALSE ;
}
2005-05-09 01:46:57 +00:00
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
return DeviceIoControl ( hFile , IOCTL_SERIAL_GET_TIMEOUTS ,
2005-05-09 01:46:57 +00:00
NULL , 0 ,
lpCommTimeouts , sizeof ( COMMTIMEOUTS ) ,
2002-10-03 18:26:53 +00:00
& dwBytesReturned , NULL ) ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
2008-04-03 10:50:57 +00:00
* @ implemented
2003-07-10 18:50:51 +00:00
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
GetDefaultCommConfigW ( LPCWSTR lpszName , LPCOMMCONFIG lpCC , LPDWORD lpdwSize )
2001-03-31 01:17:30 +00:00
{
2008-04-03 10:50:57 +00:00
FARPROC pGetDefaultCommConfig ;
HMODULE hConfigModule ;
DWORD res = ERROR_INVALID_PARAMETER ;
DPRINT ( " (%s, %p, %p) *lpdwSize: %u \n " , lpszName , lpCC , lpdwSize , lpdwSize ? * lpdwSize : 0 ) ;
hConfigModule = LoadLibraryW ( lpszSerialUI ) ;
if ( hConfigModule ) {
pGetDefaultCommConfig = GetProcAddress ( hConfigModule , " drvGetDefaultCommConfigW " ) ;
if ( pGetDefaultCommConfig ) {
res = pGetDefaultCommConfig ( lpszName , lpCC , lpdwSize ) ;
}
FreeLibrary ( hConfigModule ) ;
}
if ( res ) SetLastError ( res ) ;
return ( res = = ERROR_SUCCESS ) ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
2008-04-03 10:50:57 +00:00
* @ implemented
2003-07-10 18:50:51 +00:00
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
GetDefaultCommConfigA ( LPCSTR lpszName , LPCOMMCONFIG lpCC , LPDWORD lpdwSize )
2001-03-31 01:17:30 +00:00
{
2008-04-03 10:50:57 +00:00
BOOL ret = FALSE ;
UNICODE_STRING lpszNameW ;
DPRINT ( " (%s, %p, %p) *lpdwSize: %u \n " , lpszName , lpCC , lpdwSize , lpdwSize ? * lpdwSize : 0 ) ;
if ( lpszName ) RtlCreateUnicodeStringFromAsciiz ( & lpszNameW , lpszName ) ;
else lpszNameW . Buffer = NULL ;
ret = GetDefaultCommConfigW ( lpszNameW . Buffer , lpCC , lpdwSize ) ;
RtlFreeUnicodeString ( & lpszNameW ) ;
return ret ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
* @ implemented
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
PurgeComm ( HANDLE hFile , DWORD dwFlags )
2001-03-31 01:17:30 +00:00
{
2002-10-03 18:26:53 +00:00
DWORD dwBytesReturned ;
2005-05-09 01:46:57 +00:00
return DeviceIoControl ( hFile , IOCTL_SERIAL_PURGE ,
2002-10-03 18:26:53 +00:00
& dwFlags , sizeof ( DWORD ) , NULL , 0 , & dwBytesReturned , NULL ) ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
* @ implemented
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
SetCommBreak ( HANDLE hFile )
2001-03-31 01:17:30 +00:00
{
2002-10-03 18:26:53 +00:00
DWORD dwBytesReturned ;
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
return DeviceIoControl ( hFile , IOCTL_SERIAL_SET_BREAK_ON , NULL , 0 , NULL , 0 , & dwBytesReturned , NULL ) ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
2005-06-24 18:19:40 +00:00
* @ implemented
2003-07-10 18:50:51 +00:00
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
SetCommConfig ( HANDLE hCommDev , LPCOMMCONFIG lpCC , DWORD dwSize )
2001-03-31 01:17:30 +00:00
{
2005-06-24 18:19:40 +00:00
BOOL ReturnValue = FALSE ;
DPRINT ( " SetCommConfig(%d, %p, %d) \n " , hCommDev , lpCC , dwSize ) ;
if ( NULL = = lpCC )
{
DPRINT ( " SetCommConfig() - invalid parameter \n " ) ;
2005-06-24 18:28:22 +00:00
SetLastError ( ERROR_INVALID_PARAMETER ) ;
2005-06-24 18:19:40 +00:00
ReturnValue = FALSE ;
}
else
{
ReturnValue = SetCommState ( hCommDev , & lpCC - > dcb ) ;
}
return ReturnValue ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
* @ implemented
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
SetCommMask ( HANDLE hFile , DWORD dwEvtMask )
2001-03-31 01:17:30 +00:00
{
2002-10-03 18:26:53 +00:00
DWORD dwBytesReturned ;
2005-05-09 01:46:57 +00:00
return DeviceIoControl ( hFile , IOCTL_SERIAL_SET_WAIT_MASK ,
2002-10-03 18:26:53 +00:00
& dwEvtMask , sizeof ( DWORD ) , NULL , 0 , & dwBytesReturned , NULL ) ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
* @ implemented
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
SetCommState ( HANDLE hFile , LPDCB lpDCB )
2001-03-31 01:17:30 +00:00
{
2004-01-23 17:18:16 +00:00
BOOL result = FALSE ;
2002-10-03 18:26:53 +00:00
DWORD dwBytesReturned ;
SERIAL_BAUD_RATE BaudRate ;
SERIAL_HANDFLOW HandFlow ;
SERIAL_CHARS SpecialChars ;
SERIAL_LINE_CONTROL LineControl ;
DPRINT ( " SetCommState(%d, %p) - ENTERED \n " , hFile , lpDCB ) ;
if ( lpDCB = = NULL ) {
DPRINT ( " SetCommState() - ERROR: NULL DCB pointer passed \n " ) ;
return FALSE ;
}
BaudRate . BaudRate = lpDCB - > BaudRate ;
result = DeviceIoControl ( hFile , IOCTL_SERIAL_SET_BAUD_RATE ,
& BaudRate , sizeof ( BaudRate ) , NULL , 0 , & dwBytesReturned , NULL ) ;
if ( ! NT_SUCCESS ( result ) ) {
DPRINT ( " ERROR: SetCommState() - DeviceIoControl(IOCTL_SERIAL_SET_BAUD_RATE) Failed. \n " ) ;
return FALSE ;
}
/*
# define SERIAL_DTR_MASK ((ULONG)0x03)
# define SERIAL_DTR_CONTROL ((ULONG)0x01)
# define SERIAL_DTR_HANDSHAKE ((ULONG)0x02)
# define SERIAL_CTS_HANDSHAKE ((ULONG)0x08)
# define SERIAL_DSR_HANDSHAKE ((ULONG)0x10)
# define SERIAL_DCD_HANDSHAKE ((ULONG)0x20)
# define SERIAL_OUT_HANDSHAKEMASK ((ULONG)0x38)
# define SERIAL_DSR_SENSITIVITY ((ULONG)0x40)
# define SERIAL_ERROR_ABORT ((ULONG)0x80000000)
# define SERIAL_CONTROL_INVALID ((ULONG)0x7fffff84)
*/
HandFlow . ControlHandShake = 0 ;
if ( lpDCB - > fOutxCtsFlow ) {
HandFlow . ControlHandShake | = SERIAL_CTS_HANDSHAKE ;
}
if ( lpDCB - > fOutxDsrFlow ) {
HandFlow . ControlHandShake | = SERIAL_DSR_HANDSHAKE ;
}
if ( lpDCB - > fDtrControl ) {
HandFlow . ControlHandShake | = SERIAL_DTR_CONTROL ;
}
if ( lpDCB - > fDtrControl ) {
HandFlow . ControlHandShake | = SERIAL_DTR_HANDSHAKE ;
}
if ( lpDCB - > fRtsControl ) {
HandFlow . ControlHandShake | = SERIAL_RTS_CONTROL ;
}
if ( lpDCB - > fRtsControl ) {
HandFlow . ControlHandShake | = SERIAL_RTS_HANDSHAKE ;
}
if ( lpDCB - > fDsrSensitivity ) {
HandFlow . ControlHandShake | = SERIAL_DSR_SENSITIVITY ;
}
if ( lpDCB - > fAbortOnError ) {
HandFlow . ControlHandShake | = SERIAL_ERROR_ABORT ;
}
/*
# define SERIAL_AUTO_TRANSMIT ((ULONG)0x01)
# define SERIAL_AUTO_RECEIVE ((ULONG)0x02)
# define SERIAL_ERROR_CHAR ((ULONG)0x04)
# define SERIAL_NULL_STRIPPING ((ULONG)0x08)
# define SERIAL_BREAK_CHAR ((ULONG)0x10)
# define SERIAL_RTS_MASK ((ULONG)0xc0)
# define SERIAL_RTS_CONTROL ((ULONG)0x40)
# define SERIAL_RTS_HANDSHAKE ((ULONG)0x80)
# define SERIAL_TRANSMIT_TOGGLE ((ULONG)0xc0)
# define SERIAL_XOFF_CONTINUE ((ULONG)0x80000000)
# define SERIAL_FLOW_INVALID ((ULONG)0x7fffff20)
*/
HandFlow . FlowReplace = 0 ;
if ( lpDCB - > fErrorChar ) {
HandFlow . FlowReplace | = SERIAL_ERROR_CHAR ;
}
if ( lpDCB - > fNull ) {
HandFlow . FlowReplace | = SERIAL_NULL_STRIPPING ;
}
if ( lpDCB - > fTXContinueOnXoff ) {
HandFlow . FlowReplace | = SERIAL_XOFF_CONTINUE ;
}
HandFlow . XonLimit = lpDCB - > XonLim ;
HandFlow . XoffLimit = lpDCB - > XoffLim ;
result = DeviceIoControl ( hFile , IOCTL_SERIAL_SET_HANDFLOW ,
& HandFlow , sizeof ( HandFlow ) , NULL , 0 , & dwBytesReturned , NULL ) ;
if ( ! NT_SUCCESS ( result ) ) {
DPRINT ( " ERROR: SetCommState() - DeviceIoControl(IOCTL_SERIAL_SET_HANDFLOW) Failed. \n " ) ;
return FALSE ;
}
SpecialChars . EofChar = lpDCB - > EofChar ;
SpecialChars . ErrorChar = lpDCB - > ErrorChar ;
SpecialChars . BreakChar = 0 ;
SpecialChars . EventChar = lpDCB - > EvtChar ;
SpecialChars . XonChar = lpDCB - > XonChar ;
SpecialChars . XoffChar = lpDCB - > XoffChar ;
result = DeviceIoControl ( hFile , IOCTL_SERIAL_SET_CHARS ,
& SpecialChars , sizeof ( SpecialChars ) , NULL , 0 , & dwBytesReturned , NULL ) ;
if ( ! NT_SUCCESS ( result ) ) {
DPRINT ( " ERROR: SetCommState() - DeviceIoControl(IOCTL_SERIAL_SET_CHARS) Failed. \n " ) ;
return FALSE ;
}
LineControl . StopBits = lpDCB - > StopBits ;
LineControl . Parity = lpDCB - > Parity ;
LineControl . WordLength = lpDCB - > ByteSize ;
result = DeviceIoControl ( hFile , IOCTL_SERIAL_SET_LINE_CONTROL ,
& LineControl , sizeof ( LineControl ) , NULL , 0 , & dwBytesReturned , NULL ) ;
if ( ! NT_SUCCESS ( result ) ) {
DPRINT ( " ERROR: SetCommState() - DeviceIoControl(IOCTL_SERIAL_SET_LINE_CONTROL) Failed. \n " ) ;
return FALSE ;
}
DPRINT ( " SetCommState() - COMPLETED SUCCESSFULLY \n " ) ;
return TRUE ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
* @ implemented
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
SetCommTimeouts ( HANDLE hFile , LPCOMMTIMEOUTS lpCommTimeouts )
2001-03-31 01:17:30 +00:00
{
2002-10-03 18:26:53 +00:00
DWORD dwBytesReturned ;
SERIAL_TIMEOUTS Timeouts ;
if ( lpCommTimeouts = = NULL ) {
return FALSE ;
}
Timeouts . ReadIntervalTimeout = lpCommTimeouts - > ReadIntervalTimeout ;
Timeouts . ReadTotalTimeoutMultiplier = lpCommTimeouts - > ReadTotalTimeoutMultiplier ;
Timeouts . ReadTotalTimeoutConstant = lpCommTimeouts - > ReadTotalTimeoutConstant ;
Timeouts . WriteTotalTimeoutMultiplier = lpCommTimeouts - > WriteTotalTimeoutMultiplier ;
Timeouts . WriteTotalTimeoutConstant = lpCommTimeouts - > WriteTotalTimeoutConstant ;
2005-05-09 01:46:57 +00:00
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
return DeviceIoControl ( hFile , IOCTL_SERIAL_SET_TIMEOUTS ,
2002-10-03 18:26:53 +00:00
& Timeouts , sizeof ( Timeouts ) , NULL , 0 , & dwBytesReturned , NULL ) ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
2008-04-03 10:50:57 +00:00
* @ implemented
2003-07-10 18:50:51 +00:00
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
SetDefaultCommConfigA ( LPCSTR lpszName , LPCOMMCONFIG lpCC , DWORD dwSize )
2001-03-31 01:17:30 +00:00
{
2008-04-03 10:50:57 +00:00
BOOL r ;
LPWSTR lpDeviceW = NULL ;
DWORD len ;
DPRINT ( " (%s, %p, %u) \n " , lpszName , lpCC , dwSize ) ;
if ( lpszName )
{
len = MultiByteToWideChar ( CP_ACP , 0 , lpszName , - 1 , NULL , 0 ) ;
2009-07-04 08:48:18 +00:00
2008-04-03 10:50:57 +00:00
lpDeviceW = HeapAlloc ( GetProcessHeap ( ) , 0 , len * sizeof ( WCHAR ) ) ;
2009-07-04 08:48:18 +00:00
if ( ! lpDeviceW )
{
SetLastError ( ERROR_NOT_ENOUGH_MEMORY ) ;
return FALSE ;
}
2008-04-03 10:50:57 +00:00
MultiByteToWideChar ( CP_ACP , 0 , lpszName , - 1 , lpDeviceW , len ) ;
}
r = SetDefaultCommConfigW ( lpDeviceW , lpCC , dwSize ) ;
HeapFree ( GetProcessHeap ( ) , 0 , lpDeviceW ) ;
return r ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
2008-04-03 10:50:57 +00:00
* @ implemented
2003-07-10 18:50:51 +00:00
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
SetDefaultCommConfigW ( LPCWSTR lpszName , LPCOMMCONFIG lpCC , DWORD dwSize )
2001-03-31 01:17:30 +00:00
{
2008-04-03 10:50:57 +00:00
FARPROC pGetDefaultCommConfig ;
HMODULE hConfigModule ;
DWORD res = ERROR_INVALID_PARAMETER ;
DPRINT ( " (%s, %p, %p) *dwSize: %u \n " , lpszName , lpCC , dwSize , dwSize ? dwSize : 0 ) ;
hConfigModule = LoadLibraryW ( lpszSerialUI ) ;
if ( hConfigModule ) {
pGetDefaultCommConfig = GetProcAddress ( hConfigModule , " drvGetDefaultCommConfigW " ) ;
if ( pGetDefaultCommConfig ) {
res = pGetDefaultCommConfig ( lpszName , lpCC , & dwSize ) ;
}
FreeLibrary ( hConfigModule ) ;
}
if ( res ) SetLastError ( res ) ;
return ( res = = ERROR_SUCCESS ) ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
* @ implemented
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
SetupComm ( HANDLE hFile , DWORD dwInQueue , DWORD dwOutQueue )
2001-03-31 01:17:30 +00:00
{
2002-10-03 18:26:53 +00:00
DWORD dwBytesReturned ;
SERIAL_QUEUE_SIZE QueueSize ;
QueueSize . InSize = dwInQueue ;
QueueSize . OutSize = dwOutQueue ;
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
return DeviceIoControl ( hFile , IOCTL_SERIAL_SET_QUEUE_SIZE ,
2002-10-03 18:26:53 +00:00
& QueueSize , sizeof ( QueueSize ) , NULL , 0 , & dwBytesReturned , NULL ) ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
* @ implemented
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
TransmitCommChar ( HANDLE hFile , char cChar )
2001-03-31 01:17:30 +00:00
{
2002-10-03 18:26:53 +00:00
DWORD dwBytesReturned ;
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
return DeviceIoControl ( hFile , IOCTL_SERIAL_IMMEDIATE_CHAR ,
2002-10-03 18:26:53 +00:00
& cChar , sizeof ( cChar ) , NULL , 0 , & dwBytesReturned , NULL ) ;
2001-03-31 01:17:30 +00:00
}
2003-07-10 18:50:51 +00:00
/*
* @ implemented
*/
2004-01-23 17:18:16 +00:00
BOOL
2008-11-30 11:42:05 +00:00
WINAPI
2002-10-03 18:26:53 +00:00
WaitCommEvent ( HANDLE hFile , LPDWORD lpEvtMask , LPOVERLAPPED lpOverlapped )
2001-03-31 01:17:30 +00:00
{
2002-10-03 18:26:53 +00:00
DWORD dwBytesReturned ;
if ( lpEvtMask = = NULL ) {
return FALSE ;
}
2005-05-09 01:46:57 +00:00
Saveliy Tretiakov <saveliyt@mail.ru>
- Implement ClearCommError
- Correct badly implemented apis: ClearCommBreak, EscapeCommFunction, GetCommMask, GetCommModemStatus, GetCommState, GetCommTimeouts, PurgeComm, SetCommBreak, SetCommMask, SetCommTimeouts, SetCommState, SetupComm, TransmitCommChar, WaitCommEvent
svn path=/trunk/; revision=14346
2005-03-27 12:03:59 +00:00
return DeviceIoControl ( hFile , IOCTL_SERIAL_WAIT_ON_MASK ,
2002-10-03 18:26:53 +00:00
NULL , 0 , lpEvtMask , sizeof ( DWORD ) , & dwBytesReturned , lpOverlapped ) ;
2001-03-31 01:17:30 +00:00
}
/* EOF */