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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? commbase.cs

?? 用C#語言編寫
?? CS
?? 第 1 頁 / 共 4 頁
字號:
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.IO;
using System.Xml.Serialization;

//JH 1.1: Version 1.1 changes labelled thus.
//JH 1.2: Version 1.2 changes labelled thus.
//JH 1.3: Version 1.3 changes labelled thus.

namespace JH.CommBase
{

	/// <summary>
	/// Lowest level Com driver handling all Win32 API calls and processing send and receive in terms of
	/// individual bytes. Used as a base class for higher level drivers.
	/// </summary>
	public abstract class CommBase : IDisposable
	{
		private IntPtr hPort;
		private IntPtr ptrUWO = IntPtr.Zero;
		private Thread rxThread = null;
		private bool online = false;
		private bool auto = false;
		private bool checkSends = true;
		private Exception rxException = null;
		private bool rxExceptionReported = false;
		private int writeCount = 0;
		private ManualResetEvent writeEvent = new ManualResetEvent(false);
		//JH 1.2: Added below to improve robustness of thread start-up.
		private ManualResetEvent startEvent = new ManualResetEvent(false);
		private int stateRTS = 2;
		private int stateDTR = 2;
		private int stateBRK = 2;
		//JH 1.3: Added to support the new congestion detection scheme (following two lines):
		private bool[] empty = new bool[1];
		private bool dataQueued = false;


		/// <summary>
		/// Parity settings
		/// </summary>
		public enum Parity 
		{
			/// <summary>
			/// Characters do not have a parity bit.
			/// </summary>
			none = 0,
			/// <summary>
			/// If there are an odd number of 1s in the data bits, the parity bit is 1.
			/// </summary>
			odd = 1,
			/// <summary>
			/// If there are an even number of 1s in the data bits, the parity bit is 1.
			/// </summary>
			even = 2,
			/// <summary>
			/// The parity bit is always 1.
			/// </summary>
			mark = 3,
			/// <summary>
			/// The parity bit is always 0.
			/// </summary>
			space = 4
		};

		/// <summary>
		/// Stop bit settings
		/// </summary>
		public enum StopBits
		{
			/// <summary>
			/// Line is asserted for 1 bit duration at end of each character
			/// </summary>
			one = 0,
			/// <summary>
			/// Line is asserted for 1.5 bit duration at end of each character
			/// </summary>
			onePointFive = 1,
			/// <summary>
			/// Line is asserted for 2 bit duration at end of each character
			/// </summary>
			two = 2
		};

		/// <summary>
		/// Uses for RTS or DTR pins
		/// </summary>
		public enum HSOutput
		{
			/// <summary>
			/// Pin is asserted when this station is able to receive data.
			/// </summary>
			handshake = 2,
			/// <summary>
			/// Pin is asserted when this station is transmitting data (RTS on NT, 2000 or XP only).
			/// </summary>
			gate = 3,
			/// <summary>
			/// Pin is asserted when this station is online (port is open).
			/// </summary>
			online = 1,
			/// <summary>
			/// Pin is never asserted.
			/// </summary>
			none = 0
		};

		/// <summary>
		/// Standard handshake methods
		/// </summary>
		public enum Handshake
		{
			/// <summary>
			/// No handshaking
			/// </summary>
			none,
			/// <summary>
			/// Software handshaking using Xon / Xoff
			/// </summary>
			XonXoff,
			/// <summary>
			/// Hardware handshaking using CTS / RTS
			/// </summary>
			CtsRts,
			/// <summary>
			/// Hardware handshaking using DSR / DTR
			/// </summary>
			DsrDtr
		}
		
