⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comm.c

📁 wince host 和 target PCI驱动程序
💻 C
字号:
/*
COPYRIGHT (c) 1996 by Philips Semiconductors

THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED AND COPIED IN 
ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH A LICENSE AND WITH THE 
INCLUSION OF THE THIS COPY RIGHT NOTICE. THIS SOFTWARE OR ANY OTHER COPIES 
OF THIS SOFTWARE MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER
PERSON. THE OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED. 

THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT ANY PRIOR NOTICE
AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY Philips Semiconductor. 

PHILIPS ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE
ON PLATFORMS OTHER THAN THE ONE ON WHICH THIS SOFTWARE IS FURNISHED.
*/

/*
	Copyright (c) 1996 Philips Semiconductors - TriMedia. All rights reserved.

FILE	comm.c

HISTORY
	#define TR Tilakraj Roy
	950201	TR Created

*/

#include "windows.h"
#include "stdcom.h"
#include "iodev.h"
#include "comm.h"


COMM_VTBL CommVtbl = 
{
	commCreate,
	commDestroy,
	commOpen,
	commClose,
	commReadChar,
	commWriteChar,
	commWriteStr,
	commSetCommState,
	commGetHandles
};



BOOL	commCreate ( INTERFACE_ID RefIID, PVOID *pObject )
{
	PCOMM_OBJECT	this;
	PIODEV_VTBL		pIoDevVtbl;

	if ( *pObject == NULL )
	{
		if ( ( this = malloc ( sizeof ( COMM_OBJECT ) ) ) == NULL )
		{	
			*pObject = NULL;
			return FALSE;
		}
		else
		{
			this->pvRef = this;
			if ( QueryInterface ( RefIID, &this->pVtbl ) == FALSE )
			{
				free (this);	
				return FALSE;
			}
			*pObject = this;
			goto commCreate_baseinit;
		}
	}
	else
	{
		this = (PCOMM_OBJECT)*pObject;
		this->pvRef = this;
		if ( QueryInterface ( RefIID, &this->pVtbl ) == FALSE )
		{
			free (this);	
			return FALSE;
		}

commCreate_baseinit :
		// create all the base class instances.
		if ( QueryInterface ( IID_IODEV, &pIoDevVtbl ) == FALSE )
		{
			return FALSE;
		}
		else
		{
			this->pIoDev = &this->IoDev;
			if ( pIoDevVtbl->Create ( IID_IODEV, &this->pIoDev ) == FALSE )
			{
				return FALSE;
			}
			this->pIoDevVtbl = pIoDevVtbl;
		}
	}
}

BOOL	commDestroy ( PVOID pObject )
{
	PCOMM_OBJECT	this = (PCOMM_OBJECT)pObject;
	if ( this->pvRef != this )
		return FALSE;
	free ( this );
}

BOOL	commWriteStr (PVOID pObject, PSTR pszString)
{
	PCOMM_OBJECT this = (PCOMM_OBJECT)pObject;
	return  this->pVtbl->WriteChar ( this, pszString, strlen (pszString) );
}


BOOL	commOpen (PVOID pObject)
{
	PCOMM_OBJECT this = (PCOMM_OBJECT)pObject;

	this->pIoDev->szName[0] = 0;
	wsprintf(this->pIoDev->szName,"COM%d", this->dwCommPort);

	if ( this->pIoDev->pVtbl->Open (this->pIoDev) == FALSE )
		return FALSE;

	// com port specific stuff
	this->dwInQSize 	= 1024 * 4;
	this->dwOutQSize 	= 1024 * 4;
	this->dwBaudRate 	= CBR_9600;
	this->bParity 		= NOPARITY;
	this->bStopBits 	= ONESTOPBIT;
	this->bByteSize 	= 8;

	SetupComm (
		this->pIoDev->hFile,
		this->dwInQSize, this->dwOutQSize );

	if ( GetCommState (  
		this->pIoDev->hFile,
		&this->DeviceControlBlock) == FALSE )
	{
		return FALSE;
	}

	this->DeviceControlBlock.BaudRate	= this->dwBaudRate;
	this->DeviceControlBlock.Parity		= this->bParity;
	this->DeviceControlBlock.StopBits	= this->bStopBits;
	this->DeviceControlBlock.ByteSize	= this->bByteSize;
	this->DeviceControlBlock.fTXContinueOnXoff = FALSE;
	this->DeviceControlBlock.fBinary	= TRUE;
	this->DeviceControlBlock.fParity	= FALSE;
	this->DeviceControlBlock.fOutX		= TRUE;
	this->DeviceControlBlock.fInX		= TRUE;
//	this->DeviceControlBlock.fOutxCtsFlow	= TRUE;
//	this->DeviceControlBlock.fRtsControl	= RTS_CONTROL_ENABLE;

	SetCommState ( this->pIoDev->hFile, &this->DeviceControlBlock);

	this->CommTimeOuts.ReadIntervalTimeout = 0;//0xFFFFFFFF ;
	this->CommTimeOuts.ReadTotalTimeoutMultiplier = 0 ;
	this->CommTimeOuts.ReadTotalTimeoutConstant = 0;//1000 ;
	this->CommTimeOuts.WriteTotalTimeoutMultiplier = 0;//1 ;
	this->CommTimeOuts.WriteTotalTimeoutConstant = 0;//1000 ;

	SetCommTimeouts ( this->pIoDev->hFile, &this->CommTimeOuts ) ;

	EscapeCommFunction ( this->pIoDev->hFile, SETDTR ) ;
	return TRUE;
}

VOID	commClose (PVOID pObject)
{
	PCOMM_OBJECT this = (PCOMM_OBJECT)pObject;

	this->pIoDev->pVtbl->Close(this->pIoDev);
}

BOOL	commSetCommState (PVOID pObject)
{
	PCOMM_OBJECT this = (PCOMM_OBJECT)pObject;

	this->DeviceControlBlock.BaudRate = this->dwBaudRate;
	this->DeviceControlBlock.Parity   = this->bParity;
	this->DeviceControlBlock.StopBits = this->bStopBits;
	this->DeviceControlBlock.ByteSize = this->bByteSize;

	if ( SetCommState ( this->pIoDev->hFile,
		&this->DeviceControlBlock) == FALSE  )
	{
		return FALSE;
	}
	else
	{
		return TRUE;
	}
}


BOOL	commReadChar(PVOID pObject, PVOID pBuffer, DWORD dwLength)
{
	PCOMM_OBJECT this = (PCOMM_OBJECT)pObject;
	return this->pIoDev->pVtbl->ReadChar ( this->pIoDev, pBuffer, dwLength );

}

BOOL	commWriteChar(PVOID pObject, PVOID pBuffer, DWORD dwLength)
{
	PCOMM_OBJECT this = (PCOMM_OBJECT)pObject;
	return this->pIoDev->pVtbl->WriteChar ( this->pIoDev, pBuffer, dwLength );
}

VOID	commGetHandles (PVOID pObject,
	HANDLE *phIn, HANDLE *phOut, HANDLE *phErr)
{
	PCOMM_OBJECT this = (PCOMM_OBJECT)pObject;

	*phIn = this->pIoDev->hFile;
	*phOut = this->pIoDev->hFile;
	*phErr = this->pIoDev->hFile;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -