FrmCamera.cs 4.0 KB
 
using HalconDotNet;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; 

namespace OnlineStore.ACSingleStore
{
    public partial class FrmCamera : FrmBase
    {
        private AC_SA_BoxBean store = null;
        public FrmCamera(AC_SA_BoxBean store)
        {
            this.store = store;
            InitializeComponent();
        }

        private void btnOpen_Click(object sender, EventArgs e)
        { 
            HDevelopExport.CloseAllCamera();
            store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH); 

            HDevelopExport.OpenAllCamera();
            FormStatus(true);
        }
        private void FormStatus(bool open)
        {
            btnOpen.Enabled = !open;
            btnCloseCamera.Enabled = open;
            btnGetImage.Enabled = open;
            timer1.Enabled = open; 
        }
        private void btnGetImage_Click(object sender, EventArgs e)
        {
            List<string> allCodeList = new List<string>();
            foreach (string cameraName in HDevelopExport.cameraNameList)
            {
                HObject ho_Image = HDevelopExport.GrabImage(cameraName);
                List<string> codeList = HDevelopExport.GetCode(ho_Image);
                allCodeList.AddRange(codeList);
            }
            if (allCodeList != null)
            {

                this.richTextBox1.Clear();
                foreach (string str in allCodeList)
                {
                    this.richTextBox1.AppendText(str);
                }
            }
        }
        private void btnCloseCamera_Click(object sender, EventArgs e)
        {
            store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);

            HDevelopExport.CloseAllCamera();
            FormStatus(false);
        }

        private void FrmCamera_Load(object sender, EventArgs e)
        {
            
            FormStatus(false);
        }

        private void FrmCamera_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (btnCloseCamera.Enabled.Equals(true))
            {
                store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
                HDevelopExport.CloseAllCamera();
                FormStatus(false);
            }
        }
        private int preIndex = 0;
        int dWidth = 0; int dHeight = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            preIndex++;
            HObject ho_Image = null;
            int index = preIndex % HDevelopExport.cameraNameList.Count;
            ho_Image = HDevelopExport.GrabImage(HDevelopExport.cameraNameList[index]);

            if (ho_Image != null)
            {
                if (dWidth <= 0)
                {
                    HTuple width, height;
                    //int dWidth = 0; int dHeight = 0;
                    HOperatorSet.GetImageSize(ho_Image, out width, out height);

                    dWidth = (int)width.D;
                    dHeight = (int)height.D;
                    hWindowControl1.HalconWindow.SetPart(0, 0, dHeight, dWidth);
                }

                HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow);

                List<string> codeList = HDevelopExport.GetCode(ho_Image);
                if (codeList != null)
                {
                    this.richTextBox1.Clear();
                    this.richTextBox1.AppendText(DateTime.Now.ToString()+ "读到二维码:" + "\r\n");
                    LogUtil.info("读取到的二维码列表" + "\r\n");
                    foreach (string str in codeList)
                    {
                        this.richTextBox1.AppendText(str + "\r\n");
                        LogUtil.info(str + "\r\n");
                    }
                }
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
         
    }
}