亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
喷水一区二区三区| 麻豆国产精品一区二区三区| 26uuu精品一区二区三区四区在线| 91成人在线精品| 91麻豆精品在线观看| 93久久精品日日躁夜夜躁欧美| 福利视频网站一区二区三区| 成人激情黄色小说| 成人av一区二区三区| 成人午夜av影视| 91黄视频在线| 在线成人av影院| 欧美精品一区二| 欧美国产一区二区| 艳妇臀荡乳欲伦亚洲一区| 亚洲国产中文字幕在线视频综合 | 亚洲影视在线观看| 五月激情综合婷婷| 精品伊人久久久久7777人| 顶级嫩模精品视频在线看| 91在线观看高清| 欧美一卡2卡三卡4卡5免费| 精品久久久久久亚洲综合网| 国产偷国产偷精品高清尤物| 亚洲人精品午夜| 久久精品99国产精品| 精品一区二区久久| 91欧美激情一区二区三区成人| 欧美精品自拍偷拍| 久久婷婷久久一区二区三区| 成人欧美一区二区三区在线播放| 亚洲国产精品一区二区www在线| 青青草伊人久久| 色网综合在线观看| 久久中文娱乐网| 亚洲一区在线观看免费| 国产精品一区在线| 欧美日韩高清在线播放| 欧美韩日一区二区三区四区| 午夜视频一区在线观看| 成人免费观看男女羞羞视频| 日韩一区二区在线看片| 亚洲欧洲国产日韩| 国产福利一区二区三区| 欧美日韩国产综合草草| 国产精品白丝在线| 国产在线视频一区二区| 欧美精品视频www在线观看| 中文字幕不卡的av| 精品午夜一区二区三区在线观看| 91久久线看在观草草青青| 久久精品亚洲精品国产欧美kt∨ | 欧美色中文字幕| 国产精品色噜噜| 精东粉嫩av免费一区二区三区| 色婷婷国产精品综合在线观看| 日韩精品中文字幕在线不卡尤物 | 国产传媒久久文化传媒| 欧美一区二区三区视频在线 | 亚洲高清视频中文字幕| 成人av第一页| 中文字幕乱码日本亚洲一区二区| 婷婷一区二区三区| 欧亚洲嫩模精品一区三区| 中文字幕一区二区视频| 不卡一区二区在线| 亚洲国产精品av| 成人av在线播放网址| 国产日产欧美一区| 国产黄色91视频| 2023国产一二三区日本精品2022| 日本一不卡视频| 日韩一区二区三区免费看| 蜜桃av一区二区| 欧美mv日韩mv国产| 国产精品99久久不卡二区| 久久亚洲捆绑美女| 国产v综合v亚洲欧| 亚洲免费av高清| 欧美日韩免费观看一区二区三区 | 美女网站色91| 日韩一区二区电影| 蜜桃视频第一区免费观看| 精品久久免费看| 高潮精品一区videoshd| 亚洲麻豆国产自偷在线| 在线日韩国产精品| 日产精品久久久久久久性色| 7777精品伊人久久久大香线蕉 | 自拍偷拍国产精品| 欧美三级日韩三级国产三级| 天天影视涩香欲综合网| 精品欧美一区二区久久| 成人av网站大全| 日韩成人免费看| 国产精品水嫩水嫩| 欧美色精品天天在线观看视频| 天天色综合成人网| www亚洲一区| 欧美亚洲日本国产| 精品亚洲成a人在线观看| 中文字幕成人网| 欧美精品一二三| 国产99久久精品| 天堂影院一区二区| 国产女人18毛片水真多成人如厕 | 欧美日韩午夜影院| 国产一区二区成人久久免费影院| 亚洲福中文字幕伊人影院| 欧美日韩成人在线| 粉嫩av亚洲一区二区图片| 亚洲一二三四在线| 中文字幕在线不卡一区二区三区| 欧美一区二区视频在线观看2020| 国产乱淫av一区二区三区| 亚洲国产日韩a在线播放| 国产人成一区二区三区影院| 欧美在线观看禁18| 成人免费看黄yyy456| 美女诱惑一区二区| 夜夜嗨av一区二区三区| 欧美国产精品一区| 欧美成人精品3d动漫h| 在线看不卡av| 波多野结衣精品在线| 蜜桃传媒麻豆第一区在线观看| 亚洲欧洲综合另类在线| www一区二区| 精品国产乱码久久久久久牛牛 | 婷婷综合久久一区二区三区| 国产精品久久久久9999吃药| 日韩精品一区二区在线| 在线国产电影不卡| 91麻豆福利精品推荐| 国产成人鲁色资源国产91色综| 日本不卡一二三区黄网| 亚洲成人免费在线| 亚洲国产日韩a在线播放性色| 国产精品久久久久久亚洲毛片 | 日本精品一区二区三区高清| 国产成人免费视| 国产精品自拍av| 久久99精品久久久久久动态图 | 国产一区二区三区免费播放| 爽爽淫人综合网网站| 亚洲制服丝袜av| 一区二区三区视频在线看| 亚洲天堂精品视频| 亚洲欧洲日韩在线| 亚洲视频在线一区| 亚洲一区二区不卡免费| 亚洲影视在线播放| 天堂在线亚洲视频| 精品在线免费观看| 粗大黑人巨茎大战欧美成人| 粉嫩久久99精品久久久久久夜| 成人性色生活片| 91一区在线观看| 欧美日韩国产小视频在线观看| 欧美日韩卡一卡二| 日韩午夜在线播放| 久久久久久黄色| 亚洲日本丝袜连裤袜办公室| 一区二区三区精品久久久| 一区二区高清在线| 日韩成人伦理电影在线观看| 精品一区二区av| 99精品偷自拍| 欧美日韩国产综合一区二区三区| 欧美一区二区日韩| 久久精子c满五个校花| 亚洲国产成人一区二区三区| 亚洲欧美二区三区| 日韩福利电影在线| 国产成人福利片| 91激情五月电影| 欧美成人a∨高清免费观看| 欧美激情一区三区| 午夜精品成人在线视频| 国产中文字幕一区| 色八戒一区二区三区| 欧美一区二区视频在线观看| 国产亚洲综合色| 日日夜夜一区二区| 成人免费高清视频在线观看| 欧美网站大全在线观看| 久久色在线视频| 亚洲高清免费在线| 成人免费视频一区| 欧美电影免费观看高清完整版| 国产精品国产三级国产普通话99 | 亚洲视频香蕉人妖| 日韩精品视频网站| 99国产精品久久久久久久久久 | 日韩欧美的一区| 亚洲欧美另类久久久精品| 久久国内精品自在自线400部| 91在线播放网址| 欧美国产欧美综合| 精品一二三四在线|