亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? serial.cpp

?? 不用控制器,對讀卡頭進(jìn)行讀寫.可設(shè)置根據(jù)讀卡器類型不同而進(jìn)行長度的設(shè)置
?? CPP
?? 第 1 頁 / 共 3 頁
字號(hào):
//	Serial.cpp - Implementation of the CSerial class
//
//	Copyright (C) 1999-2003 Ramon de Klein (Ramon.de.Klein@ict.nl)
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


//////////////////////////////////////////////////////////////////////
// Include the standard header files

#define STRICT
#include <crtdbg.h>
#include <tchar.h>
#include <windows.h>
#include <stdafx.h> 


//////////////////////////////////////////////////////////////////////
// Include module headerfile

#include "Serial.h"


//////////////////////////////////////////////////////////////////////
// Disable warning C4127: conditional expression is constant, which
// is generated when using the _RPTF and _ASSERTE macros.

#pragma warning(disable: 4127)


//////////////////////////////////////////////////////////////////////
// Enable debug memory manager

#ifdef _DEBUG

#ifdef THIS_FILE
#undef THIS_FILE
#endif

static const char THIS_FILE[] = __FILE__;
#define new DEBUG_NEW

#endif


//////////////////////////////////////////////////////////////////////
// Helper methods

inline void CSerial::CheckRequirements (LPOVERLAPPED lpOverlapped, DWORD dwTimeout) const
{
#ifdef SERIAL_NO_OVERLAPPED

	// Check if an overlapped structure has been specified
	if (lpOverlapped || (dwTimeout != INFINITE))
	{
		// Quit application
		::MessageBox(0,_T("Overlapped I/O and time-outs are not supported, when overlapped I/O is disabled."),_T("Serial library"), MB_ICONERROR | MB_TASKMODAL);
		::DebugBreak();
		::ExitProcess(0xFFFFFFF);
	}

#endif

#ifdef SERIAL_NO_CANCELIO

	// Check if 0 or INFINITE time-out has been specified, because
	// the communication I/O cannot be cancelled.
	if ((dwTimeout != 0) && (dwTimeout != INFINITE))
	{
		// Quit application
		::MessageBox(0,_T("Timeouts are not supported, when SERIAL_NO_CANCELIO is defined"),_T("Serial library"), MB_ICONERROR | MB_TASKMODAL);
		::DebugBreak();
		::ExitProcess(0xFFFFFFF);
	}

#endif	// SERIAL_NO_CANCELIO

	// Avoid warnings
	(void) dwTimeout;
	(void) lpOverlapped;
}

inline BOOL CSerial::CancelCommIo (void)
{
#ifdef SERIAL_NO_CANCELIO
	// CancelIo shouldn't have been called at this point
	::DebugBreak();
	return FALSE;
#else

	// Cancel the I/O request
	return ::CancelIo(m_hFile);

#endif	// SERIAL_NO_CANCELIO
}


//////////////////////////////////////////////////////////////////////
// Code

CSerial::CSerial ()
	: m_lLastError(ERROR_SUCCESS)
	, m_hFile(0)
	, m_eEvent(EEventNone)
	, m_dwEventMask(0)
#ifndef SERIAL_NO_OVERLAPPED
	, m_hevtOverlapped(0)
#endif
{
}

CSerial::~CSerial ()
{
	// If the device is already closed,
	// then we don't need to do anything.
	if (m_hFile)
	{
		// Display a warning
		_RPTF0(_CRT_WARN,"CSerial::~CSerial - Serial port not closed\n");

		// Close implicitly
		Close();
	}
}

CSerial::EPort CSerial::CheckPort (LPCTSTR lpszDevice)
{
	// Try to open the device
	HANDLE hFile = ::CreateFile(lpszDevice, 
						   GENERIC_READ|GENERIC_WRITE, 
						   0, 
						   0, 
						   OPEN_EXISTING, 
						   0,
						   0);

	// Check if we could open the device
	if (hFile == INVALID_HANDLE_VALUE)
	{
		// Display error
		switch (::GetLastError())
		{
		case ERROR_FILE_NOT_FOUND:
			// The specified COM-port does not exist
			return EPortNotAvailable;

		case ERROR_ACCESS_DENIED:
			// The specified COM-port is in use
			return EPortInUse;

		default:
			// Something else is wrong
			return EPortUnknownError;
		}
	}

	// Close handle
	::CloseHandle(hFile);

	// Port is available
	return EPortAvailable;
}

