| | |
| | | using HMI.UI.Util; |
| | | 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.title == "一区扫码") |
| | | |
| | | 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 |
| | | { |
| | | portName = "COM2"; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | comStr = "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 |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MsgBoxHelper.Error(this, $"初始化扫码枪失败!{ex.StackTrace}"); |
| | | ViewControl.Logger.Error("Init Scan Gun Failed.", ex); |
| | | MsgBoxHelper.Error(this, $"{this.lang("Tr.InitGunFailed")}: {ex.StackTrace}"); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MessageBox.Show($"获取扫码枪数据失败!{ex.StackTrace}"); |
| | | ViewControl.Logger.Error("Get Scan Gun Data Failed.", ex); |
| | | MessageBox.Show($"{this.lang("Tr.GetGunData")}: {ex.StackTrace}"); |
| | | } |
| | | } |
| | | |
| | |
| | | string position = positionText.Text, snr = snrText.Text; |
| | | if (string.IsNullOrEmpty(position) || string.IsNullOrEmpty(snr)) |
| | | { |
| | | MessageBox.Show("请输入储位条码和产品条码"); |
| | | ToastHelper.Warning(this, this.lang("Tr.PleaseInputSnrs")); |
| | | return; |
| | | } |
| | | try |
| | | { |
| | | FinishBarcode.Invoke(this, new BarcodeEventArg(title, position, snr)); |
| | | FinishBarcode.Invoke(this, new BarcodeEventArg(Tag.ToString(), position, snr)); |
| | | //positionText.Text = ""; |
| | | //snrText.Text = ""; |
| | | positionText.Focus(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MessageBox.Show(ex.Message); |
| | | ViewControl.Logger.Error("Con_Click Failed.", ex); |
| | | ToastHelper.Warning(this, ex.Message); |
| | | } |
| | | }); |
| | | } |
| | |
| | | string position = positionText.Text, snr = snrText.Text; |
| | | if (string.IsNullOrEmpty(position) || string.IsNullOrEmpty(snr)) |
| | | { |
| | | MessageBox.Show("请输入储位条码和产品条码"); |
| | | ToastHelper.Warning(this, this.lang("Tr.PleaseInputSnrs")); |
| | | return; |
| | | } |
| | | try |
| | | { |
| | | FinishBarcode.Invoke(this, new BarcodeEventArg(title, position, snr)); |
| | | FinishBarcode.Invoke(this, new BarcodeEventArg(Tag.ToString(), position, snr)); |
| | | this.Close(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MessageBox.Show(ex.Message); |
| | | ViewControl.Logger.Error("Con_Click Failed.", ex); |
| | | ToastHelper.Warning(this, ex.Message); |
| | | } |
| | | } |
| | | |
| | |
| | | try |
| | | { |
| | | serialPort.Close(); |
| | | serialPort = null; |
| | | } |
| | | catch (Exception ex) |
| | | { |