| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using LB_VisionControl; |
| | | using System.Drawing; |
| | | using System.Windows.Forms; |
| | | |
| | | namespace LB_SmartVision.Forms.Pages.BarcodeReaderPage |
| | | { |
| | | partial class BarcodeReaderForm |
| | | { |
| | | /// <summary> |
| | | /// Required designer variable. |
| | | /// </summary> |
| | | private System.ComponentModel.IContainer components = null; |
| | | |
| | | /// <summary> |
| | | /// Clean up any resources being used. |
| | | /// </summary> |
| | | /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
| | | protected override void Dispose(bool disposing) |
| | | { |
| | | if (disposing && (components != null)) |
| | | { |
| | | components.Dispose(); |
| | | } |
| | | base.Dispose(disposing); |
| | | } |
| | | |
| | | #region Windows Form Designer generated code |
| | | |
| | | /// <summary> |
| | | /// Required method for Designer support - do not modify |
| | | /// the contents of this method with the code editor. |
| | | /// </summary> |
| | | private void InitializeComponent() |
| | | { |
| | | uiGroupBoxImage = new GroupBox(); |
| | | uiGroupBoxControl = new GroupBox(); |
| | | uiGroupBoxResult = new GroupBox(); |
| | | uiComboBoxBrand = new ComboBox(); |
| | | uiLabel1 = new Label(); |
| | | uiRadioButtonSoftTrigger = new RadioButton(); |
| | | uiRadioButtonHardTrigger = new RadioButton(); |
| | | uiButtonStartGrabbing = new Button(); |
| | | uiButtonStopGrabbing = new Button(); |
| | | uiButtonSoftTrigger = new Button(); |
| | | uiListBoxBarcodes = new ListBox(); |
| | | uiTextBoxResult = new TextBox(); |
| | | uiLabel2 = new Label(); |
| | | uiButtonClear = new Button(); |
| | | uiGroupBoxImage.SuspendLayout(); |
| | | uiGroupBoxControl.SuspendLayout(); |
| | | uiGroupBoxResult.SuspendLayout(); |
| | | SuspendLayout(); |
| | | // |
| | | // uiGroupBoxImage |
| | | // |
| | | uiGroupBoxImage.BackColor = Color.FromArgb(32, 41, 50); |
| | | uiGroupBoxImage.Font = new Font("å®ä½", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | uiGroupBoxImage.ForeColor = Color.White; |
| | | uiGroupBoxImage.Location = new Point(12, 12); |
| | | uiGroupBoxImage.Margin = new Padding(4, 5, 4, 5); |
| | | uiGroupBoxImage.Name = "uiGroupBoxImage"; |
| | | uiGroupBoxImage.Padding = new Padding(4, 5, 4, 5); |
| | | uiGroupBoxImage.Size = new Size(400, 400); |
| | | uiGroupBoxImage.TabIndex = 0; |
| | | uiGroupBoxImage.TabStop = false; |
| | | uiGroupBoxImage.Text = "å¾åé¢è§"; |
| | | // |
| | | // uiGroupBoxControl |
| | | // |
| | | uiGroupBoxControl.BackColor = Color.FromArgb(32, 41, 50); |
| | | uiGroupBoxControl.Controls.Add(uiButtonSoftTrigger); |
| | | uiGroupBoxControl.Controls.Add(uiButtonStopGrabbing); |
| | | uiGroupBoxControl.Controls.Add(uiButtonStartGrabbing); |
| | | uiGroupBoxControl.Controls.Add(uiRadioButtonHardTrigger); |
| | | uiGroupBoxControl.Controls.Add(uiRadioButtonSoftTrigger); |
| | | uiGroupBoxControl.Controls.Add(uiComboBoxBrand); |
| | | uiGroupBoxControl.Controls.Add(uiLabel1); |
| | | uiGroupBoxControl.Font = new Font("å®ä½", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | uiGroupBoxControl.ForeColor = Color.White; |
| | | uiGroupBoxControl.Location = new Point(430, 12); |
| | | uiGroupBoxControl.Margin = new Padding(4, 5, 4, 5); |
| | | uiGroupBoxControl.Name = "uiGroupBoxControl"; |
| | | uiGroupBoxControl.Padding = new Padding(4, 5, 4, 5); |
| | | uiGroupBoxControl.Size = new Size(350, 200); |
| | | uiGroupBoxControl.TabIndex = 1; |
| | | uiGroupBoxControl.TabStop = false; |
| | | uiGroupBoxControl.Text = "æ§å¶é¢æ¿"; |
| | | // |
| | | // uiGroupBoxResult |
| | | // |
| | | uiGroupBoxResult.BackColor = Color.FromArgb(32, 41, 50); |
| | | uiGroupBoxResult.Controls.Add(uiButtonClear); |
| | | uiGroupBoxResult.Controls.Add(uiLabel2); |
| | | uiGroupBoxResult.Controls.Add(uiTextBoxResult); |
| | | uiGroupBoxResult.Controls.Add(uiListBoxBarcodes); |
| | | uiGroupBoxResult.Font = new Font("å®ä½", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | uiGroupBoxResult.ForeColor = Color.White; |
| | | uiGroupBoxResult.Location = new Point(430, 230); |
| | | uiGroupBoxResult.Margin = new Padding(4, 5, 4, 5); |
| | | uiGroupBoxResult.Name = "uiGroupBoxResult"; |
| | | uiGroupBoxResult.Padding = new Padding(4, 5, 4, 5); |
| | | uiGroupBoxResult.Size = new Size(350, 280); |
| | | uiGroupBoxResult.TabIndex = 2; |
| | | uiGroupBoxResult.TabStop = false; |
| | | uiGroupBoxResult.Text = "读ç ç»æ"; |
| | | // |
| | | // uiComboBoxBrand |
| | | // |
| | | uiComboBoxBrand.DropDownStyle = ComboBoxStyle.DropDownList; |
| | | uiComboBoxBrand.FormattingEnabled = true; |
| | | uiComboBoxBrand.Location = new Point(90, 50); |
| | | uiComboBoxBrand.Name = "uiComboBoxBrand"; |
| | | uiComboBoxBrand.Size = new Size(150, 28); |
| | | uiComboBoxBrand.TabIndex = 0; |
| | | // |
| | | // uiLabel1 |
| | | // |
| | | uiLabel1.Location = new Point(15, 50); |
| | | uiLabel1.Name = "uiLabel1"; |
| | | uiLabel1.Size = new Size(70, 29); |
| | | uiLabel1.TabIndex = 1; |
| | | uiLabel1.Text = "åç:"; |
| | | uiLabel1.TextAlign = ContentAlignment.MiddleRight; |
| | | // |
| | | // uiRadioButtonSoftTrigger |
| | | // |
| | | uiRadioButtonSoftTrigger.Checked = true; |
| | | uiRadioButtonSoftTrigger.Location = new Point(20, 90); |
| | | uiRadioButtonSoftTrigger.Name = "uiRadioButtonSoftTrigger"; |
| | | uiRadioButtonSoftTrigger.Size = new Size(100, 29); |
| | | uiRadioButtonSoftTrigger.TabIndex = 2; |
| | | uiRadioButtonSoftTrigger.TabStop = true; |
| | | uiRadioButtonSoftTrigger.Text = "软触å"; |
| | | uiRadioButtonSoftTrigger.UseVisualStyleBackColor = true; |
| | | uiRadioButtonSoftTrigger.CheckedChanged += uiRadioButtonSoftTrigger_CheckedChanged; |
| | | // |
| | | // uiRadioButtonHardTrigger |
| | | // |
| | | uiRadioButtonHardTrigger.Location = new Point(140, 90); |
| | | uiRadioButtonHardTrigger.Name = "uiRadioButtonHardTrigger"; |
| | | uiRadioButtonHardTrigger.Size = new Size(100, 29); |
| | | uiRadioButtonHardTrigger.TabIndex = 3; |
| | | uiRadioButtonHardTrigger.Text = "硬触å"; |
| | | uiRadioButtonHardTrigger.UseVisualStyleBackColor = true; |
| | | // |
| | | // uiButtonStartGrabbing |
| | | // |
| | | uiButtonStartGrabbing.BackColor = Color.FromArgb(0, 150, 136); |
| | | uiButtonStartGrabbing.ForeColor = Color.White; |
| | | uiButtonStartGrabbing.Location = new Point(20, 140); |
| | | uiButtonStartGrabbing.Name = "uiButtonStartGrabbing"; |
| | | uiButtonStartGrabbing.Size = new Size(100, 35); |
| | | uiButtonStartGrabbing.TabIndex = 4; |
| | | uiButtonStartGrabbing.Text = "å¼å§éé"; |
| | | uiButtonStartGrabbing.UseVisualStyleBackColor = false; |
| | | uiButtonStartGrabbing.Click += uiButtonStartGrabbing_Click; |
| | | // |
| | | // uiButtonStopGrabbing |
| | | // |
| | | uiButtonStopGrabbing.BackColor = Color.FromArgb(255, 87, 34); |
| | | uiButtonStopGrabbing.Enabled = false; |
| | | uiButtonStopGrabbing.ForeColor = Color.White; |
| | | uiButtonStopGrabbing.Location = new Point(140, 140); |
| | | uiButtonStopGrabbing.Name = "uiButtonStopGrabbing"; |
| | | uiButtonStopGrabbing.Size = new Size(100, 35); |
| | | uiButtonStopGrabbing.TabIndex = 5; |
| | | uiButtonStopGrabbing.Text = "忢éé"; |
| | | uiButtonStopGrabbing.UseVisualStyleBackColor = false; |
| | | uiButtonStopGrabbing.Click += uiButtonStopGrabbing_Click; |
| | | // |
| | | // uiButtonSoftTrigger |
| | | // |
| | | uiButtonSoftTrigger.BackColor = Color.FromArgb(64, 158, 255); |
| | | uiButtonSoftTrigger.ForeColor = Color.White; |
| | | uiButtonSoftTrigger.Location = new Point(260, 140); |
| | | uiButtonSoftTrigger.Name = "uiButtonSoftTrigger"; |
| | | uiButtonSoftTrigger.Size = new Size(75, 35); |
| | | uiButtonSoftTrigger.TabIndex = 6; |
| | | uiButtonSoftTrigger.Text = "触å"; |
| | | uiButtonSoftTrigger.UseVisualStyleBackColor = false; |
| | | uiButtonSoftTrigger.Click += uiButtonSoftTrigger_Click; |
| | | // |
| | | // uiListBoxBarcodes |
| | | // |
| | | uiListBoxBarcodes.FormattingEnabled = true; |
| | | uiListBoxBarcodes.ItemHeight = 20; |
| | | uiListBoxBarcodes.Location = new Point(15, 35); |
| | | uiListBoxBarcodes.Name = "uiListBoxBarcodes"; |
| | | uiListBoxBarcodes.Size = new Size(320, 164); |
| | | uiListBoxBarcodes.TabIndex = 0; |
| | | // |
| | | // uiTextBoxResult |
| | | // |
| | | uiTextBoxResult.Location = new Point(90, 210); |
| | | uiTextBoxResult.Name = "uiTextBoxResult"; |
| | | uiTextBoxResult.ReadOnly = true; |
| | | uiTextBoxResult.Size = new Size(160, 26); |
| | | uiTextBoxResult.TabIndex = 1; |
| | | // |
| | | // uiLabel2 |
| | | // |
| | | uiLabel2.Location = new Point(15, 210); |
| | | uiLabel2.Name = "uiLabel2"; |
| | | uiLabel2.Size = new Size(70, 29); |
| | | uiLabel2.TabIndex = 2; |
| | | uiLabel2.Text = "ç¶æ:"; |
| | | uiLabel2.TextAlign = ContentAlignment.MiddleRight; |
| | | // |
| | | // uiButtonClear |
| | | // |
| | | uiButtonClear.BackColor = Color.FromArgb(64, 158, 255); |
| | | uiButtonClear.ForeColor = Color.White; |
| | | uiButtonClear.Location = new Point(260, 208); |
| | | uiButtonClear.Name = "uiButtonClear"; |
| | | uiButtonClear.Size = new Size(75, 30); |
| | | uiButtonClear.TabIndex = 3; |
| | | uiButtonClear.Text = "æ¸
空"; |
| | | uiButtonClear.UseVisualStyleBackColor = false; |
| | | uiButtonClear.Click += uiButtonClear_Click; |
| | | // |
| | | // BarcodeReaderForm |
| | | // |
| | | AutoScaleDimensions = new SizeF(7F, 17F); |
| | | AutoScaleMode = AutoScaleMode.Font; |
| | | BackColor = Color.FromArgb(32, 41, 50); |
| | | ClientSize = new Size(800, 530); |
| | | Controls.Add(uiGroupBoxResult); |
| | | Controls.Add(uiGroupBoxControl); |
| | | Controls.Add(uiGroupBoxImage); |
| | | Name = "BarcodeReaderForm"; |
| | | StartPosition = FormStartPosition.CenterScreen; |
| | | Text = "读ç 卿µè¯"; |
| | | FormClosing += BarcodeReaderForm_FormClosing; |
| | | uiGroupBoxImage.ResumeLayout(false); |
| | | uiGroupBoxControl.ResumeLayout(false); |
| | | uiGroupBoxResult.ResumeLayout(false); |
| | | uiGroupBoxResult.PerformLayout(); |
| | | ResumeLayout(false); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | private GroupBox uiGroupBoxImage; |
| | | private GroupBox uiGroupBoxControl; |
| | | private GroupBox uiGroupBoxResult; |
| | | private ComboBox uiComboBoxBrand; |
| | | private Label uiLabel1; |
| | | private RadioButton uiRadioButtonSoftTrigger; |
| | | private RadioButton uiRadioButtonHardTrigger; |
| | | private Button uiButtonStartGrabbing; |
| | | private Button uiButtonStopGrabbing; |
| | | private Button uiButtonSoftTrigger; |
| | | private ListBox uiListBoxBarcodes; |
| | | private TextBox uiTextBoxResult; |
| | | private Label uiLabel2; |
| | | private Button uiButtonClear; |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using LB_VisionProcesses.BarcodeReaders; |
| | | using System; |
| | | using System.Diagnostics; |
| | | using System.Drawing; |
| | | using System.Windows.Forms; |
| | | |
| | | namespace LB_SmartVision.Forms.Pages.BarcodeReaderPage |
| | | { |
| | | public partial class BarcodeReaderForm : Form |
| | | { |
| | | BarcodeReaderBase barcodeReader { get; set; } |
| | | PictureBox pictureBox1 { get; set; } |
| | | |
| | | public BarcodeReaderForm() |
| | | { |
| | | InitializeComponent(); |
| | | } |
| | | |
| | | public BarcodeReaderForm(BarcodeReaderBase reader) |
| | | { |
| | | InitializeComponent(); |
| | | |
| | | // å建å¾åæ¾ç¤ºæ§ä»¶ |
| | | pictureBox1 = new PictureBox(); |
| | | pictureBox1.Dock = DockStyle.Fill; |
| | | pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; |
| | | uiGroupBoxImage.Controls.Add(pictureBox1); |
| | | |
| | | if (reader == null) |
| | | return; |
| | | |
| | | this.barcodeReader = reader; |
| | | this.Text = reader.SN; |
| | | |
| | | // æ·»å åçé项 |
| | | foreach (BarcodeReaderBrand brand in Enum.GetValues(typeof(BarcodeReaderBrand))) |
| | | { |
| | | if (brand != BarcodeReaderBrand.Unsupported) |
| | | uiComboBoxBrand.Items.Add(brand.ToString()); |
| | | } |
| | | |
| | | // 设置åç |
| | | uiComboBoxBrand.Text = reader.Brand.ToString(); |
| | | |
| | | // å è½½åè°å½æ° |
| | | Subscribe(); |
| | | } |
| | | |
| | | private void BarcodeReaderForm_FormClosing(object sender, FormClosingEventArgs e) |
| | | { |
| | | if (barcodeReader == null) |
| | | return; |
| | | |
| | | barcodeReader.StopGrabbing(); |
| | | Unsubscribe(); |
| | | } |
| | | |
| | | public void Unsubscribe() |
| | | { |
| | | try |
| | | { |
| | | if (barcodeReader == null) |
| | | return; |
| | | // åæ¶åè°å½æ° |
| | | barcodeReader.BarcodeRead -= OnBarcodeRead; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // è®°å½éè¯¯ä¿¡æ¯ |
| | | Debug.WriteLine($"é误: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | public void Subscribe() |
| | | { |
| | | try |
| | | { |
| | | if (barcodeReader == null) |
| | | return; |
| | | |
| | | // åæ¶åè°å½æ° |
| | | barcodeReader.BarcodeRead -= OnBarcodeRead; |
| | | // å è½½åè°å½æ° |
| | | barcodeReader.BarcodeRead += OnBarcodeRead; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // è®°å½éè¯¯ä¿¡æ¯ |
| | | Debug.WriteLine($"é误: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | private void OnBarcodeRead(object sender, BarcodeEventArgs e) |
| | | { |
| | | if (e.Barcodes == null || e.Barcodes.Count == 0) |
| | | return; |
| | | |
| | | if (this.InvokeRequired) |
| | | { |
| | | this.Invoke(new Action(() => |
| | | { |
| | | DisplayBarcodeResult(e); |
| | | })); |
| | | } |
| | | else |
| | | { |
| | | DisplayBarcodeResult(e); |
| | | } |
| | | } |
| | | |
| | | private void DisplayBarcodeResult(BarcodeEventArgs e) |
| | | { |
| | | uiListBoxBarcodes.Items.Clear(); |
| | | if (e.BarcodeInfos != null && e.BarcodeInfos.Count > 0) |
| | | { |
| | | foreach (var info in e.BarcodeInfos) |
| | | { |
| | | uiListBoxBarcodes.Items.Add(info.Text); |
| | | } |
| | | } |
| | | |
| | | if (e.Image != null) |
| | | { |
| | | // å建å¾å坿¬è¿è¡ç»å¶ |
| | | Bitmap drawImg = new Bitmap(e.Image); |
| | | using (Graphics g = Graphics.FromImage(drawImg)) |
| | | { |
| | | g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; |
| | | using (Pen pen = new Pen(Color.LimeGreen, 3)) |
| | | using (SolidBrush brush = new SolidBrush(Color.LimeGreen)) |
| | | using (Font font = new Font("Arial", 16, FontStyle.Bold)) |
| | | { |
| | | foreach (var info in e.BarcodeInfos) |
| | | { |
| | | if (info.Points != null && info.Points.Length >= 4) |
| | | { |
| | | // ç»å¶æ¡çº¿ |
| | | g.DrawPolygon(pen, info.Points); |
| | | // ç»å¶ææ¬ |
| | | Point textPos = info.Points[0]; |
| | | textPos.Y -= 25; |
| | | g.DrawString(info.Text, font, brush, textPos); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // éæ¾æ§å¾å |
| | | var oldImg = pictureBox1.Image; |
| | | pictureBox1.Image = drawImg; |
| | | oldImg?.Dispose(); |
| | | } |
| | | |
| | | uiTextBoxResult.Text = $"读åå°{e.BarcodeInfos.Count}个æ¡ç "; |
| | | } |
| | | |
| | | private void uiRadioButtonSoftTrigger_CheckedChanged(object sender, EventArgs e) |
| | | { |
| | | uiButtonSoftTrigger.Enabled = uiRadioButtonSoftTrigger.Checked; |
| | | |
| | | if (barcodeReader == null) |
| | | return; |
| | | |
| | | barcodeReader.SetTriggerMode(uiRadioButtonSoftTrigger.Checked); |
| | | } |
| | | |
| | | private void uiButtonStartGrabbing_Click(object sender, EventArgs e) |
| | | { |
| | | if (barcodeReader == null) |
| | | return; |
| | | |
| | | if (barcodeReader.StartGrabbing()) |
| | | { |
| | | uiButtonStartGrabbing.Enabled = false; |
| | | uiButtonStopGrabbing.Enabled = true; |
| | | } |
| | | } |
| | | |
| | | private void uiButtonStopGrabbing_Click(object sender, EventArgs e) |
| | | { |
| | | if (barcodeReader == null) |
| | | return; |
| | | |
| | | if (barcodeReader.StopGrabbing()) |
| | | { |
| | | uiButtonStartGrabbing.Enabled = true; |
| | | uiButtonStopGrabbing.Enabled = false; |
| | | } |
| | | } |
| | | |
| | | private void uiButtonSoftTrigger_Click(object sender, EventArgs e) |
| | | { |
| | | if (barcodeReader == null) |
| | | return; |
| | | |
| | | barcodeReader.SoftTrigger(); |
| | | } |
| | | |
| | | private void uiButtonClear_Click(object sender, EventArgs e) |
| | | { |
| | | uiListBoxBarcodes.Items.Clear(); |
| | | uiTextBoxResult.Text = ""; |
| | | if (pictureBox1 != null) |
| | | pictureBox1.Image = null; |
| | | } |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using ReaLTaiizor.Controls; |
| | | using System.Drawing; |
| | | using System.Windows.Forms; |
| | | |
| | | namespace LB_SmartVision.Forms.Pages.BarcodeReaderPage |
| | | { |
| | | partial class BarcodeReadersEditPage |
| | | { |
| | | /// <summary> |
| | | /// Required designer variable. |
| | | /// </summary> |
| | | private System.ComponentModel.IContainer components = null; |
| | | |
| | | /// <summary> |
| | | /// Clean up any resources being used. |
| | | /// </summary> |
| | | /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
| | | protected override void Dispose(bool disposing) |
| | | { |
| | | if (disposing && (components != null)) |
| | | { |
| | | components.Dispose(); |
| | | } |
| | | base.Dispose(disposing); |
| | | } |
| | | |
| | | #region Component Designer generated code |
| | | |
| | | /// <summary> |
| | | /// Required method for Designer support - do not modify |
| | | /// the contents of this method with the code editor. |
| | | /// </summary> |
| | | private void InitializeComponent() |
| | | { |
| | | uiButton1 = new HopeButton(); |
| | | uiButton2 = new LostButton(); |
| | | uiFlowLayoutPanel1 = new FlowLayoutPanel(); |
| | | tableLayoutPanel1 = new TableLayoutPanel(); |
| | | tableLayoutPanel2 = new TableLayoutPanel(); |
| | | tableLayoutPanel1.SuspendLayout(); |
| | | tableLayoutPanel2.SuspendLayout(); |
| | | SuspendLayout(); |
| | | // |
| | | // uiButton1 |
| | | // |
| | | uiButton1.BorderColor = Color.FromArgb(220, 223, 230); |
| | | uiButton1.ButtonType = ReaLTaiizor.Util.HopeButtonType.Primary; |
| | | uiButton1.Cursor = Cursors.Hand; |
| | | uiButton1.DangerColor = Color.FromArgb(245, 108, 108); |
| | | uiButton1.DefaultColor = Color.FromArgb(255, 255, 255); |
| | | uiButton1.Dock = DockStyle.Fill; |
| | | uiButton1.Font = new Font("å®ä½", 12F); |
| | | uiButton1.HoverTextColor = Color.FromArgb(48, 49, 51); |
| | | uiButton1.InfoColor = Color.FromArgb(144, 147, 153); |
| | | uiButton1.Location = new Point(503, 3); |
| | | uiButton1.MinimumSize = new Size(1, 1); |
| | | uiButton1.Name = "uiButton1"; |
| | | uiButton1.PrimaryColor = Color.FromArgb(64, 158, 255); |
| | | uiButton1.Size = new Size(95, 38); |
| | | uiButton1.SuccessColor = Color.FromArgb(103, 194, 58); |
| | | uiButton1.TabIndex = 11; |
| | | uiButton1.Text = "æ°å¢"; |
| | | uiButton1.TextColor = Color.White; |
| | | uiButton1.WarningColor = Color.FromArgb(230, 162, 60); |
| | | uiButton1.Click += uiButton1_Click; |
| | | // |
| | | // uiButton2 |
| | | // |
| | | uiButton2.BackColor = Color.FromArgb(39, 41, 60); |
| | | uiButton2.Cursor = Cursors.Hand; |
| | | uiButton2.Dock = DockStyle.Fill; |
| | | uiButton2.Font = new Font("å®ä½", 12F); |
| | | uiButton2.ForeColor = Color.White; |
| | | uiButton2.HoverColor = Color.DodgerBlue; |
| | | uiButton2.Image = null; |
| | | uiButton2.Location = new Point(403, 3); |
| | | uiButton2.MinimumSize = new Size(1, 1); |
| | | uiButton2.Name = "uiButton2"; |
| | | uiButton2.Size = new Size(94, 38); |
| | | uiButton2.TabIndex = 12; |
| | | uiButton2.Text = "å
¨é¨æ¸
é¤"; |
| | | uiButton2.Click += uiButton2_Click; |
| | | // |
| | | // uiFlowLayoutPanel1 |
| | | // |
| | | uiFlowLayoutPanel1.BackColor = Color.FromArgb(32, 41, 50); |
| | | uiFlowLayoutPanel1.Dock = DockStyle.Fill; |
| | | uiFlowLayoutPanel1.Font = new Font("å®ä½", 12F); |
| | | uiFlowLayoutPanel1.ForeColor = SystemColors.Control; |
| | | uiFlowLayoutPanel1.Location = new Point(4, 5); |
| | | uiFlowLayoutPanel1.Margin = new Padding(4, 5, 4, 5); |
| | | uiFlowLayoutPanel1.MinimumSize = new Size(1, 1); |
| | | uiFlowLayoutPanel1.Name = "uiFlowLayoutPanel1"; |
| | | uiFlowLayoutPanel1.Padding = new Padding(2); |
| | | uiFlowLayoutPanel1.Size = new Size(599, 293); |
| | | uiFlowLayoutPanel1.TabIndex = 10; |
| | | // |
| | | // tableLayoutPanel1 |
| | | // |
| | | tableLayoutPanel1.ColumnCount = 1; |
| | | tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); |
| | | tableLayoutPanel1.Controls.Add(uiFlowLayoutPanel1, 0, 0); |
| | | tableLayoutPanel1.Controls.Add(tableLayoutPanel2, 0, 1); |
| | | tableLayoutPanel1.Dock = DockStyle.Fill; |
| | | tableLayoutPanel1.Location = new Point(0, 0); |
| | | tableLayoutPanel1.Name = "tableLayoutPanel1"; |
| | | tableLayoutPanel1.RowCount = 2; |
| | | tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); |
| | | tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F)); |
| | | tableLayoutPanel1.Size = new Size(607, 353); |
| | | tableLayoutPanel1.TabIndex = 13; |
| | | // |
| | | // tableLayoutPanel2 |
| | | // |
| | | tableLayoutPanel2.ColumnCount = 6; |
| | | tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 16.666666F)); |
| | | tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 16.666666F)); |
| | | tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 16.666666F)); |
| | | tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 16.666666F)); |
| | | tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 16.666666F)); |
| | | tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 16.666666F)); |
| | | tableLayoutPanel2.Controls.Add(uiButton1, 5, 0); |
| | | tableLayoutPanel2.Controls.Add(uiButton2, 4, 0); |
| | | tableLayoutPanel2.Dock = DockStyle.Fill; |
| | | tableLayoutPanel2.Location = new Point(3, 306); |
| | | tableLayoutPanel2.Name = "tableLayoutPanel2"; |
| | | tableLayoutPanel2.RowCount = 1; |
| | | tableLayoutPanel2.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); |
| | | tableLayoutPanel2.Size = new Size(601, 44); |
| | | tableLayoutPanel2.TabIndex = 11; |
| | | // |
| | | // BarcodeReadersEditPage |
| | | // |
| | | BackColor = Color.FromArgb(32, 41, 50); |
| | | Controls.Add(tableLayoutPanel1); |
| | | Name = "BarcodeReadersEditPage"; |
| | | Size = new Size(607, 353); |
| | | Paint += BarcodeReadersEditPage_Paint; |
| | | tableLayoutPanel1.ResumeLayout(false); |
| | | tableLayoutPanel2.ResumeLayout(false); |
| | | ResumeLayout(false); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | private HopeButton uiButton1; |
| | | private LostButton uiButton2; |
| | | private FlowLayoutPanel uiFlowLayoutPanel1; |
| | | private TableLayoutPanel tableLayoutPanel1; |
| | | private TableLayoutPanel tableLayoutPanel2; |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using LB_VisionControl; |
| | | using LB_VisionProcesses.BarcodeReaders; |
| | | using LB_VisionProcesses.BarcodeReaders.Huayray; |
| | | using System; |
| | | using System.Collections.Concurrent; |
| | | using System.Windows.Forms; |
| | | |
| | | namespace LB_SmartVision.Forms.Pages.BarcodeReaderPage |
| | | { |
| | | public partial class BarcodeReadersEditPage : UserControl |
| | | { |
| | | public Action<string, LogInfoType> LogInfo; |
| | | |
| | | |
| | | public BarcodeReadersEditPage() |
| | | { |
| | | InitializeComponent(); |
| | | |
| | | Name = "BarcodeReadersEditPage"; |
| | | Text = "读ç å¨è®¾ç½®"; |
| | | } |
| | | |
| | | private void BarcodeReadersEditPage_Paint(object sender, PaintEventArgs e) |
| | | { |
| | | uiFlowLayoutPanel1.Controls.Clear(); |
| | | |
| | | if (GlobalVar.dicBarcodeReaders.Count <= 0) |
| | | return; |
| | | |
| | | foreach (var item in GlobalVar.dicBarcodeReaders) |
| | | { |
| | | string ReaderSN = item.Key; |
| | | string ReaderBrand = item.Value.Brand.ToString(); |
| | | |
| | | if (string.IsNullOrEmpty(ReaderSN) || string.IsNullOrEmpty(ReaderBrand)) |
| | | continue; |
| | | |
| | | UserItem flow = new UserItem(new string[] { "æµè¯", "å·æ°", "ç§»é¤" }); |
| | | flow.Name = ReaderSN; |
| | | flow.Text = $"[{ReaderBrand}] {ReaderSN}"; |
| | | if (item.Value.IsConnected) |
| | | flow.state = State.Pass; |
| | | else |
| | | flow.state = State.Error; |
| | | LoadFlowEvent(flow); |
| | | |
| | | uiFlowLayoutPanel1.Controls.Add(flow); |
| | | } |
| | | } |
| | | |
| | | |
| | | private void uiButton1_Click(object sender, System.EventArgs e) |
| | | { |
| | | CreateBarcodeReaderForm createForm = new CreateBarcodeReaderForm(); |
| | | createForm.ShowDialog(); |
| | | |
| | | if (createForm.bCreate) |
| | | { |
| | | BarcodeReaderBase reader = createForm.barcodeReader; |
| | | if (GlobalVar.dicBarcodeReaders.ContainsKey(reader.SN)) |
| | | { |
| | | MessageBox.Show($"读ç å¨[{reader.SN}]å·²åå¨!", "å¼å¸¸"); |
| | | return; |
| | | } |
| | | |
| | | string ReaderSN = reader.SN; |
| | | string ReaderBrand = reader.Brand.ToString(); |
| | | |
| | | if (string.IsNullOrEmpty(ReaderSN) || string.IsNullOrEmpty(ReaderBrand)) |
| | | return; |
| | | |
| | | GlobalVar.dicBarcodeReaders.TryAdd(ReaderSN, reader); |
| | | LogInfo?.Invoke(string.Format("æ·»å 读ç å¨[{0}][{1}]æå", ReaderBrand, ReaderSN), LogInfoType.PASS); |
| | | } |
| | | this.Invalidate(); |
| | | } |
| | | |
| | | private void uiButton2_Click(object sender, System.EventArgs e) |
| | | { |
| | | //æ¸
é¤ç¨Clearæ¹æ³ |
| | | uiFlowLayoutPanel1.Controls.Clear(); |
| | | foreach (var reader in GlobalVar.dicBarcodeReaders.Values) |
| | | { |
| | | reader.Dispose(); |
| | | } |
| | | GlobalVar.dicBarcodeReaders.Clear(); |
| | | } |
| | | |
| | | private void LoadFlowEvent(UserItem flow) |
| | | { |
| | | //æé®1为æµè¯ |
| | | flow.MenuItem1ClickedEvent += TestEvent; |
| | | //æé®2ä¸ºå·æ° |
| | | flow.MenuItem2ClickedEvent += ReconnectEvent; |
| | | //æé®3ä¸ºç§»é¤ |
| | | flow.MenuItem3ClickedEvent += DeleteEvent; |
| | | } |
| | | |
| | | private void RemoveFlowEvent(UserItem flow) |
| | | { |
| | | //æé®1为æµè¯ |
| | | flow.MenuItem1ClickedEvent -= TestEvent; |
| | | //æé®2ä¸ºå·æ° |
| | | flow.MenuItem2ClickedEvent -= ReconnectEvent; |
| | | //æé®3ä¸ºç§»é¤ |
| | | flow.MenuItem3ClickedEvent -= DeleteEvent; |
| | | } |
| | | |
| | | // æµè¯è¯»ç å¨ |
| | | private void TestEvent(string Name, string Text) |
| | | { |
| | | for (int i = 0; i < uiFlowLayoutPanel1.Controls.Count; i++) |
| | | { |
| | | UserItem flow = (UserItem)uiFlowLayoutPanel1.Controls[i]; |
| | | string name = flow.Name; |
| | | if (name != Name) |
| | | continue; |
| | | |
| | | if (GlobalVar.dicBarcodeReaders.ContainsKey(name)) |
| | | { |
| | | BarcodeReaderForm readerForm = new BarcodeReaderForm(GlobalVar.dicBarcodeReaders[name]); |
| | | readerForm.Show(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // ç§»é¤è¯»ç å¨ |
| | | private void DeleteEvent(string Name, string Text) |
| | | { |
| | | for (int i = 0; i < uiFlowLayoutPanel1.Controls.Count; i++) |
| | | { |
| | | UserItem flow = (UserItem)uiFlowLayoutPanel1.Controls[i]; |
| | | string name = flow.Name; |
| | | if (name != Name) |
| | | continue; |
| | | |
| | | RemoveFlowEvent(flow); |
| | | uiFlowLayoutPanel1.Controls.Remove(uiFlowLayoutPanel1.Controls[i]); |
| | | if (GlobalVar.dicBarcodeReaders.TryRemove(name, out BarcodeReaderBase barcodeReader)) |
| | | { |
| | | barcodeReader.Dispose(); |
| | | LogInfo?.Invoke(string.Format("ç§»é¤è¯»ç å¨[{0}]", name), LogInfoType.INFO); |
| | | } |
| | | else |
| | | LogInfo?.Invoke(string.Format("ç§»é¤è¯»ç å¨[{0}]失败", name), LogInfoType.ERROR); |
| | | |
| | | } |
| | | } |
| | | |
| | | // éè¿è¯»ç å¨ |
| | | private void ReconnectEvent(string Name, string Text) |
| | | { |
| | | for (int i = 0; i < uiFlowLayoutPanel1.Controls.Count; i++) |
| | | { |
| | | UserItem flow = (UserItem)uiFlowLayoutPanel1.Controls[i]; |
| | | string name = flow.Name; |
| | | if (name != Name) |
| | | continue; |
| | | |
| | | if (!GlobalVar.dicBarcodeReaders.ContainsKey(name)) |
| | | { |
| | | LogInfo?.Invoke(string.Format("读ç å¨[{0}]ä¸åå¨", name), LogInfoType.ERROR); |
| | | flow.state = State.Error; |
| | | flow.Refresh(); |
| | | return; |
| | | } |
| | | |
| | | var reader = GlobalVar.dicBarcodeReaders[name]; |
| | | if (reader == null) |
| | | { |
| | | LogInfo?.Invoke(string.Format("读ç å¨[{0}]å®ä¾ä¸ºç©º", name), LogInfoType.ERROR); |
| | | flow.state = State.Error; |
| | | flow.Refresh(); |
| | | return; |
| | | } |
| | | |
| | | try |
| | | { |
| | | // å
éæ¾æ§å®ä¾çèµæº |
| | | reader.Dispose(); |
| | | |
| | | // æ·»å çæå»¶è¿ï¼ç¡®ä¿SDKåºå±èµæºå®å
¨éæ¾ |
| | | System.Threading.Thread.Sleep(500); |
| | | |
| | | // 强å¶åå¾åæ¶ï¼ç¡®ä¿ç¸æºå¯¹è±¡è¢«å®å
¨éæ¾ |
| | | GC.Collect(); |
| | | GC.WaitForPendingFinalizers(); |
| | | GC.Collect(); |
| | | |
| | | // ä»åå
¸ä¸ç§»é¤æ§å®ä¾ |
| | | GlobalVar.dicBarcodeReaders.TryRemove(name, out _); |
| | | |
| | | // å建æ°å®ä¾ |
| | | BarcodeReaderBase newReader = null; |
| | | switch (reader.Brand) |
| | | { |
| | | case BarcodeReaderBrand.Huayray: |
| | | newReader = new HRBarcodeReader(); |
| | | break; |
| | | default: |
| | | throw new Exception($"䏿¯æç读ç å¨åç: {reader.Brand}"); |
| | | } |
| | | |
| | | if (newReader.Open(name)) |
| | | { |
| | | // æ·»å å°åå
¸ |
| | | GlobalVar.dicBarcodeReaders.TryAdd(name, newReader); |
| | | flow.state = State.Pass; |
| | | LogInfo?.Invoke(string.Format("éè¿è¯»ç å¨[{0}]æå", name), LogInfoType.PASS); |
| | | } |
| | | else |
| | | { |
| | | flow.state = State.Error; |
| | | LogInfo?.Invoke(string.Format("读ç å¨[{0}]éæ°å建åä»è¿æ¥å¤±è´¥", name), LogInfoType.ERROR); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | flow.state = State.Error; |
| | | LogInfo?.Invoke(string.Format("éè¿è¯»ç å¨[{0}]å¼å¸¸: {1}", name, ex.Message), LogInfoType.ERROR); |
| | | } |
| | | flow.Refresh(); |
| | | } |
| | | } |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using ReaLTaiizor.Controls; |
| | | using System.Drawing; |
| | | using System.Windows.Forms; |
| | | |
| | | namespace LB_SmartVision.Forms.Pages.BarcodeReaderPage |
| | | { |
| | | partial class CreateBarcodeReaderForm |
| | | { |
| | | /// <summary> |
| | | /// Required designer variable. |
| | | /// </summary> |
| | | private System.ComponentModel.IContainer components = null; |
| | | |
| | | /// <summary> |
| | | /// Clean up any resources being used. |
| | | /// </summary> |
| | | /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
| | | protected override void Dispose(bool disposing) |
| | | { |
| | | if (disposing && (components != null)) |
| | | { |
| | | components.Dispose(); |
| | | } |
| | | base.Dispose(disposing); |
| | | } |
| | | |
| | | #region Windows Form Designer generated code |
| | | |
| | | /// <summary> |
| | | /// Required method for Designer support - do not modify |
| | | /// the contents of this method with the code editor. |
| | | /// </summary> |
| | | private void InitializeComponent() |
| | | { |
| | | uiComboBoxBrand = new ComboBox(); |
| | | uiComboBoxSN = new ComboBox(); |
| | | uiLabel1 = new Label(); |
| | | uiLabel2 = new Label(); |
| | | uiButtonTest = new HopeButton(); |
| | | uiButtonCreate = new HopeButton(); |
| | | uiButtonCancel = new LostButton(); |
| | | SuspendLayout(); |
| | | // |
| | | // uiComboBoxBrand |
| | | // |
| | | uiComboBoxBrand.DropDownStyle = ComboBoxStyle.DropDownList; |
| | | uiComboBoxBrand.Font = new Font("å®ä½", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | uiComboBoxBrand.FormattingEnabled = true; |
| | | uiComboBoxBrand.Location = new Point(127, 30); |
| | | uiComboBoxBrand.Name = "uiComboBoxBrand"; |
| | | uiComboBoxBrand.Size = new Size(200, 28); |
| | | uiComboBoxBrand.TabIndex = 0; |
| | | uiComboBoxBrand.MouseClick += uiComboBoxBrand_MouseClick; |
| | | uiComboBoxBrand.SelectedIndexChanged += uiComboBoxBrand_SelectedIndexChanged; |
| | | // |
| | | // uiComboBoxSN |
| | | // |
| | | uiComboBoxSN.DropDownStyle = ComboBoxStyle.DropDownList; |
| | | uiComboBoxSN.Font = new Font("å®ä½", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | uiComboBoxSN.FormattingEnabled = true; |
| | | uiComboBoxSN.Location = new Point(127, 80); |
| | | uiComboBoxSN.Name = "uiComboBoxSN"; |
| | | uiComboBoxSN.Size = new Size(200, 28); |
| | | uiComboBoxSN.TabIndex = 1; |
| | | uiComboBoxSN.MouseClick += uiComboBoxSN_MouseClick; |
| | | // |
| | | // uiLabel1 |
| | | // |
| | | uiLabel1.Font = new Font("å®ä½", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | uiLabel1.ForeColor = Color.White; |
| | | uiLabel1.Location = new Point(25, 30); |
| | | uiLabel1.Name = "uiLabel1"; |
| | | uiLabel1.Size = new Size(100, 29); |
| | | uiLabel1.TabIndex = 2; |
| | | uiLabel1.Text = "åç:"; |
| | | uiLabel1.TextAlign = ContentAlignment.MiddleRight; |
| | | // |
| | | // uiLabel2 |
| | | // |
| | | uiLabel2.Font = new Font("å®ä½", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | uiLabel2.ForeColor = Color.White; |
| | | uiLabel2.Location = new Point(25, 80); |
| | | uiLabel2.Name = "uiLabel2"; |
| | | uiLabel2.Size = new Size(100, 29); |
| | | uiLabel2.TabIndex = 3; |
| | | uiLabel2.Text = "åºåå·:"; |
| | | uiLabel2.TextAlign = ContentAlignment.MiddleRight; |
| | | // |
| | | // uiButtonTest |
| | | // |
| | | uiButtonTest.BorderColor = Color.FromArgb(220, 223, 230); |
| | | uiButtonTest.ButtonType = ReaLTaiizor.Util.HopeButtonType.Primary; |
| | | uiButtonTest.Cursor = Cursors.Hand; |
| | | uiButtonTest.DangerColor = Color.FromArgb(245, 108, 108); |
| | | uiButtonTest.DefaultColor = Color.FromArgb(255, 255, 255); |
| | | uiButtonTest.Font = new Font("å®ä½", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | uiButtonTest.HoverTextColor = Color.FromArgb(48, 49, 51); |
| | | uiButtonTest.InfoColor = Color.FromArgb(144, 147, 153); |
| | | uiButtonTest.Location = new Point(350, 52); |
| | | uiButtonTest.MinimumSize = new Size(1, 1); |
| | | uiButtonTest.Name = "uiButtonTest"; |
| | | uiButtonTest.PrimaryColor = Color.FromArgb(64, 158, 255); |
| | | uiButtonTest.Size = new Size(100, 35); |
| | | uiButtonTest.SuccessColor = Color.FromArgb(103, 194, 58); |
| | | uiButtonTest.TabIndex = 4; |
| | | uiButtonTest.Text = "æµè¯è¿æ¥"; |
| | | uiButtonTest.TextColor = Color.White; |
| | | uiButtonTest.WarningColor = Color.FromArgb(230, 162, 60); |
| | | uiButtonTest.Click += uiButtonTest_Click; |
| | | // |
| | | // uiButtonCreate |
| | | // |
| | | uiButtonCreate.BorderColor = Color.FromArgb(220, 223, 230); |
| | | uiButtonCreate.ButtonType = ReaLTaiizor.Util.HopeButtonType.Primary; |
| | | uiButtonCreate.Cursor = Cursors.Hand; |
| | | uiButtonCreate.DangerColor = Color.FromArgb(245, 108, 108); |
| | | uiButtonCreate.DefaultColor = Color.FromArgb(255, 255, 255); |
| | | uiButtonCreate.Font = new Font("å®ä½", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | uiButtonCreate.HoverTextColor = Color.FromArgb(48, 49, 51); |
| | | uiButtonCreate.InfoColor = Color.FromArgb(144, 147, 153); |
| | | uiButtonCreate.Location = new Point(127, 140); |
| | | uiButtonCreate.MinimumSize = new Size(1, 1); |
| | | uiButtonCreate.Name = "uiButtonCreate"; |
| | | uiButtonCreate.PrimaryColor = Color.FromArgb(0, 150, 136); |
| | | uiButtonCreate.Size = new Size(100, 35); |
| | | uiButtonCreate.SuccessColor = Color.FromArgb(103, 194, 58); |
| | | uiButtonCreate.TabIndex = 5; |
| | | uiButtonCreate.Text = "å建"; |
| | | uiButtonCreate.TextColor = Color.White; |
| | | uiButtonCreate.WarningColor = Color.FromArgb(230, 162, 60); |
| | | uiButtonCreate.Click += uiButtonCreate_Click; |
| | | // |
| | | // uiButtonCancel |
| | | // |
| | | uiButtonCancel.BackColor = Color.FromArgb(39, 41, 60); |
| | | uiButtonCancel.Cursor = Cursors.Hand; |
| | | uiButtonCancel.Font = new Font("å®ä½", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | uiButtonCancel.ForeColor = Color.White; |
| | | uiButtonCancel.HoverColor = Color.DodgerBlue; |
| | | uiButtonCancel.Image = null; |
| | | uiButtonCancel.Location = new Point(245, 140); |
| | | uiButtonCancel.MinimumSize = new Size(1, 1); |
| | | uiButtonCancel.Name = "uiButtonCancel"; |
| | | uiButtonCancel.Size = new Size(100, 35); |
| | | uiButtonCancel.TabIndex = 6; |
| | | uiButtonCancel.Text = "åæ¶"; |
| | | uiButtonCancel.Click += uiButtonCancel_Click; |
| | | // |
| | | // CreateBarcodeReaderForm |
| | | // |
| | | AutoScaleDimensions = new SizeF(7F, 17F); |
| | | AutoScaleMode = AutoScaleMode.Font; |
| | | BackColor = Color.FromArgb(32, 41, 50); |
| | | ClientSize = new Size(484, 211); |
| | | Controls.Add(uiButtonCancel); |
| | | Controls.Add(uiButtonCreate); |
| | | Controls.Add(uiButtonTest); |
| | | Controls.Add(uiLabel2); |
| | | Controls.Add(uiLabel1); |
| | | Controls.Add(uiComboBoxSN); |
| | | Controls.Add(uiComboBoxBrand); |
| | | Name = "CreateBarcodeReaderForm"; |
| | | StartPosition = FormStartPosition.CenterParent; |
| | | Text = "æ·»å 读ç å¨"; |
| | | ResumeLayout(false); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | private ComboBox uiComboBoxBrand; |
| | | private ComboBox uiComboBoxSN; |
| | | private Label uiLabel1; |
| | | private Label uiLabel2; |
| | | private HopeButton uiButtonTest; |
| | | private HopeButton uiButtonCreate; |
| | | private LostButton uiButtonCancel; |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | 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<BarcodeReaderBrand>(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); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | #endregion |
| | | |
| | | #region 读ç å¨ |
| | | public static ConcurrentDictionary<string, string> allBarcodeReadersConnectionString = new ConcurrentDictionary<string, string>(); |
| | | public static string allBarcodeReadersConnectionStringPath |
| | | => GlobalVar.strApplicationPath + "\\ææäº§å\\" + GlobalVar.strProductName + "\\A_BarcodeReaderConnections.json"; |
| | | |
| | | #endregion |
| | | |
| | | #region æµç¨ |
| | | public static Dictionary<string, object> ControlStates { get; set; } = new Dictionary<string, object>(); |
| | | |
| | |
| | | using HalconDotNet; |
| | | using LB_SmartVision.Forms; |
| | | using LB_SmartVision.Forms.Pages; |
| | | using LB_SmartVision.Forms.Pages.BarcodeReaderPage; |
| | | using LB_SmartVision.Forms.Pages.CameraPage; |
| | | using LB_SmartVision.Forms.Pages.CommunicatorPage; |
| | | using LB_SmartVision.Forms.Pages.HistoricalData; |
| | |
| | | using LB_VisionProcesses.Cameras; |
| | | using LB_VisionProcesses.Cameras.HRCameras; |
| | | using LB_VisionProcesses.Cameras.LBCameras; |
| | | using LB_VisionProcesses.BarcodeReaders; |
| | | using LB_VisionProcesses.BarcodeReaders.Huayray; |
| | | using LB_VisionProcesses.Communicators; |
| | | using LB_VisionProcesses.Communicators.SiemensS7; |
| | | using LB_VisionProcesses.Communicators.TCom; |
| | |
| | | { |
| | | AllProcessesPage AllProcessesPages = new AllProcessesPage(); |
| | | CamerasEditPage CamerasEditPage = new CamerasEditPage(); |
| | | BarcodeReadersEditPage BarcodeReadersEditPage = new BarcodeReadersEditPage(); |
| | | HistoricalDataEditPage HistoricalDataEditPage = new HistoricalDataEditPage(); |
| | | CommunicatorsEditPage CommunicatorsEditPage = new CommunicatorsEditPage(); |
| | | SettingEditPage SettingEditPage = new SettingEditPage(); |
| | |
| | | |
| | | GlobalVar.dicCommunicators.DictionaryChanged += CommunicatorsChanged; |
| | | GlobalVar.dicCameras.DictionaryChanged += CamerasChanged; |
| | | GlobalVar.dicBarcodeReaders.DictionaryChanged += BarcodeReadersChanged; |
| | | GlobalVar.dicProcesses.DictionaryChanged += ProcessRunBllChanged; |
| | | |
| | | //æå¼å§å°±æ¸
空ææTab页 |
| | |
| | | |
| | | CamerasEditPage.LogInfo += LogInfo; |
| | | materialTabControl.Controls.Add(new MyPage(CamerasEditPage)); |
| | | |
| | | BarcodeReadersEditPage.LogInfo += LogInfo; |
| | | materialTabControl.Controls.Add(new MyPage(BarcodeReadersEditPage)); |
| | | |
| | | CommunicatorsEditPage.LogInfo += LogInfo; |
| | | materialTabControl.Controls.Add(new MyPage(CommunicatorsEditPage)); |
| | |
| | | catch { } |
| | | } |
| | | |
| | | private void BarcodeReadersChanged(object sender, DictionaryChangedEventArgs<string, BarcodeReaderBase> e) |
| | | { |
| | | try |
| | | { |
| | | switch (e.ChangeType) |
| | | { |
| | | case DictionaryChangeType.Added: |
| | | LogInfo($"读ç å¨[{e.NewValue.SN}]å è½½æå", LogInfoType.INFO); |
| | | e.NewValue.SN = e.NewKey; |
| | | break; |
| | | case DictionaryChangeType.Removed: |
| | | if (e.OldValue != null) |
| | | e.OldValue.Dispose(); |
| | | LogInfo($"读ç å¨[{e.OldValue.SN}]已移é¤", LogInfoType.INFO); |
| | | break; |
| | | } |
| | | } |
| | | catch { } |
| | | } |
| | | |
| | | private void VisionForm_Load(object sender, EventArgs e) |
| | | { |
| | | XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config")); |
| | |
| | | else |
| | | { |
| | | LogInfo("ç¸æºå 载失败", LogInfoType.ERROR); |
| | | } |
| | | |
| | | //å 载读ç å¨ |
| | | foreach (var reader in GlobalVar.dicBarcodeReaders.Values) |
| | | { |
| | | reader.Dispose(); |
| | | } |
| | | GlobalVar.dicBarcodeReaders.Clear(); |
| | | if (LoadAllBarcodeReaders(GlobalVar.allBarcodeReadersConnectionStringPath)) |
| | | { |
| | | LogInfo("读ç å¨å è½½æå", LogInfoType.PASS); |
| | | } |
| | | else |
| | | { |
| | | LogInfo("读ç å¨å 载失败", LogInfoType.ERROR); |
| | | } |
| | | //å è½½å
¨å±åé |
| | | IProcess.dicGlobalVars.Clear(); |
| | |
| | | SaveAllProcessVars(); |
| | | SaveAllCommunicators(); |
| | | SaveAllCameras(); |
| | | SaveAllBarcodeReaders(); |
| | | SaveAllProcessSetting(); |
| | | SaveAllLayout(); |
| | | SaveAllCsv(); |
| | |
| | | catch { return false; } |
| | | } |
| | | |
| | | public bool LoadAllBarcodeReaders(string allBarcodeReadersConnectionStringPath) |
| | | { |
| | | if (!File.Exists(allBarcodeReadersConnectionStringPath)) |
| | | { |
| | | Debug.WriteLine("读ç å¨é
ç½®æä»¶ä¸åå¨ï¼å建空æä»¶"); |
| | | SaveAllBarcodeReaders(); |
| | | return true; |
| | | } |
| | | string strJson = string.Empty; |
| | | using (StreamReader streamReader = new StreamReader(allBarcodeReadersConnectionStringPath, Encoding.UTF8)) |
| | | { |
| | | strJson = streamReader.ReadToEnd(); |
| | | streamReader.Close(); |
| | | } |
| | | GlobalVar.allBarcodeReadersConnectionString = JsonConvert.DeserializeObject<ConcurrentDictionary<string, string>>(strJson); |
| | | if (GlobalVar.allBarcodeReadersConnectionString == null) |
| | | { |
| | | MessageBox.Show("读ç å¨å 载失败!", "å¼å¸¸"); |
| | | return false; |
| | | } |
| | | BarcodeReaderBase reader = null; |
| | | foreach (var ReaderConnectionString in GlobalVar.allBarcodeReadersConnectionString) |
| | | { |
| | | Enum.TryParse<BarcodeReaderBrand>(ReaderConnectionString.Value, out BarcodeReaderBrand brand); |
| | | switch (brand) |
| | | { |
| | | case BarcodeReaderBrand.Huayray: |
| | | { |
| | | reader = new HRBarcodeReader(); |
| | | break; |
| | | } |
| | | default: |
| | | { |
| | | MessageBox.Show($"[{ReaderConnectionString.Key}]读ç å¨åç䏿¯æ!", "å¼å¸¸"); |
| | | continue; |
| | | } |
| | | } |
| | | reader.SN = ReaderConnectionString.Key; |
| | | if (!reader.Open(ReaderConnectionString.Key)) |
| | | { |
| | | LogInfo($"åå§å读ç å¨[{ReaderConnectionString.Key}]失败", LogInfoType.ERROR); |
| | | reader.IsConnected = false; |
| | | reader.IsGrabbing = false; |
| | | } |
| | | else |
| | | { |
| | | LogInfo($"åå§å读ç å¨[{ReaderConnectionString.Key}]æå", LogInfoType.PASS); |
| | | } |
| | | |
| | | GlobalVar.dicBarcodeReaders.TryAdd(ReaderConnectionString.Key, reader); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | public bool SaveAllBarcodeReaders() |
| | | { |
| | | try |
| | | { |
| | | string strJson = string.Empty; |
| | | GlobalVar.allBarcodeReadersConnectionString = new ConcurrentDictionary<string, string>(); |
| | | |
| | | foreach (var item in GlobalVar.dicBarcodeReaders) |
| | | { |
| | | string ReaderSN = item.Value.SN; |
| | | string ReaderBrand = item.Value.Brand.ToString(); |
| | | |
| | | if (string.IsNullOrEmpty(ReaderSN) || string.IsNullOrEmpty(ReaderBrand)) |
| | | { |
| | | break; |
| | | } |
| | | GlobalVar.allBarcodeReadersConnectionString.TryAdd(ReaderSN, ReaderBrand); |
| | | } |
| | | var settings = new JsonSerializerSettings |
| | | { |
| | | Formatting = Formatting.Indented, |
| | | ContractResolver = new DefaultContractResolver |
| | | { |
| | | NamingStrategy = new CamelCaseNamingStrategy() |
| | | } |
| | | }; |
| | | |
| | | strJson = JsonConvert.SerializeObject(GlobalVar.allBarcodeReadersConnectionString, settings); |
| | | string directoryPath = Path.GetDirectoryName(GlobalVar.allBarcodeReadersConnectionStringPath); |
| | | if (!Directory.Exists(directoryPath)) |
| | | { |
| | | try |
| | | { |
| | | Directory.CreateDirectory(directoryPath); |
| | | } |
| | | catch (Exception) |
| | | { } |
| | | } |
| | | File.WriteAllText(GlobalVar.allBarcodeReadersConnectionStringPath, strJson, Encoding.UTF8); |
| | | return true; |
| | | } |
| | | catch { return false; } |
| | | } |
| | | |
| | | |
| | | public bool LoadAllCommunicators(string allCommunicatorsConnectionStringPath) |
| | | { |
| | |
| | | { |
| | | public virtual event EventHandler<BarcodeEventArgs> BarcodeRead; |
| | | |
| | | public virtual string SN { get; protected set; } = string.Empty; |
| | | public virtual string SN { get; set; } = string.Empty; |
| | | |
| | | public virtual bool IsConnected { get; protected set; } = false; |
| | | public virtual bool IsConnected { get; set; } = false; |
| | | |
| | | public virtual bool IsGrabbing { get; protected set; } = false; |
| | | public virtual bool IsGrabbing { get; set; } = false; |
| | | |
| | | public abstract BarcodeReaderBrand Brand { get; } |
| | | |
| | |
| | | { |
| | | Close(); |
| | | } |
| | | IsConnected = false; |
| | | IsGrabbing = false; |
| | | } |
| | | catch { } |
| | | } |
| | |
| | | InitializeComponent(); |
| | | } |
| | | |
| | | public BarcodeReaderForm(IBarcodeReader reader) |
| | | { |
| | | InitializeComponent(); |
| | | _reader = reader; |
| | | _reader.BarcodeRead += Reader_BarcodeRead; |
| | | _currentSN = _reader.IsConnected ? "设å¤å·²å¨çº¿" : ""; |
| | | |
| | | // 忥 UI ç¶æ |
| | | cmbBrand.Text = _reader.Brand.ToString(); |
| | | cmbSN.Text = _reader.IsConnected ? "å¨çº¿è®¾å¤" : ""; |
| | | } |
| | | |
| | | public BarcodeReaderForm(LB_VisionProcesses.Processes.BarcodeReaderProcess process, string processPath) |
| | | { |
| | | InitializeComponent(); |
| | |
| | | { |
| | | // æ´æ°ç»æå表 |
| | | lstBarcodes.Items.Clear(); |
| | | if (e.Barcodes != null && e.Barcodes.Count > 0) |
| | | if (e.BarcodeInfos != null && e.BarcodeInfos.Count > 0) |
| | | { |
| | | foreach (var code in e.Barcodes) |
| | | foreach (var info in e.BarcodeInfos) |
| | | { |
| | | lstBarcodes.Items.Add($"{DateTime.Now:HH:mm:ss} - {code}"); |
| | | lstBarcodes.Items.Add($"{DateTime.Now:HH:mm:ss} - {info.Text}"); |
| | | } |
| | | } |
| | | else |
| | |
| | | lstBarcodes.Items.Add($"{DateTime.Now:HH:mm:ss} - æªè¯»å°æ¡ç "); |
| | | } |
| | | |
| | | // æ´æ°é¢è§å¾å |
| | | // æ´æ°é¢è§å¾åå¹¶ç»å¶æ 注 |
| | | if (e.Image != null) |
| | | { |
| | | // å建æ°ä½å¾ç¨äºç»å¾ï¼ä¸ç´æ¥ä¿®æ¹ SDK ä¼ å
¥çåå¾ |
| | | Bitmap drawImg = new Bitmap(e.Image); |
| | | using (Graphics g = Graphics.FromImage(drawImg)) |
| | | { |
| | | // 设置ç»å¾è´¨é |
| | | g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; |
| | | |
| | | using (Pen pen = new Pen(Color.LimeGreen, 3)) |
| | | using (SolidBrush brush = new SolidBrush(Color.LimeGreen)) |
| | | using (Font font = new Font("Arial", 16, FontStyle.Bold)) |
| | | { |
| | | foreach (var info in e.BarcodeInfos) |
| | | { |
| | | if (info.Points != null && info.Points.Length >= 4) |
| | | { |
| | | // ç»å¶åè¾¹å½¢æ¡ |
| | | g.DrawPolygon(pen, info.Points); |
| | | |
| | | // å¨ç¬¬ä¸ä¸ªç¹ä¸æ¹ç»å¶æ¡ç å
容 |
| | | // 计ç®ç»å¶ææ¬çä½ç½®ï¼ç¨å¾®åç§»ä¸ç¹é²æ¢è¦çè¾¹æ¡ï¼ |
| | | Point textPos = info.Points[0]; |
| | | textPos.Y -= 25; |
| | | g.DrawString(info.Text, font, brush, textPos); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // éæ¾æ§å¾åï¼é²æ¢å
åæ³æ¼ |
| | | var oldImg = picPreview.Image; |
| | | picPreview.Image = new Bitmap(e.Image); // æ·è´ä¸ä»½é²æ¢è¢« SDK å
é¨éæ¾ |
| | | picPreview.Image = drawImg; |
| | | oldImg?.Dispose(); |
| | | } |
| | | } |
| | |
| | | |
| | | try |
| | | { |
| | | // å
è¿è¡ä¸æ¬¡æä¸¾ï¼ç¡®ä¿ SDK è½å¤åç°è®¾å¤ï¼é¨å SDK è¦æ±å¨æå¼åå¿
é¡»æ§è¡æä¸¾ï¼ |
| | | GetDeviceList(); |
| | | |
| | | // 妿ä¹å失败è¿ï¼éæ°åå»ºç¸æºå¯¹è±¡ç¡®ä¿å¹²åç¶æ |
| | | if (_camera == null) |
| | | { |
| | | _camera = new EidCamera(); |
| | | } |
| | | |
| | | // ç¡®ä¿ä¹åç奿已鿾 |
| | | try { _camera.eidReleaseHandle_Net(); } catch { } |
| | | |
| | | // åå»ºå¥æ |
| | | int nRet = _camera.eidCreateDevice_Net(sn, EidCamera.EidDeviceDataType.eidDeviceDataTypeSN); |
| | | if (nRet != EidCamera.eidErrorOK) return false; |
| | | if (nRet != EidCamera.eidErrorOK) |
| | | { |
| | | _camera = null; |
| | | return false; |
| | | } |
| | | |
| | | // åé
åºå®å¥æç»å§æï¼é²æ¢è¢« GC åæ¶ |
| | | if (!_callbackHandle.IsAllocated) |
| | | { |
| | | _callbackHandle = GCHandle.Alloc(_frameCallback); |
| | | } |
| | | |
| | | // æå¼è®¾å¤ |
| | | nRet = _camera.eidOpenDevice_Net(); |
| | | if (nRet != EidCamera.eidErrorOK) |
| | | { |
| | | _camera.eidReleaseHandle_Net(); |
| | | if (_callbackHandle.IsAllocated) _callbackHandle.Free(); |
| | | _camera = null; |
| | | return false; |
| | | } |
| | | |
| | |
| | | { |
| | | _camera.eidCloseDevice_Net(); |
| | | _camera.eidReleaseHandle_Net(); |
| | | if (_callbackHandle.IsAllocated) _callbackHandle.Free(); |
| | | _camera = null; |
| | | return false; |
| | | } |
| | | |
| | |
| | | } |
| | | catch |
| | | { |
| | | // åçå¼å¸¸æ¶ç¡®ä¿éæ¾èµæº |
| | | try { _camera?.eidCloseDevice_Net(); } catch { } |
| | | try { _camera?.eidReleaseHandle_Net(); } catch { } |
| | | if (_callbackHandle.IsAllocated) _callbackHandle.Free(); |
| | | // åçå¼å¸¸æ¶éæ¾ç¸æºå¯¹è±¡ï¼ç¡®ä¿ä¸æ¬¡å建æ°å®ä¾ |
| | | _camera = null; |
| | | return false; |
| | | } |
| | | } |
| | |
| | | |
| | | try |
| | | { |
| | | StopGrabbing(); |
| | | if (IsConnected) |
| | | { |
| | | StopGrabbing(); |
| | | _camera.eidCloseDevice_Net(); |
| | | _camera.eidReleaseHandle_Net(); |
| | | _camera?.eidCloseDevice_Net(); |
| | | } |
| | | // æ 论æ¯å¦è¿æ¥ï¼é½å°è¯éæ¾å¥æ |
| | | _camera?.eidReleaseHandle_Net(); |
| | | |
| | | // éæ¾åè°å¥æ |
| | | if (_callbackHandle.IsAllocated) |
| | | { |
| | | _callbackHandle.Free(); |
| | | } |
| | | |
| | | // éæ¾ç¸æºå¯¹è±¡å¼ç¨ï¼ç¡®ä¿SDKèµæºå®å
¨éæ¾ |
| | | _camera = null; |
| | | |
| | | this.IsConnected = false; |
| | | this.SN = string.Empty; |
| | | this.IsGrabbing = false; |
| | | return true; |
| | | } |
| | | catch |
| | |
| | | try |
| | | { |
| | | List<string> barcodes = new List<string>(); |
| | | List<BarcodeInfo> barcodeInfos = new List<BarcodeInfo>(); |
| | | // è§£ææ¡ç |
| | | for (int i = 0; i < frameInfo.codeNum; i++) |
| | | { |
| | |
| | | if (!string.IsNullOrEmpty(data)) |
| | | { |
| | | barcodes.Add(data); |
| | | BarcodeInfo info = new BarcodeInfo |
| | | { |
| | | Text = data, |
| | | Points = new Point[] |
| | | { |
| | | new Point((int)codeInfo.position[0].x, (int)codeInfo.position[0].y), |
| | | new Point((int)codeInfo.position[1].x, (int)codeInfo.position[1].y), |
| | | new Point((int)codeInfo.position[2].x, (int)codeInfo.position[2].y), |
| | | new Point((int)codeInfo.position[3].x, (int)codeInfo.position[3].y) |
| | | } |
| | | }; |
| | | barcodeInfos.Add(info); |
| | | } |
| | | } |
| | | |
| | | // 转æ¢å¾å (妿éè¦) |
| | | // 转æ¢å¾å |
| | | Bitmap bitmap = null; |
| | | if (frameInfo.imageDataLen > 0 && frameInfo.imageData != IntPtr.Zero) |
| | | { |
| | |
| | | |
| | | // 触åäºä»¶ |
| | | OnBarcodeRead(new BarcodeEventArgs(this.SN, barcodes, bitmap)); |
| | | OnBarcodeRead(new BarcodeEventArgs(this.SN, barcodeInfos, bitmap)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¡ç 详ç»ä¿¡æ¯ |
| | | /// </summary> |
| | | public class BarcodeInfo |
| | | { |
| | | public string Text { get; set; } |
| | | /// <summary> |
| | | /// æ¡ç çå个顶ç¹åæ |
| | | /// </summary> |
| | | public Point[] Points { get; set; } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读ç ç»æåæ°ç±» |
| | | /// </summary> |
| | | public class BarcodeEventArgs : EventArgs |
| | |
| | | public string SN { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 读ç ç»æå
容 |
| | | /// æ¡ç 详ç»ä¿¡æ¯å表 |
| | | /// </summary> |
| | | public List<string> Barcodes { get; set; } = new List<string>(); |
| | | public List<BarcodeInfo> BarcodeInfos { get; set; } = new List<BarcodeInfo>(); |
| | | |
| | | /// <summary> |
| | | /// ä»
è·åæ¡ç ææ¬å表 (ä¿æå
¼å®¹æ§) |
| | | /// </summary> |
| | | public List<string> Barcodes => BarcodeInfos.Select(x => x.Text).ToList(); |
| | | |
| | | /// <summary> |
| | | /// å
³èå¾å (å¯é) |
| | |
| | | /// <summary> |
| | | /// æ¯å¦è¯»åæå |
| | | /// </summary> |
| | | public bool IsSuccess => Barcodes.Count > 0; |
| | | public bool IsSuccess => BarcodeInfos.Count > 0; |
| | | |
| | | public BarcodeEventArgs(string sn, List<string> barcodes, Bitmap image = null) |
| | | public BarcodeEventArgs(string sn, List<BarcodeInfo> barcodeInfos, Bitmap image = null) |
| | | { |
| | | SN = sn; |
| | | Barcodes = barcodes; |
| | | BarcodeInfos = barcodeInfos; |
| | | Image = image; |
| | | } |
| | | } |