The SetCommTimeouts function sets the time-out parameters for all read and write operations on a specified communications device.
BOOL SetCommTimeouts( HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts )
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.
EX1
#include <Origin.h> #include <mscomm.h> BOOL Set_Comm_Timeouts() { file ff; //Open comm port if (!ff.Open("COM1:", file::modeReadWrite )) { ASSERT(FALSE); return FALSE; } UINT hCom = ff.GetHandle(); if ( hCom == file::hFileNull ) { ASSERT(FALSE); return FALSE; } COMMTIMEOUTS tTimeout; tTimeout.ReadIntervalTimeout = MAXWORD; tTimeout.ReadTotalTimeoutMultiplier = 0; tTimeout.ReadTotalTimeoutConstant = 500; // pas de time out = 0 tTimeout.WriteTotalTimeoutMultiplier = 0; tTimeout.WriteTotalTimeoutConstant = 0; // config the timeout if( !SetCommTimeouts((HANDLE)hCom,&tTimeout) ) { ASSERT(FALSE); return FALSE; } //... if( !ff.Close() ) // Close() function will happen automatically by the file class destructor. { ASSERT(FALSE); return FALSE; } }
file::Open, file::GetHandle, GetCommTimeouts
mscomm.h