| | |
| | | using HMI.Core.Util; |
| | | using HMI.UI.Util; |
| | | using HMI.Util; |
| | | using Panuon.WPF.UI; |
| | | using Plugin.TestResult.Model; |
| | | using System; |
| | | using System.ComponentModel; |
| | | using System.IO.Ports; |
| | |
| | | { |
| | | string comStr = ""; |
| | | if (serialPort != null) return; |
| | | if (this.Tag == "Zone1") |
| | | |
| | | string section = this.Tag.ToString(); |
| | | ScannerConfig common = ScannerConfig.ReadFromIni(ViewControl.SannerIniFile, "Config"); |
| | | |
| | | string portName = IniFileHelper.ReadIniData(section, "PortName", "", ViewControl.SannerIniFile); |
| | | if (string.IsNullOrEmpty(portName)) |
| | | { |
| | | comStr = "COM1"; |
| | | if (section.StartsWith("A")) |
| | | { |
| | | portName = "COM1"; |
| | | } |
| | | else |
| | | { |
| | | comStr = "COM2"; |
| | | portName = "COM2"; |
| | | } |
| | | } |
| | | common.PortName = portName; |
| | | |
| | | |
| | | // 配置串口 |
| | | serialPort = new SerialPort |
| | | { |
| | | PortName = comStr, |
| | | BaudRate = 115200, |
| | | PortName = common.PortName, |
| | | BaudRate = common.BaudRate, |
| | | Parity = Parity.None, |
| | | DataBits = 8, |
| | | StopBits = StopBits.One, |
| | | DataBits = common.DataBits, |
| | | StopBits = common.StopBits, |
| | | Handshake = Handshake.None, |
| | | DtrEnable = true, |
| | | RtsEnable = true |
| | | DtrEnable = common.DtrEnable, |
| | | RtsEnable = common.RtsEnable |
| | | //ReadTimeout = 500, |
| | | //WriteTimeout = 500, |
| | | //ReciveBufferSize=4096 |
| | |
| | | try |
| | | { |
| | | serialPort.Close(); |
| | | serialPort = null; |
| | | } |
| | | catch (Exception ex) |
| | | { |