LONG CSerial::Open (LPCTSTR lpszDevice, DWORD dwInQueue, DWORD dwOutQueue, bool fOverlapped)
{
	// Reset error state
	m_lLastError = ERROR_SUCCESS;

	// Check if the port isn't already opened
	if (m_hFile)
	{
		m_lLastError = ERROR_ALREADY_INITIALIZED;
		_RPTF0(_CRT_WARN,"CSerial::Open - Port already opened\n");
		return m_lLastError;
	}

	// Open the device
	m_hFile = ::CreateFile(lpszDevice,
						   GENERIC_READ|GENERIC_WRITE,
						   0,
						   0,
						   OPEN_EXISTING,
						   fOverlapped?FILE_FLAG_OVERLAPPED:0,
						   0);
	if (m_hFile == INVALID_HANDLE_VALUE)
	{
		// Reset file handle
		m_hFile = 0;

		// Display error
		m_lLastError = ::GetLastError();
		_RPTF0(_CRT_WARN, "CSerial::Open - Unable to open port\n");
		return m_lLastError;
	}

#ifndef SERIAL_NO_OVERLAPPED
	// We cannot have an event handle yet
	_ASSERTE(m_hevtOverlapped == 0);

	// Create the event handle for internal overlapped operations (manual reset)
	if (fOverlapped)
	{
		m_hevtOverlapped = ::CreateEvent(0,true,false,0);
		if (m_hevtOverlapped == 0)
		{
			// Obtain the error information
			m_lLastError = ::GetLastError();
			_RPTF0(_CRT_WARN,"CSerial::Open - Unable to create event\n");

			// Close the port
			::CloseHandle(m_hFile);
			m_hFile = 0;

			// Return the error
			return m_lLastError;
		}
	}
#else
	
	// Overlapped flag shouldn't be specified
	_ASSERTE(!fOverlapped);

#endif

	// Setup the COM-port
	if (dwInQueue || dwOutQueue)
	{
		// Make sure the queue-sizes are reasonable sized. Win9X systems crash
		// if the input queue-size is zero. Both queues need to be at least
		// 16 bytes large.
		_ASSERTE(dwInQueue >= 16);
		_ASSERTE(dwOutQueue >= 16);

		if (!::SetupComm(m_hFile,dwInQueue,dwOutQueue))
		{
			// Display a warning
			long lLastError = ::GetLastError();
			_RPTF0(_CRT_WARN,"CSerial::Open - Unable to setup the COM-port\n");

			// Close the port
			Close();

			// Save last error from SetupComm
			m_lLastError = lLastError;
			return m_lLastError;	
		}
	}

	// Setup the default communication mask
	SetMask();

	// Non-blocking reads is default
	SetupReadTimeouts(EReadTimeoutNonblocking);

	// Setup the device for default settings
 	COMMCONFIG commConfig = {0};
	DWORD dwSize = sizeof(commConfig);
	commConfig.dwSize = dwSize;
	if (::GetDefaultCommConfig(lpszDevice,&commConfig,&dwSize))
	{
		// Set the default communication configuration
		if (!::SetCommConfig(m_hFile,&commConfig,dwSize))
		{
			// Display a warning
			_RPTF0(_CRT_WARN,"CSerial::Open - Unable to set default communication configuration.\n");
		}
	}
	else
	{
		// Display a warning
		_RPTF0(_CRT_WARN,"CSerial::Open - Unable to obtain default communication configuration.\n");
	}

	// Return successful
	return m_lLastError;
}

