亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
欧美午夜一区二区三区免费大片| 91蜜桃婷婷狠狠久久综合9色| 欧美视频在线一区| 日日噜噜夜夜狠狠视频欧美人| 日本一区二区动态图| av中文字幕不卡| 天天影视色香欲综合网老头| 欧美三级午夜理伦三级中视频| 中文字幕视频一区二区三区久| aaa国产一区| 亚洲国产精品传媒在线观看| 成人av在线网站| 久久久99精品免费观看不卡| 成人综合在线观看| 色狠狠av一区二区三区| 欧美一区二区免费| 成人动漫在线一区| 久久成人久久鬼色| 午夜国产精品影院在线观看| 国产精品视频九色porn| 精品国产3级a| 欧美一区二区在线观看| 色婷婷久久久久swag精品| 国产剧情一区二区| 精品一区二区精品| 日本欧美韩国一区三区| 亚洲国产精品久久久久秋霞影院| 亚洲情趣在线观看| 一色屋精品亚洲香蕉网站| 久久你懂得1024| 欧美刺激午夜性久久久久久久 | 国产乱码精品一区二区三| 水蜜桃久久夜色精品一区的特点| 亚洲精品视频一区| 亚洲欧美综合另类在线卡通| 中文字幕不卡一区| 国产视频在线观看一区二区三区 | 欧美精品v国产精品v日韩精品| 在线视频欧美区| 91尤物视频在线观看| 成人黄色在线看| 成人午夜私人影院| 成人精品视频.| 99综合电影在线视频| 成人综合激情网| av高清不卡在线| 波多野结衣一区二区三区 | 在线观看日韩电影| 欧美亚洲一区二区在线| 欧美在线视频全部完| 在线观看av一区二区| 欧美最猛性xxxxx直播| 欧美性生交片4| 欧美日韩亚洲综合在线| 91精品国产色综合久久久蜜香臀| 欧美年轻男男videosbes| 欧美精品亚洲一区二区在线播放| 538在线一区二区精品国产| 日韩欧美一区二区久久婷婷| 欧美xxxx老人做受| 国产女人aaa级久久久级 | 亚洲同性gay激情无套| 一区二区三区高清| 日韩国产欧美在线视频| 精品一区二区三区香蕉蜜桃| 国产精品一区二区果冻传媒| jlzzjlzz国产精品久久| 欧美亚洲一区三区| 欧美成人免费网站| 欧美国产精品中文字幕| 一区二区在线观看视频| 视频一区国产视频| 国产麻豆精品久久一二三| 99综合电影在线视频| 欧美顶级少妇做爰| 久久久久久久久久久黄色| 亚洲天堂成人在线观看| 日本午夜精品视频在线观看 | 国产精品中文有码| 97se亚洲国产综合自在线| 欧美日韩高清一区二区不卡| 久久综合久久鬼色| 亚洲乱码国产乱码精品精的特点 | 一本久久a久久免费精品不卡| 欧美精品777| 中文字幕在线观看不卡视频| 天天操天天干天天综合网| 国产精品一区二区在线播放| 色婷婷综合激情| 精品av久久707| 一区二区久久久久| 国产高清精品在线| 欧美一区二区三区视频在线| 国产精品久久午夜夜伦鲁鲁| 日韩av中文字幕一区二区三区| 成人国产精品视频| 欧美成人官网二区| 亚洲在线视频一区| 国产成人av电影| 日韩视频在线观看一区二区| 国产精品美女久久久久久2018| 日韩中文欧美在线| 一本一本大道香蕉久在线精品 | 国产精品理论在线观看| 蜜臀av性久久久久蜜臀aⅴ| 99麻豆久久久国产精品免费| 欧美大片一区二区| 婷婷久久综合九色国产成人 | 国产成人精品亚洲午夜麻豆| 91.com在线观看| 亚洲精品亚洲人成人网在线播放| 国产精华液一区二区三区| 91精品国产综合久久国产大片| 综合av第一页| 成人av资源下载| 久久久精品天堂| 久久99精品久久久久久动态图| 欧美亚洲高清一区二区三区不卡| 国产精品美女久久久久久久久 | 国产在线精品一区在线观看麻豆| 欧美三级一区二区| 一区二区三区成人在线视频| a级高清视频欧美日韩| 国产欧美一区二区三区鸳鸯浴| 免费成人小视频| 日韩一级视频免费观看在线| 亚洲国产精品一区二区尤物区| 一本色道a无线码一区v| 亚洲欧美日本韩国| 91丨porny丨首页| 日韩理论电影院| 一本一道久久a久久精品| 亚洲欧美福利一区二区| heyzo一本久久综合| 久久女同性恋中文字幕| 国产经典欧美精品| 欧美极品aⅴ影院| 成人av资源下载| 亚洲摸摸操操av| 色视频成人在线观看免| 一区二区三区在线免费观看| 色一情一乱一乱一91av| 夜夜操天天操亚洲| 欧美日韩精品欧美日韩精品一 | 91影视在线播放| 一区二区三区在线播放| 色8久久人人97超碰香蕉987| 亚洲男人电影天堂| 欧美三级视频在线播放| 午夜天堂影视香蕉久久| 欧美一区二区三区在线看| 久久99国产精品尤物| 久久夜色精品一区| 黄网站免费久久| 欧美精品一区二区在线观看| 蜜臀av性久久久久蜜臀aⅴ流畅| 精品日韩av一区二区| 精品亚洲成av人在线观看| 日韩一卡二卡三卡国产欧美| 蜜臂av日日欢夜夜爽一区| 欧美精品一区二区久久久| 久久99精品一区二区三区三区| 日韩一区二区三区在线视频| 日韩激情一二三区| 精品久久久久久久久久久久久久久久久| 日本sm残虐另类| 欧美成人一区二区三区片免费| 久久精品久久综合| 中文幕一区二区三区久久蜜桃| 成人免费看黄yyy456| 国产精品成人一区二区三区夜夜夜| 成人免费毛片片v| 婷婷成人综合网| 欧美tickling网站挠脚心| 国产米奇在线777精品观看| 91超碰这里只有精品国产| 狠狠色丁香久久婷婷综合_中 | 26uuu精品一区二区三区四区在线 26uuu精品一区二区在线观看 | 精品在线观看免费| 久久综合久久99| 欧美中文一区二区三区| 天天操天天综合网| 久久视频一区二区| 国产精品羞羞答答xxdd| 亚洲一区视频在线观看视频| 欧美精品三级在线观看| 久久99国产精品久久99果冻传媒| 精品精品国产高清a毛片牛牛| 成人免费视频视频在线观看免费| 一区二区三区成人在线视频| 欧美一级淫片007| 国产福利视频一区二区三区| 亚洲一级二级在线| 精品久久久网站| 91色视频在线| 一区二区三区四区乱视频| 91精品国产综合久久久久久漫画| 国产剧情av麻豆香蕉精品| 一区二区三区在线观看网站| 日韩精品一区二区三区三区免费|