using LB_VisionProcesses.BarcodeReaders; using LB_VisionProcesses.BarcodeReaders.Huayray; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace LB_SmartVision.Forms.Pages.BarcodeReaderPage { public partial class CreateBarcodeReaderForm : Form { public BarcodeReaderBase barcodeReader { get; set; } public bool bCreate = false; public CreateBarcodeReaderForm(BarcodeReaderBase reader = null) { InitializeComponent(); // 禁止修改窗口大小 this.FormBorderStyle = FormBorderStyle.FixedDialog; if (reader == null) this.barcodeReader = new HRBarcodeReader(); else this.barcodeReader = reader; uiButtonCreate.Enabled = false; } private void uiButtonTest_Click(object sender, EventArgs e) { uiButtonCreate.Enabled = false; if (string.IsNullOrEmpty(uiComboBoxSN.Text)) MessageBox.Show($"初始化读码器[{uiComboBoxSN.Text}]为空!", "异常"); if (barcodeReader == null) { MessageBox.Show("请先选择读码器品牌!", "异常"); return; } barcodeReader.Close(); if (barcodeReader.Open(uiComboBoxSN.Text)) { uiButtonCreate.Enabled = true; barcodeReader.Close(); } else MessageBox.Show($"初始化读码器[{uiComboBoxSN.Text}]失败!", "异常"); } private void uiButtonCreate_Click(object sender, EventArgs e) { if (barcodeReader.Open(uiComboBoxSN.Text)) { barcodeReader.SN = uiComboBoxSN.Text; bCreate = true; this.Close(); } else MessageBox.Show($"初始化读码器[{uiComboBoxSN.Text}]失败!", "异常"); } private void uiButtonCancel_Click(object sender, EventArgs e) { if (barcodeReader != null) barcodeReader.Close(); bCreate = false; this.Close(); } private void uiComboBoxBrand_MouseClick(object sender, MouseEventArgs e) { uiComboBoxBrand.Items.Clear(); foreach (BarcodeReaderBrand brand in Enum.GetValues(typeof(BarcodeReaderBrand))) { if (brand != BarcodeReaderBrand.Unsupported) uiComboBoxBrand.Items.Add(brand.ToString()); } } private void uiComboBoxBrand_SelectedIndexChanged(object sender, EventArgs e) { uiButtonCreate.Enabled = false; uiComboBoxSN.Text = string.Empty; if (barcodeReader != null) barcodeReader.Close(); Enum.TryParse(uiComboBoxBrand.Text, out BarcodeReaderBrand brand); switch (brand) { case BarcodeReaderBrand.Huayray: barcodeReader = new HRBarcodeReader(); break; default: return; } } private void uiComboBoxSN_MouseClick(object sender, MouseEventArgs e) { uiButtonCreate.Enabled = false; uiComboBoxSN.Text = string.Empty; uiComboBoxSN.Items.Clear(); var list = barcodeReader.GetDeviceList(); foreach (string sn in list) uiComboBoxSN.Items.Add(sn); } } }