SetCommTimeouts

 

Description

The SetCommTimeouts function sets the time-out parameters for all read and write operations on a specified communications device.

Syntax

BOOL SetCommTimeouts( HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts )

Parameters

hFile
Handle to the communications device.
lpCommTimeouts
Pointer to a COMMTIMEOUTS structure that contains the new time-out values.

Return

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.

Examples

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;
        }
}

Remark

See Also

file::Open, file::GetHandle, GetCommTimeouts

Header to Include

mscomm.h

Reference