예제 #1
0
 private void BTN_Z2MoveUp_Click(object sender, EventArgs e)
 {
     Device?.MoveZ2(0 - Z2Distance);
 }
예제 #2
0
        private void BTN_StartTest_Click(object sender, EventArgs e)
        {
            BTN_StartTest.Enabled = false;

            /*parameter initialize*/
            List <double> z2Positions;

            try
            {
                z2Positions = Properties.Settings.Default.MotorZ2Positions.Split(',').ToList().Select(x => double.Parse(x)).ToList();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to retrieve test positions, please check the configuration file");
                BTN_StartTest.Enabled = true;
                return;
            }

            /*device initialize*/
            CameraController camera = UC_CameraCtrl.Device;
            Result           ret    = camera.Open(UC_CameraCtrl.TestType);

            if (ret.Id != "Ok" && ret.Id != "Dummy")
            {
                MessageBox.Show($"Failed to open camera for {UC_CameraCtrl.TestType}({ret.Id})");
                //return;
            }

            MotorController motor = MotorCtrlUC.Device;

            if (motor == null)
            {
                MessageBox.Show($"Failed to open motor for {UC_CameraCtrl.TestType}");
            }

            for (int i = 0; i < z2Positions.Count; i++)
            {
                double offset = 0;
                if (i == 0)
                {
                    offset = z2Positions[0];
                }
                else
                {
                    offset = z2Positions[i] - z2Positions[i - 1];
                }
                motor.MoveZ2(offset);

                Thread.Sleep(2000);

                ret = camera.Read(z2Positions[i].ToString());
                UpdateImg(ret.Param as Bitmap);

                ret = camera.Analyze(UC_CameraCtrl.TestType, z2Positions[i]);
                UpdateImg(ret.Param as Bitmap);

                if (camera.Imgs.Last().Circles.Count == 0)
                {
                    MessageBox.Show("Failed to find any circles in recent images");
                    break;
                }

                Thread.Sleep(1000);
            }

            ret = camera.Calculate(UC_CameraCtrl.TestType);
            UC_Result.Update(ret.Param as Dictionary <string, string>);

            BTN_StartTest.Enabled = true;
        }