Example #1
0
        //检查图像状态

        /*返回值为含三个值得int数组,定义如下:
         *  [0,0,0] 未读到图
         *  [1,x,y] 有messagebox窗口,x,y为坐标
         *  [2,2,2] messagebox窗口未知错误
         *  [3,3,3] 未找到定位区域(右测试按钮)
         *  [4,4,4] 未知错误
         *  [5,a,b] 查询到测试窗体,其中a和b的值只有0,1,2,3,4;
         *  当a=0表示上窗体初始状态,=1测试中,=2测试成功,=3测试失败,=4未知状态
         *  当b=0表示下窗体初始状态,=1测试中,=2测试成功,=3测试失败,=4未知状态
         */

        private int[] CheckImageStatus()
        {
            try
            {
                for (int i = 0; i < 5; i++)
                {
                    //截屏
                    if (PrintImage.PrintBitImage(bmpfile))
                    {
                        break;
                    }
                    if (i == 4)
                    {
                        Log("截图失败");
                        return(null);
                    }
                    Thread.Sleep(500);
                }

                //调用函数
                object[] parm = new object[1];
                parm[0] = bmpfile;

                lock (m_objDll)
                {
                    Log(DateTime.Now.ToString() + ", 处理图像开始");
                    //判断是否处于结束态, 调用HALCON函数
                    int[] res = (int[])(m_dicMethod[MyData.halconCheckImageStatusName].Invoke(obj, parm));

                    Log(DateTime.Now.ToString() + ", 处理图像结束");

                    Log("图像状态:【" + res[0].ToString() + ", " + res[1].ToString() + ", " + res[2].ToString() + "】");
                    return(res);
                }
            }
            catch (Exception ex)
            {
                Log(ex.Message);
            }

            return(null);
        }
Example #2
0
        private void Run()
        {
            DateTime dt       = DateTime.Now;
            string   filename = Application.StartupPath + @"\" +
                                //                  dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + "_" +
                                //                  dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString() + ".bmp";
                                string.Format("{0,0:D4}{1,0:D2}{2,0:D2}_{3,0:D2}{4,0:D2}{5,0:D2}.bmp", dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second);

            Thread.Sleep(300);
            if (!PrintImage.PrintBitImage(filename))
            {
                MessageBox.Show("截图失败");
                return;
            }

            if (File.Exists(filename))
            {
                if (this.IsHandleCreated)
                {
                    this.Invoke(new EventHandler(delegate
                    {
                        //this.WindowState = FormWindowState.Normal;
                        pictureBox1.ImageLocation = filename;
                        textBox_capture.Text      = filename;
                    }));
                }
            }
            else
            {
                if (this.IsHandleCreated)
                {
                    this.Invoke(new EventHandler(delegate
                    {
                        //this.WindowState = FormWindowState.Normal;
                        pictureBox1.ImageLocation = null;
                        textBox_capture.Text      = filename;
                    }));
                }
            }

            Application.DoEvents();
        }