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

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

?? commbase.cs

?? 用C#語言編寫
?? CS
?? 第 1 頁 / 共 4 頁
字號:
			return PortStatus.available;
		}

		/// <summary>
		/// Opens the com port and configures it with the required settings
		/// </summary>
		/// <returns>false if the port could not be opened</returns>
		public bool Open() 
		{
			Win32Com.DCB PortDCB = new Win32Com.DCB();
			Win32Com.COMMTIMEOUTS CommTimeouts = new Win32Com.COMMTIMEOUTS();
			CommBaseSettings cs;
			Win32Com.OVERLAPPED wo = new Win32Com.OVERLAPPED();
			Win32Com.COMMPROP cp;

			if (online) return false;
			cs = CommSettings();

			hPort = Win32Com.CreateFile(cs.port, Win32Com.GENERIC_READ | Win32Com.GENERIC_WRITE, 0, IntPtr.Zero,
				Win32Com.OPEN_EXISTING, Win32Com.FILE_FLAG_OVERLAPPED, IntPtr.Zero);
			if (hPort == (IntPtr)Win32Com.INVALID_HANDLE_VALUE)
			{
				if (Marshal.GetLastWin32Error() == Win32Com.ERROR_ACCESS_DENIED)
				{
					return false;
				}
				else
				{
					//JH 1.3: Try alternative name form if main one fails:
					hPort = Win32Com.CreateFile(AltName(cs.port), Win32Com.GENERIC_READ | Win32Com.GENERIC_WRITE, 0, IntPtr.Zero,
						Win32Com.OPEN_EXISTING, Win32Com.FILE_FLAG_OVERLAPPED, IntPtr.Zero);
					if (hPort == (IntPtr)Win32Com.INVALID_HANDLE_VALUE)
					{
						if (Marshal.GetLastWin32Error() == Win32Com.ERROR_ACCESS_DENIED)
						{
							return false;
						}
						else
						{
							throw new CommPortException("Port Open Failure");
						}
					}
				}
			}

			online = true;

			//JH1.1: Changed from 0 to "magic number" to give instant return on ReadFile:
			CommTimeouts.ReadIntervalTimeout = Win32Com.MAXDWORD;
			CommTimeouts.ReadTotalTimeoutConstant = 0;
			CommTimeouts.ReadTotalTimeoutMultiplier = 0;

			//JH1.2: 0 does not seem to mean infinite on non-NT platforms, so default it to 10
			//seconds per byte which should be enough for anyone.
			if (cs.sendTimeoutMultiplier == 0)
			{
				if (System.Environment.OSVersion.Platform == System.PlatformID.Win32NT)
				{
					CommTimeouts.WriteTotalTimeoutMultiplier = 0;
				}
				else
				{
					CommTimeouts.WriteTotalTimeoutMultiplier = 10000;
				}
			}
			else
			{
				CommTimeouts.WriteTotalTimeoutMultiplier = cs.sendTimeoutMultiplier;
			}
			CommTimeouts.WriteTotalTimeoutConstant = cs.sendTimeoutConstant;
			
			PortDCB.init(((cs.parity == Parity.odd) || (cs.parity == Parity.even)), cs.txFlowCTS, cs.txFlowDSR,
				(int)cs.useDTR, cs.rxGateDSR, !cs.txWhenRxXoff, cs.txFlowX, cs.rxFlowX, (int)cs.useRTS);
			PortDCB.BaudRate = cs.baudRate;
			PortDCB.ByteSize = (byte)cs.dataBits;
			PortDCB.Parity = (byte)cs.parity;
			PortDCB.StopBits = (byte)cs.stopBits;
			PortDCB.XoffChar = (byte)cs.XoffChar;
			PortDCB.XonChar = (byte)cs.XonChar;
			if ((cs.rxQueue != 0) || (cs.txQueue != 0))
				if (!Win32Com.SetupComm(hPort, (uint)cs.rxQueue, (uint)cs.txQueue)) ThrowException("Bad queue settings");

			//JH 1.2: Defaulting mechanism for handshake thresholds - prevents problems of setting specific
			//defaults which may violate the size of the actually granted queue. If the user specifically sets
			//these values, it's their problem!
			if ((cs.rxLowWater == 0) || (cs.rxHighWater == 0)) 
			{
				if (!Win32Com.GetCommProperties(hPort, out cp))	cp.dwCurrentRxQueue = 0;
				if (cp.dwCurrentRxQueue > 0)
				{
					//If we can determine the queue size, default to 1/10th, 8/10ths, 1/10th.
					//Note that HighWater is measured from top of queue.
					PortDCB.XoffLim = PortDCB.XonLim = (short)((int)cp.dwCurrentRxQueue / 10);
				}
				else
				{
					//If we do not know the queue size, set very low defaults for safety.
					PortDCB.XoffLim = PortDCB.XonLim = 8;
				}
			}
			else
			{
				PortDCB.XoffLim = (short)cs.rxHighWater;
				PortDCB.XonLim = (short)cs.rxLowWater;
			}
			
			if (!Win32Com.SetCommState(hPort, ref PortDCB)) ThrowException("Bad com settings");
			if (!Win32Com.SetCommTimeouts(hPort, ref CommTimeouts)) ThrowException("Bad timeout settings");

			stateBRK = 0;
			if (cs.useDTR == HSOutput.none) stateDTR = 0;
			if (cs.useDTR == HSOutput.online) stateDTR = 1;
			if (cs.useRTS == HSOutput.none) stateRTS = 0;
			if (cs.useRTS == HSOutput.online) stateRTS = 1;

			checkSends = cs.checkAllSends;
			wo.Offset = 0;
			wo.OffsetHigh = 0;
			if (checkSends)
				wo.hEvent = writeEvent.Handle;
			else
				wo.hEvent = IntPtr.Zero;

			ptrUWO = Marshal.AllocHGlobal(Marshal.SizeOf(wo));

			Marshal.StructureToPtr(wo, ptrUWO, true);
			writeCount = 0;
			//JH1.3:
			empty[0] = true;
			dataQueued = false;
						
			rxException = null;
			rxExceptionReported = false;
			rxThread = new Thread(new ThreadStart(this.ReceiveThread));
			rxThread.Name = "CommBaseRx";
			rxThread.Priority = ThreadPriority.AboveNormal;
			rxThread.Start();

			//JH1.2: More robust thread start-up wait.
			startEvent.WaitOne(500, false);

			auto = false;
			if (AfterOpen()) 
			{
				auto = cs.autoReopen;
				return true;
			}
			else 
			{
				Close();
				return false;
			}

		}

		/// <summary>
		/// Closes the com port.
		/// </summary>
		public void Close()
		{
			if (online)
			{
				auto = false;
				BeforeClose(false);
				InternalClose();
				rxException = null;
			}
		}
		
		private void InternalClose() 
		{
			Win32Com.CancelIo(hPort);
			if (rxThread != null)
			{
				rxThread.Abort();
				//JH 1.3: Improve robustness of Close in case were followed by Open:
				rxThread.Join(100);
				rxThread = null;
			}
			Win32Com.CloseHandle(hPort);
			if (ptrUWO != IntPtr.Zero) Marshal.FreeHGlobal(ptrUWO);
			stateRTS = 2;
			stateDTR = 2;
			stateBRK = 2;
			online = false;
		}
		
		/// <summary>
		/// For IDisposable
		/// </summary>
		public void Dispose() {Close();}

		/// <summary>
		/// Destructor (just in case)
		/// </summary>
		~CommBase() {Close();}
		
		/// <summary>
		/// True if online.
		/// </summary>
		public bool Online {get {if (!online) return false; else return CheckOnline();}}

		/// <summary>
		/// Block until all bytes in the queue have been transmitted.
		/// </summary>
		public void Flush() {
			CheckOnline();
			CheckResult();
		}

		/// <summary>
		/// Use this to throw exceptions in derived classes. Correctly handles threading issues
		/// and closes the port if necessary.
		/// </summary>
		/// <param name="reason">Description of fault</param>
		protected void ThrowException(string reason)
		{
			if (Thread.CurrentThread == rxThread)
			{
				throw new CommPortException(reason);
			}
			else
			{
				if (online)
				{
					BeforeClose(true);
					InternalClose();
				}
				if (rxException == null)
				{
					throw new CommPortException(reason);
				}
				else
				{
					throw new CommPortException(rxException);
				}
			}
		}

		/// <summary>
		/// Queues bytes for transmission. 
		/// </summary>
		/// <param name="tosend">Array of bytes to be sent</param>
		protected void Send(byte[] tosend) {
			uint sent = 0;
			CheckOnline();
			CheckResult();
			writeCount = tosend.GetLength(0);
			if (Win32Com.WriteFile(hPort, tosend, (uint)writeCount, out sent, ptrUWO))
			{
				writeCount -= (int)sent;
			}
			else
			{
				if (Marshal.GetLastWin32Error() != Win32Com.ERROR_IO_PENDING) ThrowException("Send failed");
				//JH1.3:
				dataQueued = true;
			}
		}

		/// <summary>
		/// Queues a single byte for transmission.
		/// </summary>
		/// <param name="tosend">Byte to be sent</param>
		protected void Send(byte tosend) 
		{
			byte[] b = new byte[1];
			b[0] = tosend;
			Send(b);
		}

		private void CheckResult() 
		{
			uint sent = 0;

			//JH 1.3: Fixed a number of problems working with checkSends == false. Byte counting was unreliable because
			//occasionally GetOverlappedResult would return true with a completion having missed one or more previous
			//completions. The test for ERROR_IO_INCOMPLETE was incorrectly for ERROR_IO_PENDING instead.

			if (writeCount > 0)
			{
				if (Win32Com.GetOverlappedResult(hPort, ptrUWO, out sent, checkSends))
				{
					if (checkSends)
					{
						writeCount -= (int)sent;
						if (writeCount != 0) ThrowException("Send Timeout");
						writeCount = 0;
					}
				}
				else
				{
					if (Marshal.GetLastWin32Error() != Win32Com.ERROR_IO_INCOMPLETE) ThrowException("Write Error");
				}
			}
		}

		/// <summary>
		/// Sends a protocol byte immediately ahead of any queued bytes.
		/// </summary>
		/// <param name="tosend">Byte to send</param>
		protected void SendImmediate(byte tosend) {
			CheckOnline();
			if (!Win32Com.TransmitCommChar(hPort, tosend)) ThrowException("Transmission failure");
		}
	
		/// <summary>
		/// Delay processing.
		/// </summary>
		/// <param name="milliseconds">Milliseconds to delay by</param>
		protected void Sleep(int milliseconds)
		{
			Thread.Sleep(milliseconds);
		}

		/// <summary>
		/// Represents the status of the modem control input signals.
		/// </summary>
		public struct ModemStatus 
		{
			private uint status;
			internal ModemStatus(uint val) {status = val;}
			/// <summary>
			/// Condition of the Clear To Send signal.
			/// </summary>
			public bool cts {get{return ((status & Win32Com.MS_CTS_ON) != 0);}}
			/// <summary>
			/// Condition of the Data Set Ready signal.
			/// </summary>
			public bool dsr {get{return ((status & Win32Com.MS_DSR_ON) != 0);}}
			/// <summary>
			/// Condition of the Receive Line Status Detection signal.
			/// </summary>
			public bool rlsd {get{return ((status & Win32Com.MS_RLSD_ON) != 0);}}
			/// <summary>
			/// Condition of the Ring Detection signal.
			/// </summary>
			public bool ring {get{return ((status & Win32Com.MS_RING_ON) != 0);}}
		}

		/// <summary>
		/// Gets the status of the modem control input signals.
		/// </summary>
		/// <returns>Modem status object</returns>
		protected ModemStatus GetModemStatus() {
			uint f;

			CheckOnline();
			if (!Win32Com.GetCommModemStatus(hPort, out f)) ThrowException("Unexpected failure");
			return new ModemStatus(f);
		}

		/// <summary>
		/// Represents the current condition of the port queues.
		/// </summary>
		public struct QueueStatus 
		{
			private uint status;
			private uint inQueue;
			private uint outQueue;
			private uint inQueueSize;
			private uint outQueueSize;

			internal QueueStatus(uint stat, uint inQ, uint outQ, uint inQs, uint outQs)
				{status = stat; inQueue = inQ; outQueue = outQ; inQueueSize = inQs; outQueueSize = outQs;}
			/// <summary>
			/// Output is blocked by CTS handshaking.
			/// </summary>
			public bool ctsHold {get{return ((status & Win32Com.COMSTAT.fCtsHold) != 0);}}
			/// <summary>
			/// Output is blocked by DRS handshaking.
			/// </summary>
			public bool dsrHold {get{return ((status & Win32Com.COMSTAT.fDsrHold) != 0);}}
			/// <summary>
			/// Output is blocked by RLSD handshaking.
			/// </summary>
			public bool rlsdHold {get{return ((status & Win32Com.COMSTAT.fRlsdHold) != 0);}}
			/// <summary>
			/// Output is blocked because software handshaking is enabled and XOFF was received.
			/// </summary>
			public bool xoffHold {get{return ((status & Win32Com.COMSTAT.fXoffHold) != 0);}}
			/// <summary>
			/// Output was blocked because XOFF was sent and this station is not yet ready to receive.
			/// </summary>
			public bool xoffSent {get{return ((status & Win32Com.COMSTAT.fXoffSent) != 0);}}
			
			/// <summary>
			/// There is a character waiting for transmission in the immediate buffer.
			/// </summary>
			public bool immediateWaiting {get{return ((status & Win32Com.COMSTAT.fTxim) != 0);}}

			/// <summary>
			/// Number of bytes waiting in the input queue.
			/// </summary>
			public long InQueue {get{return (long)inQueue;}}
			/// <summary>
			/// Number of bytes waiting for transmission.
			/// </summary>
			public long OutQueue {get{return (long)outQueue;}}
			/// <summary>
			/// Total size of input queue (0 means information unavailable)
			/// </summary>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产一区二区免费在线| 欧美浪妇xxxx高跟鞋交| 91久久国产最好的精华液| 91精品国产综合久久精品麻豆| 中文字幕精品三区| 麻豆精品一二三| 91国偷自产一区二区开放时间| 欧美zozo另类异族| 午夜电影久久久| 99国产精品久久久久| 久久久久久久国产精品影院| 亚洲成人福利片| 92国产精品观看| 国产女人aaa级久久久级 | 国产精品一区免费视频| 欧美在线视频全部完| 国产精品国产三级国产普通话蜜臀| 奇米一区二区三区| 欧美日韩成人综合| 亚洲视频小说图片| 97久久精品人人爽人人爽蜜臀| 国产亚洲精品bt天堂精选| 美女网站在线免费欧美精品| 欧美性色欧美a在线播放| 1024成人网色www| 国产精品一区二区无线| 精品国产凹凸成av人导航| 岛国精品在线播放| 久久综合成人精品亚洲另类欧美| 日本午夜一本久久久综合| 欧美老肥妇做.爰bbww| 亚洲第一电影网| 欧美日韩精品系列| 五月天亚洲精品| 337p亚洲精品色噜噜噜| 日韩二区三区四区| 日韩欧美在线网站| 麻豆成人久久精品二区三区小说| 欧美一区二区大片| 中文字幕一区二区三区视频| 日韩精品国产欧美| 欧美一级日韩免费不卡| 日韩av在线播放中文字幕| 欧美一级高清片| 国模娜娜一区二区三区| 国产精品私人影院| 色综合亚洲欧洲| 亚洲成av人片一区二区三区| 欧美日本高清视频在线观看| 奇米精品一区二区三区四区| 久久综合狠狠综合久久激情| 亚洲一区免费观看| 欧美专区日韩专区| 中文字幕免费观看一区| 中日韩免费视频中文字幕| 日本vs亚洲vs韩国一区三区二区| 色琪琪一区二区三区亚洲区| 久久新电视剧免费观看| 一级女性全黄久久生活片免费| 久久99精品久久久久久久久久久久| 国产精品无人区| 午夜精品一区二区三区免费视频| 欧美精品丝袜中出| 激情伊人五月天久久综合| 欧美激情一区二区三区不卡| 色综合久久综合网欧美综合网 | 一区二区三区丝袜| 在线成人小视频| 国产露脸91国语对白| 日韩伦理av电影| 欧美成人aa大片| 91视频你懂的| 久久99国产精品久久99果冻传媒| 久久久久99精品一区| 欧美性色黄大片| 精品综合免费视频观看| 中文字幕一区二区三区色视频| 宅男在线国产精品| 国产a级毛片一区| 三级在线观看一区二区 | 欧美精品在线观看一区二区| 国产精品一区久久久久| 亚洲成人精品影院| 国产精品网站在线观看| 日韩欧美亚洲国产另类| 欧美色视频在线| 成人av手机在线观看| 久热成人在线视频| 亚洲成人激情社区| 亚洲人成精品久久久久| 久久久久国产精品厨房| 91麻豆精品91久久久久久清纯| 成人免费毛片a| 精彩视频一区二区三区| 久久午夜色播影院免费高清| 偷拍亚洲欧洲综合| 日韩欧美视频在线| 精品播放一区二区| 欧美性生活影院| 91玉足脚交白嫩脚丫在线播放| 九九视频精品免费| 日本欧美一区二区| 亚洲va欧美va人人爽| 夜夜揉揉日日人人青青一国产精品 | 久久精品免费在线观看| 日韩一区二区麻豆国产| 欧美日韩国产综合一区二区 | 国产精品久久久久一区二区三区| 日韩久久久久久| 欧美一区二视频| 欧美一区二区播放| 337p亚洲精品色噜噜| 欧美日本在线看| 日韩一区二区在线免费观看| 欧美军同video69gay| 欧美日韩免费观看一区三区| 色www精品视频在线观看| jiyouzz国产精品久久| 99在线精品免费| 97精品国产露脸对白| 91黄色激情网站| 欧美在线视频你懂得| 欧美日本在线一区| 日韩欧美电影一区| 久久综合九色综合97_久久久| 亚洲精品一区在线观看| 精品国产91亚洲一区二区三区婷婷 | 国产一区二区三区国产| 国产在线国偷精品产拍免费yy| 毛片av一区二区| 国产精品77777| av午夜一区麻豆| 91电影在线观看| 欧美精品在线观看播放| 日韩一区二区三区电影在线观看| 欧美精选一区二区| 日韩亚洲欧美成人一区| wwwwxxxxx欧美| 国产精品欧美综合在线| 亚洲免费观看高清完整| 亚洲成av人片观看| 欧美aa在线视频| 国产大陆亚洲精品国产| 一本久久a久久免费精品不卡| 欧美亚洲动漫制服丝袜| 欧美v亚洲v综合ⅴ国产v| 国产精品久久三| 亚洲精品一二三区| 轻轻草成人在线| 国产91清纯白嫩初高中在线观看| av午夜一区麻豆| 欧美一级免费观看| 国产精品情趣视频| 亚洲不卡在线观看| 国产不卡高清在线观看视频| 91在线一区二区三区| 日韩一区二区在线播放| 亚洲国产精品激情在线观看| 一个色妞综合视频在线观看| 久久精品国产99国产| 波多野结衣在线一区| 国产精品丝袜91| 亚洲香蕉伊在人在线观| 国产福利一区二区三区| 91精品国产综合久久婷婷香蕉| 国产无一区二区| 美女视频黄a大片欧美| 色综合久久久久网| 欧美国产成人精品| 久久99蜜桃精品| 在线成人小视频| 亚洲精品成人悠悠色影视| 国产九色精品成人porny| 6080午夜不卡| 一区二区三区成人在线视频| 国产成人av电影在线播放| 欧美一二三四区在线| 亚洲国产人成综合网站| 成人v精品蜜桃久久一区| 日韩欧美激情四射| 丝袜美腿亚洲色图| 一本一道久久a久久精品综合蜜臀| 久久久久9999亚洲精品| 日本成人超碰在线观看| 91美女片黄在线| 国产日韩欧美一区二区三区综合| 蜜臀精品一区二区三区在线观看 | 中文字幕一区二区三区av| 国产中文字幕一区| 欧美一区二区三区在线看| 天天操天天干天天综合网| 欧美日韩在线三区| 亚洲国产精品久久不卡毛片| 99天天综合性| 国产精品久久久久影视| 成人黄动漫网站免费app| 中文字幕不卡在线观看| 成人免费av网站| 一区在线观看免费| 91蝌蚪国产九色|