		/// <summary>
		/// Set the public fields to supply settings to CommBase.
		/// </summary>
		public class CommBaseSettings 
		{
			/// <summary>
			/// Port Name (default: "COM1:")
			/// </summary>
			public string port = "COM1:";
			/// <summary>
			/// Baud Rate (default: 2400) unsupported rates will throw "Bad settings"
			/// </summary>
			public int baudRate = 2400;
			/// <summary>
			/// The parity checking scheme (default: none)
			/// </summary>
			public Parity parity = Parity.none;
			/// <summary>
			/// Number of databits 1..8 (default: 8) unsupported values will throw "Bad settings"
			/// </summary>
			public int dataBits = 8;
			/// <summary>
			/// Number of stop bits (default: one)
			/// </summary>
			public StopBits stopBits = StopBits.one;
			/// <summary>
			/// If true, transmission is halted unless CTS is asserted by the remote station (default: false)
			/// </summary>
			public bool txFlowCTS = false;
			/// <summary>
			/// If true, transmission is halted unless DSR is asserted by the remote station (default: false)
			/// </summary>
			public bool txFlowDSR = false;
			/// <summary>
			/// If true, transmission is halted when Xoff is received and restarted when Xon is received (default: false)
			/// </summary>
			public bool txFlowX = false;
			/// <summary>
			/// If false, transmission is suspended when this station has sent Xoff to the remote station (default: true)
			/// Set false if the remote station treats any character as an Xon.
			/// </summary>
			public bool txWhenRxXoff = true;
			/// <summary>
			/// If true, received characters are ignored unless DSR is asserted by the remote station (default: false)
			/// </summary>
			public bool rxGateDSR = false;
			/// <summary>
			/// If true, Xon and Xoff characters are sent to control the data flow from the remote station (default: false)
			/// </summary>
			public bool rxFlowX = false;
			/// <summary>
			/// Specifies the use to which the RTS output is put (default: none)
			/// </summary>
			public HSOutput useRTS = HSOutput.none;
			/// <summary>
			/// Specidies the use to which the DTR output is put (default: none)
			/// </summary>
			public HSOutput useDTR = HSOutput.none;
			/// <summary>
			/// The character used to signal Xon for X flow control (default: DC1)
			/// </summary>
			public ASCII XonChar = ASCII.DC1;
			/// <summary>
			/// The character used to signal Xoff for X flow control (default: DC3)
			/// </summary>
			public ASCII XoffChar = ASCII.DC3;
			//JH 1.2: Next two defaults changed to 0 to use new defaulting mechanism dependant on queue size.
			/// <summary>
			/// The number of free bytes in the reception queue at which flow is disabled
			/// (Default: 0 = Set to 1/10th of actual rxQueue size)
			/// </summary>
			public int rxHighWater = 0;
			/// <summary>
			/// The number of bytes in the reception queue at which flow is re-enabled
			/// (Default: 0 = Set to 1/10th of actual rxQueue size)
			/// </summary>
			public int rxLowWater = 0;
			/// <summary>
			/// Multiplier. Max time for Send in ms = (Multiplier * Characters) + Constant
			/// (default: 0 = No timeout)
			/// </summary>
			public uint sendTimeoutMultiplier = 0;
			/// <summary>
			/// Constant.  Max time for Send in ms = (Multiplier * Characters) + Constant (default: 0)
			/// </summary>
			public uint sendTimeoutConstant = 0;
			/// <summary>
			/// Requested size for receive queue (default: 0 = use operating system default)
			/// </summary>
			public int rxQueue = 0;
			/// <summary>
			/// Requested size for transmit queue (default: 0 = use operating system default)
			/// </summary>
			public int txQueue = 0;
			/// <summary>
			/// If true, the port will automatically re-open on next send if it was previously closed due
			/// to an error (default: false)
			/// </summary>
			public bool autoReopen = false;

			/// <summary>
			/// If true, subsequent Send commands wait for completion of earlier ones enabling the results
			/// to be checked. If false, errors, including timeouts, may not be detected, but performance
			/// may be better.
			/// </summary>
			public bool checkAllSends = true;

