VisionStoreDetect.cs 5.4 KB
using DeviceLibrary;
using OnlineStore.Common;
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.Threading.Tasks;
using System.Windows.Forms;

namespace TheMachine
{
    public partial class VisionStoreDetect : UserControl
    {
        public VisionStoreDetect()
        {
            InitializeComponent();
            RobotManage.LoadFinishEvent += RobotManage_LoadFinishEvent; ;
            CameraPointTest.TestStorePointEvent += CameraPointTest_TestStorePointEvent;
        }

        private void RobotManage_LoadFinishEvent(bool state, string msg)
        {
            return;
            if (!this.Created)
                return;
            this.Invoke((EventHandler)delegate
            {
                LogUtil.info("开始采集");
                PictureBox p1 = new PictureBox();
                PictureBox p2 = new PictureBox();
                PictureBox p3 = new PictureBox();
                PictureBox p4 = new PictureBox();
                RobotManage.CameraA.PreviewImage("monitorA", p1.Handle);
                RobotManage.CameraA.PreviewImage("monitorB", p2.Handle);
                RobotManage.CameraA.PreviewImage("monitorC", p3.Handle);
                RobotManage.CameraA.PreviewImage("monitorD", p4.Handle);
                RobotManage.CameraA.Open(); 
                RobotManage.CameraA.GetPictureBoxEvent += CameraA_GetPictureBoxEvent;
            });
        }

        private Bitmap CameraA_GetPictureBoxEvent(int index)
        {
            switch (index) {
                case 0:
                    return Common.DeepClone((Bitmap)pictureBox1.Image);
                case 1:
                    return Common.DeepClone((Bitmap)pictureBox2.Image);
                case 2:
                    return Common.DeepClone((Bitmap)pictureBox3.Image);
                case 3:
                    return Common.DeepClone((Bitmap)pictureBox4.Image);
            }
            return null;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            return;
            if (!this.Visible)
                return;
            Task.Run(() =>
            {
                //LogUtil.info("开始采集1");
                CameraPointTest.GetThingStoreName(TestStorePointPort.入口);
                CameraPointTest.GetThingStoreName(TestStorePointPort.出口);
                CameraPointTest.GetThingStoreName(TestStorePointPort.上层左侧);
                CameraPointTest.GetThingStoreName(TestStorePointPort.下层右侧);

            });
            
        }

        private void CameraPointTest_TestStorePointEvent(object sender, Bitmap e)
        {
            
            if (!this.Created)
                return;

            this.Invoke((EventHandler<Bitmap>)delegate {
                var b = e;// Common.DeepClone(e);
                TestStorePointPort tp = (TestStorePointPort)sender;
                switch (tp)
                {
                    case TestStorePointPort.入口:
                        pictureBox1.Image = b;
                        break;
                    case TestStorePointPort.出口:
                        pictureBox2.Image = b;
                        break;
                    case TestStorePointPort.上层左侧:
                    case TestStorePointPort.下层左侧:
                        pictureBox3.Image = b;
                        break;
                    case TestStorePointPort.上层右侧:
                    case TestStorePointPort.下层右侧:
                        pictureBox4.Image = b;
                        break;
                }
            }, sender,e);
        }

        private void VisionStoreDetect_Load(object sender, EventArgs e)
        {
            
        }

        private void TestALL_Click(object sender, EventArgs e)
        {
            //RobotManage.CameraA.GetImage(0).Save("test.bmp");
            Task.Run(() =>
            {
                //    LogUtil.info("1");
                //Common.DeepClone((Bitmap)pictureBox1.Image).Save("test.bmp");
                var haslistStoreName = CameraPointTest.GetThingStoreName(TestStorePointPort.入口);
                LogUtil.info("入口:" + string.Join(",", haslistStoreName));
                haslistStoreName = CameraPointTest.GetThingStoreName(TestStorePointPort.出口);
                LogUtil.info("出口:" + string.Join(",", haslistStoreName));
                if (IOManager.IOValue(IO_Type.Tside_Right).Equals(IO_VALUE.HIGH))
                {
                    haslistStoreName=CameraPointTest.GetThingStoreName(TestStorePointPort.上层右侧);
                    LogUtil.info("上层右侧:" + string.Join(",", haslistStoreName));
                    haslistStoreName =CameraPointTest.GetThingStoreName(TestStorePointPort.下层左侧);
                    LogUtil.info("下层左侧:" + string.Join(",", haslistStoreName));
                } else {

                    haslistStoreName = CameraPointTest.GetThingStoreName(TestStorePointPort.上层左侧);
                    LogUtil.info("上层左侧:" + string.Join(",", haslistStoreName));
                    haslistStoreName = CameraPointTest.GetThingStoreName(TestStorePointPort.下层右侧);
                    LogUtil.info("下层右侧:" + string.Join(",", haslistStoreName));
                }
            });
            RobotManage.mainMachine.ScanCode();
        }
    }
}