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

📄 uartreadwrite.c

📁 一个在Linux下开发的IP摄像头的驱动程序及控制软件
💻 C
字号:
#include "Utility.h"

/*!
***************************************************************************
 * \brief
 *	read/write through COM port

 * \param tServerInfo 
	[in] server info
 * \param *pszReadWriteBuf 
	[in/out] input when writing the com port, output when reading the com port
 * \param bRead 
	[in] true means read the com port
 * \param iComNumber 
	[in] index of com port
 
 * \return 
 * \retval S_OK		operation success
 * \retval -1		com port number is negative
 * \retval -2		server has no com port or iComNumber is larger than server's com port number
**************************************************************************/
int UartReadWrite(TSERVER_INFO tServerInfo, char *pszReadWriteBuf, BOOL bRead, int iComNumber)
{
	HANDLE hSrvUtl;
	HANDLE hDevice;
	char lpszModelName[64]; 
    int nTimeout = 0;                  //for more operations
	BOOL bFlushUart = FALSE;	   //for more operations
	SCODE scRet;
	TSrvDepResource_ServerInfo srvInfo;
	
	if (iComNumber < 0)
		return -1;

	scRet = ServerUtlInit(&hSrvUtl, &hDevice, lpszModelName, tServerInfo);
	if (scRet != 0)
		return scRet;

	scRet = SrvDepResource_GetParamForServer(lpszModelName, &srvInfo);
	if (scRet != S_OK)
	{
		ServerUtlRelease(&hSrvUtl, &hDevice);
		return scRet;		
	}

	if (srvInfo.dwComNum == 0 || srvInfo.dwComNum < iComNumber)
	{
		ServerUtlRelease(&hSrvUtl, &hDevice);
		return -2;
	}

	if (bRead)
	{
		scRet = ServerUtl_UartRead(hDevice, iComNumber, pszReadWriteBuf, 10, 
								   bFlushUart, nTimeout, FALSE);
		
		if (scRet != S_OK)
		{
			ServerUtlRelease(&hSrvUtl, &hDevice);
			return scRet;
		}
	}else
	{
		scRet = ServerUtl_UartWrite(hDevice, iComNumber, pszReadWriteBuf, FALSE);

		if (scRet != S_OK)
		{
			ServerUtlRelease(&hSrvUtl, &hDevice);
			return scRet;
		}
	}


	ServerUtlRelease(&hSrvUtl, &hDevice);

	return S_OK;
}

⌨️ 快捷键说明

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