Exemplo n.º 1
0
        /// <summary>按下 Get 按鈕</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGetPosition_Click(object sender, EventArgs e)
        {
            try
            {
                // 取得 MvFanucRobotPosReg 物件

                var speed      = GetSpeedFromControlle();
                var motionType = GetMotionType();
#if NO_DEVICE
                var currentPos    = Fake_MvFanucRobotPosReg.GetNewInstance();
                var currentMotion = new ClassHelper().ClonPropertiesValue <Fake_MvFanucRobotPosReg, HalRobotMotion>(currentPos, null, true);
#else
                var currentPos    = this.GetCurrentPosUf();
                var currentMotion = new ClassHelper().ClonPropertiesValue <MvFanucRobotPosReg, HalRobotMotion>(currentPos, null, true);
#endif
                currentMotion.Speed      = speed;
                currentMotion.MotionType = motionType;

                this.TempCurrentPosition = currentMotion;
                DisplayGetPosition(currentMotion);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        /// <summary>點選 Add 按鈕</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            //MvFanucRobotPosReg curr = ldd.ReadCurPosUf();
            //HalRobotMotion motion = new HalRobotMotion();

            /**
             *          Fake_MvFanucRobotPosReg currentPosition = Fake_MvFanucRobotPosReg.GetNewInstance();
             *          ClassHelper helper = new ClassHelper();
             *          //var motion = saver.GetTargetInstanceFromSourceInstance<MvFanucRobotPosReg, HalRobotMotion>(curr, null, true);
             *          var motion = helper.ClonPropertiesValue<Fake_MvFanucRobotPosReg, HalRobotMotion>(currentPosition, null, true);
             */

            try
            {
                int?sn = GetSnFromController();
                if (!sn.HasValue || (int)sn < 1)
                {
                    MessageBox.Show("請將 Serial No 欄位設為大於0的整數");
                    return;
                }
                DialogResult dialogResult = DialogResult.None;
                if (IsSnExist(sn.Value))
                {
                    dialogResult = MessageBox.Show("Serial No : " + sn + " 已經存在,要繼續嗎?\n請按 [是]自動編號、[否]覆蓋原有資料、[取消]重新設定", "", MessageBoxButtons.YesNoCancel);
                }
                if (dialogResult == DialogResult.Yes)
                {// 自動編號
                    sn = this.GetPositionInstancesNextSn();
                }
                else if (dialogResult == DialogResult.No)
                {// 覆蓋原有資料
                 // 找到原資料刪除之

                    this.RemovePositionBySerialNum(sn.Value);
                }
                else if (dialogResult == DialogResult.Cancel)
                {  // 取消
                    return;
                }

#if NO_DEVICE
                var currentPos    = Fake_MvFanucRobotPosReg.GetNewInstance();
                var currentMotion = new ClassHelper().ClonPropertiesValue <Fake_MvFanucRobotPosReg, HalRobotMotion>(currentPos, null, true);
#else
                var currentPos    = GetCurrentPosUf();
                var currentMotion = new ClassHelper().ClonPropertiesValue <MvFanucRobotPosReg, HalRobotMotion>(currentPos, null, true);
#endif
                currentMotion.Speed      = GetSpeedFromControlle();
                currentMotion.MotionType = GetMotionType();
                this.TempCurrentPosition = currentMotion;
                PositionInfo newPositionInfo = GetNewPositionInfo(sn.Value);

                this.PositionInstances.Add(newPositionInfo);

                RefreshPositionInfoList();
                NumUdpSn.Value = this.GetPositionInstancesNextSn();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }