public bool SetParm(ComPortParm cpp) { bool result; try { if (this.IsOpen) { this.Close(); } this.handle.BaudRate = cpp.波特率; this.handle.PortName = cpp.串口名称; this.handle.DataBits = cpp.数据位; this.handle.StopBits = cpp.停止位; this.handle.Parity = cpp.校验位; this.handle.DiscardNull = cpp.DiscardNull; this.handle.DtrEnable = cpp.DtrEnable; this.handle.Handshake = cpp.Handshake; this.handle.RtsEnable = cpp.RtsEnable; this.Cpp = cpp; result = true; } catch { result = false; } return(result); }
public Com(ComPortParm cpp) { this.Cpp = cpp; this.handle = new SerialPort(); this.handle.PortName = cpp.串口名称; this.handle.BaudRate = cpp.波特率; this.handle.DataBits = cpp.数据位; this.handle.Parity = cpp.校验位; this.handle.StopBits = cpp.停止位; this.handle.DiscardNull = cpp.DiscardNull; this.handle.DtrEnable = cpp.DtrEnable; this.handle.Handshake = cpp.Handshake; this.handle.RtsEnable = cpp.RtsEnable; this.handle.DataReceived += delegate(object a, SerialDataReceivedEventArgs b) { SerialDataReceivedEventHandler dataReceive = this.DataReceive; if (dataReceive == null) { return; } dataReceive(a, b); }; }
/// <summary> /// ComPortParm.Parse :字符串转串口参数 var cpp = ComPortParm.Parse("5,9600,N,8,1"); /// </summary> /// <param name="parm">("5,9600,N,8,1")</param> /// <returns></returns> public static ComPortParm Parse(string parm) { ComPortParm cpp = new ComPortParm(); string[] array = parm.Trim().ToUpper().Split(new char[] { ',' }); if (array.Length != 0) { cpp.串口名称 = "COM" + array[0]; } if (array.Length > 1) { cpp.波特率 = int.Parse(array[1]); } string a = array[2]; if (!(a == "N")) { if (!(a == "E")) { if (!(a == "O")) { if (!(a == "M")) { if (a == "S") { cpp.校验位 = Parity.Space; } } else { cpp.校验位 = Parity.Mark; } } else { cpp.校验位 = Parity.Odd; } } else { cpp.校验位 = Parity.Even; } } else { cpp.校验位 = Parity.None; } if (array.Length > 3) { cpp.数据位 = int.Parse(array[3]); } a = array[4]; if (!(a == "1")) { if (!(a == "2")) { if (!(a == "1.5")) { if (a == "N") { cpp.停止位 = StopBits.None; } } else { cpp.停止位 = StopBits.OnePointFive; } } else { cpp.停止位 = StopBits.Two; } } else { cpp.停止位 = StopBits.One; } System.Common.ForEach(array, delegate(string m) { string a2 = m.Trim().ToLower(); if (a2 == "r") { cpp.RtsEnable = true; return; } if (a2 == "d") { cpp.DtrEnable = true; return; } if (a2 == "hno") { cpp.Handshake = Handshake.None; return; } if (a2 == "hxx") { cpp.Handshake = Handshake.XOnXOff; return; } if (a2 == "hrs") { cpp.Handshake = Handshake.RequestToSend; return; } if (!(a2 == "hrx")) { return; } cpp.Handshake = Handshake.RequestToSendXOnXOff; }); return(cpp); }
/// <summary> /// /// </summary> /// <param name="cpp">参数</param> /// <param name="ReceiveDelay">等待接收时间</param> public ComWaitRead(ComPortParm cpp, int ReceiveDelay = 50) : base(cpp) { base.DataReceive += this.ComWaitRead_DataReceive; this.ReceiveDelay = ReceiveDelay; }
// Token: 0x06000B2E RID: 2862 RVA: 0x00024CA5 File Offset: 0x00022EA5 public ComSimple(ComPortParm cpp) : base(cpp) { base.DataReceive += this.ComSimple_DataReceive; }
public ComHandled(ComPortParm cpp) : base(cpp) { }
public ComResponse(ComPortParm cpp, int delay = 100) : base(cpp) { this.responsedelay = delay; }
// Token: 0x06000B0C RID: 2828 RVA: 0x000246D8 File Offset: 0x000228D8 public ComDelayRead(ComPortParm cpp, int ReceiveDelay = 150) : base(cpp) { base.DataReceive += this.ComPluss_dataReceive; this.bw.DoWork += this.bw_DoWork; this.ReceiveDelay = ReceiveDelay; }