			/// <summary>
			/// Pre-configures settings for most modern devices: 8 databits, 1 stop bit, no parity and
			/// one of the common handshake protocols. Change individual settings later if necessary.
			/// </summary>
			/// <param name="Port">The port to use (i.e. "COM1:")</param>
			/// <param name="Baud">The baud rate</param>
			/// <param name="Hs">The handshake protocol</param>
			public void SetStandard(string Port, int Baud, Handshake Hs)
			{
				dataBits = 8; stopBits = StopBits.one; parity = Parity.none;
				port = Port; baudRate = Baud;
				switch (Hs)
				{
					case Handshake.none:
						txFlowCTS = false; txFlowDSR = false; txFlowX = false;
						rxFlowX = false; useRTS = HSOutput.online; useDTR = HSOutput.online;
						txWhenRxXoff = true; rxGateDSR = false;
						break;
					case Handshake.XonXoff:
						txFlowCTS = false; txFlowDSR = false; txFlowX = true;
						rxFlowX = true; useRTS = HSOutput.online; useDTR = HSOutput.online;
						txWhenRxXoff = true; rxGateDSR = false;
						XonChar = ASCII.DC1; XoffChar = ASCII.DC3;
						break;
					case Handshake.CtsRts:
						txFlowCTS = true; txFlowDSR = false; txFlowX = false;
						rxFlowX = false; useRTS = HSOutput.handshake; useDTR = HSOutput.online;
						txWhenRxXoff = true; rxGateDSR = false;
						break;
					case Handshake.DsrDtr:
						txFlowCTS = false; txFlowDSR = true; txFlowX = false;
						rxFlowX = false; useRTS = HSOutput.online; useDTR = HSOutput.handshake;
						txWhenRxXoff = true; rxGateDSR = false;
						break;
				}
			}

			/// <summary>
			/// Save the object in XML format to a stream
			/// </summary>
			/// <param name="s">Stream to save the object to</param>
			public void SaveAsXML(Stream s)
			{
				XmlSerializer sr = new XmlSerializer(this.GetType());
				sr.Serialize(s, this);
			}

			/// <summary>
			/// Create a new CommBaseSettings object initialised from XML data
			/// </summary>
			/// <param name="s">Stream to load the XML from</param>
			/// <returns>CommBaseSettings object</returns>
			public static CommBaseSettings LoadFromXML(Stream s)
			{
				return LoadFromXML(s, typeof(CommBaseSettings));
			}

			/// <summary>
			/// Create a new object loading members from the stream in XML format.
			/// Derived class should call this from a static method i.e.:
			/// return (ComDerivedSettings)LoadFromXML(s, typeof(ComDerivedSettings));
			/// </summary>
			/// <param name="s">Stream to load the object from</param>
			/// <param name="t">Type of the derived object</param>
			/// <returns></returns>
			protected static CommBaseSettings LoadFromXML(Stream s, Type t)
			{
				XmlSerializer sr = new XmlSerializer(t);
				try
				{
					return (CommBaseSettings)sr.Deserialize(s);
				}
				catch
				{
					return null;
				}
			}
		}

		//JH 1.3: Corrected STH -> STX (Thanks - Johan Thelin!)
		/// <summary>
		/// Byte type with enumeration constants for ASCII control codes.
		/// </summary>
		public enum ASCII : byte
		{
			NULL = 0x00,SOH = 0x01,STX = 0x02,ETX = 0x03,EOT = 0x04,ENQ = 0x05,ACK = 0x06,BELL = 0x07,
			BS = 0x08,HT = 0x09,LF = 0x0A,VT = 0x0B,FF = 0x0C,CR = 0x0D,SO = 0x0E,SI = 0x0F,DC1 = 0x11,
			DC2 = 0x12,DC3 = 0x13,DC4 = 0x14,NAK = 0x15,SYN = 0x16,ETB = 0x17,CAN = 0x18,EM = 0x19,
			SUB = 0x1A,ESC = 0x1B,FS = 0x1C,GS = 0x1D,RS = 0x1E,US = 0x1F,SP = 0x20,DEL = 0x7F
		}


		//JH 1.3: Added AltName function, PortStatus enum and IsPortAvailable function.