LONG CSerial::Close (void)
{
	// Reset error state
	m_lLastError = ERROR_SUCCESS;

	// If the device is already closed,
	// then we don't need to do anything.
	if (m_hFile == 0)
	{
		// Display a warning
		_RPTF0(_CRT_WARN,"CSerial::Close - Method called when device is not open\n");
		return m_lLastError;
	}

#ifndef SERIAL_NO_OVERLAPPED
	// Free event handle
	if (m_hevtOverlapped)
	{
		::CloseHandle(m_hevtOverlapped);
		m_hevtOverlapped = 0;
	}
#endif

	// Close COM port
	::CloseHandle(m_hFile);
	m_hFile = 0;

	// Return successful
	return m_lLastError;
}

LONG CSerial::Setup (EBaudrate eBaudrate, EDataBits eDataBits, EParity eParity, EStopBits eStopBits)
{
	// Reset error state
	m_lLastError = ERROR_SUCCESS;

	// Check if the device is open
	if (m_hFile == 0)
	{
		// Set the internal error code
		m_lLastError = ERROR_INVALID_HANDLE;

		// Issue an error and quit
		_RPTF0(_CRT_WARN,"CSerial::Setup - Device is not opened\n");
		return m_lLastError;
	}

	// Obtain the DCB structure for the device
	CDCB dcb;
	if (!::GetCommState(m_hFile,&dcb))
	{
		// Obtain the error code
		m_lLastError = ::	GetLastError();

		// Display a warning
		_RPTF0(_CRT_WARN,"CSerial::Setup - Unable to obtain DCB information\n");
		return m_lLastError;
	}

	// Set the new data
	dcb.BaudRate = DWORD(eBaudrate);
	dcb.ByteSize = BYTE(eDataBits);
	dcb.Parity   = BYTE(eParity);
	dcb.StopBits = BYTE(eStopBits);

	// Determine if parity is used
	dcb.fParity  = (eParity != EParNone);

	// Set the new DCB structure
	if (!::SetCommState(m_hFile,&dcb))
	{
		// Obtain the error code
		m_lLastError = ::GetLastError();

		// Display a warning
		_RPTF0(_CRT_WARN,"CSerial::Setup - Unable to set DCB information\n");
		return m_lLastError;
	}

	// Return successful
	return m_lLastError;
}

LONG CSerial::SetEventChar (BYTE bEventChar, bool fAdjustMask)
{
	// Reset error state
	m_lLastError = ERROR_SUCCESS;

	// Check if the device is open
	if (m_hFile == 0)
	{
		// Set the internal error code
		m_lLastError = ERROR_INVALID_HANDLE;

		// Issue an error and quit
		_RPTF0(_CRT_WARN,"CSerial::SetEventChar - Device is not opened\n");
		return m_lLastError;
	}

	// Obtain the DCB structure for the device
	CDCB dcb;
	if (!::GetCommState(m_hFile,&dcb))
	{
		// Obtain the error code
		m_lLastError = ::GetLastError();

		// Display a warning
		_RPTF0(_CRT_WARN,"CSerial::SetEventChar - Unable to obtain DCB information\n");
		return m_lLastError;
	}

	// Set the new event character
	dcb.EvtChar = char(bEventChar);

	// Adjust the event mask, to make sure the event will be received
	if (fAdjustMask)
	{
		// Enable 'receive event character' event.  Note that this
		// will generate an EEventNone if there is an asynchronous
		// WaitCommEvent pending.
		SetMask(GetEventMask() | EEventRcvEv);
	}

	// Set the new DCB structure
	if (!::SetCommState(m_hFile,&dcb))
	{
		// Obtain the error code
		m_lLastError = ::GetLastError();

		// Display a warning
		_RPTF0(_CRT_WARN,"CSerial::SetEventChar - Unable to set DCB information\n");
		return m_lLastError;
	}

	// Return successful
	return m_lLastError;
}

