FrmCamera.cs 4.5 KB
using HalconDotNet;
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.KTKSingleStore
{
    public partial class FrmCamera : FrmBase
    {
        public FrmCamera()
        {
            InitializeComponent();
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            string text = cmbCamera.Text;
            HDevelopExport.CloseAllCamera();
            if (SAStoreManager.store != null)
            {
                SAStoreManager.store.KNDIOMove(Store_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)
        {
            //HObject ho_Image = HDevelopExport.GrabImage();

            //if (ho_Image != null)
            //{
            //    HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow);

            //    string[] codeList = HDevelopExport.GetQrCode(ho_Image);
            //    if (codeList != null)
            //    {

            //        this.richTextBox1.Clear();
            //        foreach (string str in codeList)
            //        {
            //            this.richTextBox1.AppendText(str);
            //        }
            //    }
            //}
        }

        private void btnCloseCamera_Click(object sender, EventArgs e)
        {
            if (SAStoreManager.store != null)
            {
                SAStoreManager.store.KNDIOMove(Store_IO_Type.CameraLight_Power, IO_VALUE.LOW);
            }
            HDevelopExport.CloseAllCamera();
            FormStatus(false);
        }

        private void FrmCamera_Load(object sender, EventArgs e)
        {
            foreach (string name in HDevelopExport.cameraNameList)
            { 
                this.cmbCamera.Items.Add(name);
            } 
            this.cmbCamera.SelectedIndex = 0;
            FormStatus(false);
        }

        private void FrmCamera_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (btnCloseCamera.Enabled.Equals(true))
            {
                if (SAStoreManager.store != null)
                {
                    SAStoreManager.store.KNDIOMove(Store_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("读取到的二维码列表:" + "\r\n");
                    Console.Write("读取到的二维码列表" + "\r\n");
                    foreach (string str in codeList)
                    {
                        this.richTextBox1.AppendText(str+"\r\n");
                        Console.Write(str + "\r\n");
                    } 
                } 
               
                //pictureBox1.Handle,获取pictureBox1的句柄
             //   HOperatorSet.OpenWindow(0, 0, width, height, pictureBox1.Handle, "visible", "", out hWindowControl1);
                       
            }
        }
    }
}