		/// <summary>
		/// Returns the alternative name of a com port i.e. \\.\COM1 for COM1:
		/// Some systems require this form for double or more digit com port numbers.
		/// </summary>
		/// <param name="s">Name in form COM1 or COM1:</param>
		/// <returns>Name in form \\.\COM1</returns>
		private string AltName(string s)
		{
			string r = s.Trim();
			if (s.EndsWith(":")) s = s.Substring(0, s.Length - 1);
			if (s.StartsWith(@"\")) return s;
			return @"\\.\" + s;
		}

		/// <summary>
		/// Availability status of a port
		/// </summary>
		public enum PortStatus
		{
			/// <summary>
			/// Port exists but is unavailable (may be open to another program)
			/// </summary>
			unavailable = 0,
			/// <summary>
			/// Available for use
			/// </summary>
			available = 1,
			/// <summary>
			/// Port does not exist
			/// </summary>
			absent = -1
		}

		/// <summary>
		/// Tests the availability of a named comm port.
		/// </summary>
		/// <param name="s">Name of port</param>
		/// <returns>Availability of port</returns>
		public PortStatus IsPortAvailable(string s)
		{
			IntPtr h;

			h = Win32Com.CreateFile(s, Win32Com.GENERIC_READ | Win32Com.GENERIC_WRITE, 0, IntPtr.Zero,
				Win32Com.OPEN_EXISTING, Win32Com.FILE_FLAG_OVERLAPPED, IntPtr.Zero);
			if (h == (IntPtr)Win32Com.INVALID_HANDLE_VALUE)
			{
				if (Marshal.GetLastWin32Error() == Win32Com.ERROR_ACCESS_DENIED)
				{
					return PortStatus.unavailable;
				}
				else
				{
					//JH 1.3: Automatically try AltName if supplied name fails:
					h = Win32Com.CreateFile(AltName(s), Win32Com.GENERIC_READ | Win32Com.GENERIC_WRITE, 0, IntPtr.Zero,
						Win32Com.OPEN_EXISTING, Win32Com.FILE_FLAG_OVERLAPPED, IntPtr.Zero);
					if (h == (IntPtr)Win32Com.INVALID_HANDLE_VALUE)
					{
						if (Marshal.GetLastWin32Error() == Win32Com.ERROR_ACCESS_DENIED)
						{
							return PortStatus.unavailable;
						}
						else
						{
							return PortStatus.absent;
						}
					}
				}
			}
			Win32Com.CloseHandle(h);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久爱另类一区二区小说| 欧美日韩国产系列| 在线成人免费视频| 国产精品人妖ts系列视频| 亚洲午夜影视影院在线观看| 日本韩国欧美在线| 日韩免费看的电影| 婷婷综合久久一区二区三区| 大白屁股一区二区视频| 精品国产伦理网| 亚洲成a人片综合在线| av日韩在线网站| 久久久精品国产99久久精品芒果| 日韩电影一二三区| 欧美日韩国产另类一区| 又紧又大又爽精品一区二区| 国产电影一区二区三区| 337p粉嫩大胆色噜噜噜噜亚洲| 亚洲va国产va欧美va观看| 91麻豆精品一区二区三区| 国产精品伦一区| 成人精品一区二区三区四区| 久久久噜噜噜久久人人看| 天天av天天翘天天综合网色鬼国产| 91蜜桃传媒精品久久久一区二区| 久久精品人人爽人人爽| 久久99精品国产.久久久久| 日韩欧美国产1| 久久国产人妖系列| 2024国产精品| 激情久久五月天| 久久婷婷色综合| 国产成人精品免费看| 日本一区二区视频在线观看| 国产精品一区二区久久精品爱涩| 久久人人97超碰com| 国产馆精品极品| 久久精品男人的天堂| 丰满少妇在线播放bd日韩电影| 久久午夜老司机| 懂色av中文字幕一区二区三区| 欧美激情一区二区三区不卡 | 日本vs亚洲vs韩国一区三区二区| 欧美三级乱人伦电影| 亚洲成a人v欧美综合天堂| 宅男噜噜噜66一区二区66| 久久国产尿小便嘘嘘| 国产女同互慰高潮91漫画| 99免费精品视频| 污片在线观看一区二区 | 欧美美女一区二区在线观看| 日韩成人免费电影| xfplay精品久久| 99久久精品情趣| 亚洲国产综合视频在线观看| 日韩欧美精品在线视频| 成人一级片在线观看| 一区二区三区av电影 | voyeur盗摄精品| 亚洲一二三四区不卡| 日韩限制级电影在线观看| 国产精品91一区二区| 亚洲精品日韩一| 精品少妇一区二区三区在线视频| 顶级嫩模精品视频在线看| 一区二区三区视频在线看| 日韩午夜精品视频| 99麻豆久久久国产精品免费| 亚洲国产乱码最新视频 | 午夜精品成人在线视频| 久久九九久久九九| 欧美在线观看禁18| 国产一区二区日韩精品| 亚洲综合丝袜美腿| 精品国产乱码久久久久久蜜臀| 色综合久久久久综合体| 久久精品99国产精品日本| 亚洲人成人一区二区在线观看| 欧美成人女星排名| 色又黄又爽网站www久久| 国产美女主播视频一区| 亚洲国产精品久久艾草纯爱| 欧美国产1区2区| 精品国产91九色蝌蚪| 欧美在线观看一区| 99精品国产一区二区三区不卡| 日本在线播放一区二区三区| 亚洲欧美日韩在线不卡| 久久精品免费在线观看| 欧美剧情片在线观看| 91蜜桃免费观看视频| 成人性生交大片免费看中文网站| 蜜臀久久久99精品久久久久久| 亚洲午夜羞羞片| 亚洲欧美激情插| 中文字幕色av一区二区三区| 久久久久国产一区二区三区四区 | 成人免费在线视频| 精品国产自在久精品国产| 欧美精品三级在线观看| 欧美三电影在线| 一本到不卡免费一区二区| 成人午夜精品在线| 国产成人啪免费观看软件| 精品一区二区三区免费观看 | 91色在线porny| 国产成人精品一区二区三区网站观看| 麻豆freexxxx性91精品| 青青草97国产精品免费观看 | 久久激情综合网| 奇米四色…亚洲| 五月婷婷欧美视频| 视频一区二区三区在线| 亚洲国产日韩av| 午夜激情综合网| 毛片av一区二区三区| 久久精品国产免费看久久精品| 久久国产精品第一页| 国产一区二区三区不卡在线观看 | 久久国产精品72免费观看| 免费成人在线观看视频| 看电影不卡的网站| 国内国产精品久久| 国产·精品毛片| 色综合色狠狠综合色| 欧美日韩国产经典色站一区二区三区| 欧美日韩国产首页| 日韩免费高清视频| 国产亚洲精品7777| 亚洲三级免费观看| 亚洲国产视频在线| 久久国内精品自在自线400部| 国产高清精品在线| 成人动漫精品一区二区| 色婷婷精品大在线视频| 欧美日本在线视频| 久久综合狠狠综合久久综合88| 国产日产欧美一区二区视频| 亚洲欧美日韩国产综合| 亚洲妇女屁股眼交7| 蜜乳av一区二区三区| 国产一区二区三区精品视频| 99久久婷婷国产| 欧美丰满美乳xxx高潮www| 久久美女高清视频| 日韩毛片高清在线播放| 三级久久三级久久久| 国产乱国产乱300精品| 91欧美激情一区二区三区成人| 欧美精品在线一区二区三区| 久久亚洲综合色| 亚洲一区二区五区| 黄色成人免费在线| 欧美性色aⅴ视频一区日韩精品| 欧美精品一区男女天堂| 亚洲柠檬福利资源导航| 色猫猫国产区一区二在线视频| 日韩欧美在线123| 最好看的中文字幕久久| 麻豆一区二区三| 欧美中文字幕一区二区三区| 久久免费偷拍视频| 婷婷国产v国产偷v亚洲高清| 成人免费看视频| 精品精品欲导航| 亚洲电影一区二区| 国产suv一区二区三区88区| 69久久夜色精品国产69蝌蚪网| 亚洲欧洲国产专区| 国内精品免费在线观看| 91精品国模一区二区三区| 亚洲另类春色国产| 国产成人免费视频| 91精品国产色综合久久不卡电影| 亚洲免费资源在线播放| 国产91精品一区二区| 欧美大胆人体bbbb| 亚洲国产精品久久人人爱蜜臀 | 亚洲激情自拍偷拍| 国产精品一区三区| 精品国产伦一区二区三区观看方式| 亚洲成人av在线电影| 91免费版在线| 亚洲欧美日韩国产中文在线| 高潮精品一区videoshd| 久久精品欧美一区二区三区麻豆| 精品在线播放午夜| 日韩精品一区二区三区中文精品| 亚洲va韩国va欧美va精品 | 日韩av一级片| 色狠狠桃花综合| 亚洲另类一区二区| 色婷婷综合久久久久中文| 亚洲日本va在线观看| 99久久99久久久精品齐齐| 中文字幕一区av| av福利精品导航| 亚洲精品日韩一| 欧美日韩你懂的| 五月激情丁香一区二区三区|