LONG CSerial::SetMask (DWORD dwEventMask)
{
	// Reset error state
	m_lLastError = ERROR_SUCCESS;

	// Check if the device is open
	if (m_hFile == 0)
	{
		// Set the internal error code
		m_lLastError = ERROR_INVALID_HANDLE;

		// Issue an error and quit
		_RPTF0(_CRT_WARN,"CSerial::SetMask - Device is not opened\n");
		return m_lLastError;
	}

	// Set the new mask. Note that this will generate an EEventNone
	// if there is an asynchronous WaitCommEvent pending.
	if (!::SetCommMask(m_hFile,dwEventMask))
	{
		// Obtain the error code
		m_lLastError = ::GetLastError();

		// Display a warning
		_RPTF0(_CRT_WARN,"CSerial::SetMask - Unable to set event mask\n");
		return m_lLastError;
	}

	// Save event mask and return successful
	m_dwEventMask = dwEventMask;
	return m_lLastError;
}

LONG CSerial::WaitEvent (LPOVERLAPPED lpOverlapped, DWORD dwTimeout)
{
	// Check if time-outs are supported
	CheckRequirements(lpOverlapped,dwTimeout);

	// Reset error state
	m_lLastError = ERROR_SUCCESS;

	// Check if the device is open
	if (m_hFile == 0)
	{
		// Set the internal error code
		m_lLastError = ERROR_INVALID_HANDLE;

		// Issue an error and quit
		_RPTF0(_CRT_WARN,"CSerial::WaitEvent - Device is not opened\n");
		return m_lLastError;

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产日韩欧美不卡在线| 欧美日韩另类一区| 久久久影视传媒| 国产老妇另类xxxxx| 国产欧美日韩精品一区| 国产99久久精品| 亚洲视频在线观看一区| 欧美性一二三区| 麻豆精品久久久| 久久久无码精品亚洲日韩按摩| 成人性色生活片免费看爆迷你毛片| 国产精品国模大尺度视频| 91小视频免费看| 午夜日韩在线观看| 精品国产乱码久久久久久影片| 国产成人免费9x9x人网站视频| 国产精品久久久久7777按摩| 91免费版在线| 日本亚洲视频在线| 国产精品久久二区二区| 欧美日韩一区成人| 国产中文字幕一区| 亚洲精品欧美专区| 日韩精品一区二区三区蜜臀| 成人在线一区二区三区| 亚洲成a人片在线观看中文| 精品日韩99亚洲| 色伊人久久综合中文字幕| 免费观看一级特黄欧美大片| 国产精品伦理在线| 91精品国产91久久综合桃花 | 亚洲免费看黄网站| 91精品欧美福利在线观看| 国产suv精品一区二区三区| 亚洲一区二区高清| 久久综合久久鬼色中文字| 色婷婷综合久久久久中文一区二区 | 2023国产精华国产精品| 99精品视频中文字幕| 日本伊人色综合网| 亚洲精品国产无套在线观| 欧美精品一区二区三区久久久| 色婷婷av一区二区三区大白胸| 九色porny丨国产精品| 一区二区三区中文字幕| 久久精品一区二区三区四区| 欧美日韩精品一区二区天天拍小说| 国产 日韩 欧美大片| 日本欧美在线看| 一区二区三区四区不卡在线| 国产色一区二区| 日韩片之四级片| 色一情一乱一乱一91av| 成人美女视频在线观看| 久久精品国产亚洲一区二区三区 | 欧美色图激情小说| 欧美日韩色一区| 国产成人免费在线观看不卡| 美女mm1313爽爽久久久蜜臀| 一区二区三区中文字幕精品精品| 国产精品区一区二区三区| 久久婷婷国产综合精品青草 | 色婷婷精品大在线视频| 国产精品一区二区你懂的| 麻豆精品一区二区三区| 香蕉影视欧美成人| 一区二区三区日本| 一区二区三区在线免费视频| 日韩理论片网站| 成人免费在线视频| 中文字幕中文在线不卡住| 国产精品国模大尺度视频| 欧美激情一区二区三区在线| 欧美韩日一区二区三区四区| 久久久精品2019中文字幕之3| 欧美精品一区二区久久久| 欧美大度的电影原声| 日韩一区二区三区高清免费看看| 欧美老女人第四色| 欧美精品自拍偷拍| 91精品婷婷国产综合久久性色| 欧美日韩国产系列| 91精品国产综合久久久久久久| 欧美日韩的一区二区| 69堂国产成人免费视频| 4438x成人网最大色成网站| 8x8x8国产精品| 日韩午夜av电影| 日韩精品中午字幕| 久久九九久精品国产免费直播| 国产片一区二区三区| 国产精品看片你懂得| 亚洲日本在线视频观看| 一区二区三区蜜桃| 日韩影院在线观看| 韩国成人精品a∨在线观看| 福利一区福利二区| 色综合天天综合色综合av| 日本道在线观看一区二区| 欧美日本免费一区二区三区| 欧美大胆人体bbbb| 国产精品日产欧美久久久久| 亚洲欧美一区二区三区极速播放| 亚洲国产一区二区视频| 美国三级日本三级久久99| 国产精品一线二线三线精华| 91女人视频在线观看| 欧美喷潮久久久xxxxx| www欧美成人18+| √…a在线天堂一区| 天堂在线一区二区| 国产精品白丝av| 欧美性色aⅴ视频一区日韩精品| 欧美一区二区二区| 中文字幕一区二区三区色视频| 亚洲国产综合视频在线观看| 国产乱人伦偷精品视频不卡| 91久久精品一区二区三| 欧美电视剧在线看免费| 国产精品久久久久天堂| 日韩电影在线观看网站| 国产高清不卡一区| 欧美日本在线观看| 国产精品污污网站在线观看| 天天色综合天天| 不卡av在线网| 欧美成va人片在线观看| 伊人一区二区三区| 极品少妇xxxx偷拍精品少妇| 欧美性猛交xxxx黑人交| 国产亚洲欧美在线| 午夜精品123| 99re亚洲国产精品| 久久亚洲二区三区| 午夜伦理一区二区| 91影院在线免费观看| 精品国产自在久精品国产| 亚洲国产另类av| 成人av在线一区二区| 精品日韩一区二区三区免费视频| 一区二区三区日韩欧美| 粉嫩一区二区三区性色av| 日韩一区二区在线观看| 亚洲资源中文字幕| 99久久免费精品高清特色大片| 日韩欧美国产综合在线一区二区三区| 亚洲欧美另类综合偷拍| 国产91色综合久久免费分享| 日韩视频中午一区| 午夜欧美一区二区三区在线播放| 99国产一区二区三精品乱码| 欧美激情一区二区三区不卡| 狠狠狠色丁香婷婷综合激情| 3d成人动漫网站| 图片区小说区区亚洲影院| 91麻豆免费视频| 中文字幕日韩av资源站| 成人高清视频在线观看| 久久精品夜夜夜夜久久| 精品一区二区三区影院在线午夜| 欧美日韩亚洲综合一区| 亚洲黄网站在线观看| eeuss鲁片一区二区三区在线看| 久久视频一区二区| 国产一区二区三区黄视频 | 亚洲一级二级三级在线免费观看| 不卡一区在线观看| 中文字幕电影一区| 国产91清纯白嫩初高中在线观看| www日韩大片| 国产盗摄女厕一区二区三区| 久久精品一区二区| 国产 日韩 欧美大片| 中文字幕永久在线不卡| 99国产欧美另类久久久精品| 亚洲免费观看高清完整| 色婷婷综合激情| 亚洲一区二区在线播放相泽| 精品视频在线免费看| 日韩福利电影在线观看| 日韩欧美一二三四区| 激情六月婷婷综合| 国产精品欧美综合在线| 成人黄色小视频在线观看| 亚洲欧美日韩在线| 欧美三级中文字幕在线观看| 天堂久久一区二区三区| 日韩欧美亚洲国产另类| 国产精品18久久久久久久久| 中文在线一区二区| 色婷婷av一区二区三区软件| 天天操天天色综合| 久久你懂得1024| 91欧美一区二区| 日韩av中文字幕一区二区| 久久香蕉国产线看观看99| av一区二区不卡| 亚洲成人在线免费| 欧美v日韩v国产v| 成人免费看片app下载|