Example #1
0
            /// <summary>
            /// Posts a Break instruction to the island thread.
            /// Called by debugger manager thread.
            /// </summary>
            internal void Break()
            {
                _debugAction = DebugAction.Break;

                _workToDoEvent.Set();
                _workDoneEvent.WaitOne();

                ((IDisposable)this).Dispose();
            }
Example #2
0
            /// <summary>
            /// Posts an Enter instruction to the island thread.
            /// Called by debugger manager thread
            /// </summary>
            internal void EnterState(DebuggerState state, IDictionary<string, object> locals)
            {
                _debugAction = DebugAction.Enter;
                _virtualStack.Push(new VirtualStackFrame(state, locals));
                _workToDoEvent.Set();

                // Block until Island executes NOP, 
                // giving BPs a chance to be hit.
                // Must block here if the island is stopped at a breakpoint.
                _workDoneEvent.WaitOne();
            }
Example #3
0
            /// <summary>
            /// Posts a Leave instruction to the island thread.
            /// Called by debugger manager thread
            /// If location is provided, verifies that the state being left is the state that was entered.
            /// Stack may already be empty, in which case it is not modified.
            /// </summary>
            internal void LeaveState(ElementLocation location)
            {
                ErrorUtilities.VerifyThrow(location == null || location == _virtualStack.Peek().State.Location, "Mismatched leave was {0} expected {1}", location.LocationString, _virtualStack.Peek().State.Location.LocationString);

                _debugAction = DebugAction.Leave;

                if (_virtualStack.Count > 0) // May be falling out of the first enter
                {
                    _virtualStack.Pop();
                }

                _workToDoEvent.Set();
                _workDoneEvent.WaitOne();
            }
Example #4
0
 /// <summary>
 /// 根据Z轴的速度限制,计算出合理的最大速度
 /// </summary>
 /// <param name="pNext">下一道工序的起始点</param>
 /// <param name="newVel">变速前的的最大速度</param>
 /// <param name="debugAction">试教动作</param>
 /// <param name="portValue">io状态</param>
 /// <returns></returns>
 private static int getSpeed(Point pNext, int newVel, DebugAction debugAction, int portValue)
 {
     //由铣型类型决定的比例系数1 //由档位决定的比例系数2
     double coeOne = 1.0, coeTwo = 1.0;
     //根据档位选择速度增益coeTwo
     switch (portValue & 0x70)
     {
         //“X1”档
         case 0x10:
             coeTwo = 0.5;
             break;
         //“X10”档
         case 0x20:
             coeTwo = 1;
             break;
         //“X100”档
         default:
             coeTwo = 1.5;
             break;
     }
     switch (debugAction)
     {
         case DebugAction.DrillIn:
             coeOne = 0.5;
             break;
         case DebugAction.DrillOut:
             break;
         case DebugAction.Cut:
             break;
         case DebugAction.MillCir:
             coeOne = 0.1;
             break;
         case DebugAction.MillRec:
             //如果是铣矩形,这返回0.8背的z轴速度限制
             return newVel * coeTwo > zSpeedLimit ? (int)(zSpeedLimit * 0.8) : (int)(newVel * coeTwo);
         case DebugAction.Move:
             break;
     }
     int newSpeed = (int)(newVel * coeOne * coeTwo);
     int[] cmdPulse = new int[3];
     //取得铣入点的位置脉冲
     for (ushort i = 0; i < Servo.NumOfServo - 2; i++)
     {
         //取得当前位置四个的轴脉冲值
         DMC.CS_DMC_01_get_command(0, Servo.LstOfServo[i], 0, ref cmdPulse[i]);
     }
     int zSpeed = 0;
     long disX = (pNext.XPulse - cmdPulse[0]) / 100;
     long disY = (pNext.YPulse - cmdPulse[1]) / 100;
     long disZ = (pNext.ZPulse - cmdPulse[2]) / 100 + 1;
     long dis = (long)Math.Sqrt(disX * disX + disY * disY + disZ * disZ) + 3;
     //计算出z轴方向的速度向量
     zSpeed = (int)Math.Abs((newSpeed * disZ) / dis);
     //如果速度超过了z轴的极限
     if (zSpeed >= zSpeedLimit)
     {
         //则返回Z轴达到速度极限时的最大速度
         return (int)Math.Abs(zSpeedLimit * dis / disZ);
     }
     else
     {
         return newSpeed;
     }
 }
Example #5
0
 /// <summary>
 /// 改变定位信息
 /// </summary>
 /// <param name="station">要改变定位信息的工序列表</param>
 /// <param name="noOfProcessing">正在信息工序的工序号</param>
 /// <param name="pointOld">改变前的定位信息</param>
 /// <param name="typeOfAction">执行的试教动作</param>
 private static void changePosition(Station station, int noOfProcessing, Point pointOld, DebugAction typeOfAction)
 {
     //取得当前点的脉冲
     Point _pointNew = Servo.GetPosition();
     //根据试教的运动类型选择处理的方式
     switch (typeOfAction)
     {
         #region DrillIn
         case DebugAction.DrillIn:
             //如果是正面和背面,则改变除了Y轴以外的其余轴的绝对定位信息
             if (station[noOfProcessing].SideType == SideType.Front || station[noOfProcessing].SideType == SideType.Back)
             {
                 station[noOfProcessing].IntoPoint.XPulse = _pointNew.XPulse;
                 station[noOfProcessing].StartPoint.XPulse = station[noOfProcessing].IntoPoint.XPulse;
                 station[noOfProcessing].IntoPoint.YPulse = _pointNew.YPulse - pointOld.YPulse + station[noOfProcessing].IntoPoint.YPulse;
             }
             //否则改变X轴以外的其余轴的定位信息
             else
             {
                 station[noOfProcessing].IntoPoint.YPulse = _pointNew.YPulse;
                 station[noOfProcessing].StartPoint.YPulse = station[noOfProcessing].IntoPoint.YPulse;
                 station[noOfProcessing].IntoPoint.XPulse = _pointNew.XPulse - pointOld.XPulse + station[noOfProcessing].IntoPoint.XPulse;
             }
             station[noOfProcessing].IntoPoint.ZPulse = _pointNew.ZPulse;
             station[noOfProcessing].IntoPoint.WPulse = _pointNew.WPulse;
             station[noOfProcessing].StartPoint.ZPulse = station[noOfProcessing].IntoPoint.ZPulse;
             station[noOfProcessing].StartPoint.WPulse = station[noOfProcessing].IntoPoint.WPulse;
             break;
         #endregion
         #region DrillOut
         case DebugAction.DrillOut:
             //如果是正面和背面,则Y轴StartPoint的定位信息
             if (station[noOfProcessing].SideType == SideType.Front || station[noOfProcessing].SideType == SideType.Back)
             {
                 station[noOfProcessing].StartPoint.YPulse = _pointNew.YPulse - pointOld.YPulse + station[noOfProcessing].StartPoint.YPulse;
             }
             //否则改变X轴StartPoint的定位信息
             else
             {
                 station[noOfProcessing].StartPoint.XPulse = _pointNew.XPulse - pointOld.XPulse + station[noOfProcessing].StartPoint.XPulse;
             }
             break;
         #endregion
         #region Cut
         case DebugAction.Cut:
             //如果是正面和背面,则改变除了Y轴以外的其.余轴的绝对定位信息
             //if (station[noOfProcessing].SideType == SideType.Front || station[noOfProcessing].SideType == SideType.Back)
             //{
             station[noOfProcessing].IntoPoint.XPulse = _pointNew.XPulse;
             //}
             ////否则改变X轴以外的其余轴的定位信息
             //else
             //{
             station[noOfProcessing].IntoPoint.YPulse = _pointNew.YPulse;
             //}
             station[noOfProcessing].IntoPoint.ZPulse = _pointNew.ZPulse;
             if (noOfProcessing != station.MillNum)
             {
                 station[noOfProcessing].IntoPoint.WPulse = _pointNew.WPulse;
             }
             else
             {
                 //如果相差超过270度
                 if (Math.Abs(double.Parse(station[noOfProcessing].IntoPoint.WCodinate) - double.Parse(_pointNew.WCodinate)) > 270)
                 {
                     if (station[noOfProcessing].IntoPoint.WPulse > _pointNew.WPulse)
                         station[noOfProcessing].IntoPoint.WPulse = _pointNew.WPulse + Tool.WPulsePerCircle;
                     else
                         station[noOfProcessing].IntoPoint.WPulse = _pointNew.WPulse - Tool.WPulsePerCircle;
                     station[noOfProcessing].StartPoint.WPulse = station[noOfProcessing].IntoPoint.WPulse;
                 }
                 //如果是正面和背面,则改变除了Y轴以外的其余轴的绝对定位信息
                 if (station[noOfProcessing].SideType == SideType.Front || station[noOfProcessing].SideType == SideType.Back)
                 {
                     station[noOfProcessing].StartPoint.XPulse = _pointNew.XPulse;
                 }
                 //否则改变X轴以外的其余轴的定位信息
                 else
                 {
                     station[noOfProcessing].StartPoint.YPulse = _pointNew.YPulse;
                 }
                 //}
                 station[noOfProcessing].StartPoint.ZPulse = _pointNew.ZPulse;
             }
             break;
         #endregion
         #region DrillCir & DrillRec
         case DebugAction.MillCir:
         case DebugAction.MillRec:
             if (station[noOfProcessing].SideType == SideType.Front || station[noOfProcessing].SideType == SideType.Back)
             {
                 station[noOfProcessing].IntoPoint.YPulse = _pointNew.YPulse;
             }
             else
             {
                 station[noOfProcessing].IntoPoint.XPulse = _pointNew.XPulse;
             }
             break;
         #endregion
         case DebugAction.InOutChange:
             station.InOutChangeHeight = _pointNew.ZPulse;
             break;
         case DebugAction.Move:
             break;
     }
 }
Example #6
0
 /// <summary>
 /// 停止试教监视器
 /// </summary>
 public static int StopDebugMonitor()
 {
     lock (debugMonitorLock)
     {
         if (IsDebugMonitorStarted)
         {
             IsDebugMonitorStarted = false;
             debugMonitor.Abort();
             //重设试教动作为Move
             debugingAction = DebugAction.Move;
             return 0;
         }
         else
         {
             return -1;
         }
     }
 }
Example #7
0
 /// <summary>
 /// 启动试教监视器
 /// </summary>
 /// <param name="debugMode">试教模式</param>
 /// <param name="masterNode">调速主轴</param>
 /// <param name="process">要改变定位信息的工序</param>
 public static Thread StartDebugMonitor(DebugMode debugMode, ushort masterNode, Station station, int processingNo, DebugAction debugAction)
 {
     lock (debugMonitorLock)
     {
         //获取用以调速的主轴站号
         masterAxisNode = masterNode;
         //根据选定的模式进行试教
         if (debugMode == DebugMode.ModeOne)
         {
             debugMonitor = new Thread(debugMonitorHandle);
         }
         else
         {
             debugMonitor = new Thread(debugMonitorHandle2);
         }
         //获取正在加工的工位
         debugingStation = station;
         //获取正在执行的工序号
         noOfProcessing = processingNo;
         //获取正在执行的试教动作
         debugingAction = debugAction;
         //设为后台线程,以使关闭窗口后退出线程
         debugMonitor.IsBackground = true;
         debugMonitor.Priority = ThreadPriority.Highest;
         debugMonitor.Start();
         //指示试教监视器已经启动
         IsDebugMonitorStarted = true;
         return debugMonitor;
     }
 }
Example #8
0
 /// <summary>
 /// 等待动作完成
 /// </summary>
 /// <param name="nodeList">试教模式下调速的主控轴</param>
 /// <param name="process">要改变定位信息的工序</param>
 /// <param name="delayTime">延时查询时间</param>
 private static void waitForDone(ushort[] nodeList, int processingNo, WaitMode waitMode, DebugAction debugAction, int delayTime = Parameter.delayTime)
 {
     short rc = 0;
     //取得当前的加工主轴
     currentMasterNode = nodeList[0];
     //如果是试教状态,则启动试教试教监视器
     if (RunStatus == RunStatus.TryRunning) {
         //等待试教进程结束
         Monitor.StartDebugMonitor(DebugMode.ModeTwo, nodeList[0], currentStation, processingNo, debugAction).Join();
     }
     //如果是试教状态,或者等待模式为Always则等待至动作完成
     else if (waitMode == WaitMode.Always) {
         //等待每个受控制的从站完成动作
         foreach (ushort nodeNo in nodeList) {
             ushort mDone = 1;
             uint mStatus = 0;
             //如果运动没有停止,且没有达到目标位置则继续查询
             while ((mDone != 0) || ((mStatus & 0x0400) != 0x0400)) {
                 //等待一定时间再进行查询
                 Thread.Sleep(delayTime);
                 rc = DMC.CS_DMC_01_motion_done(ControlCard.CardNo, nodeNo, 0, ref mDone);
                 rc = DMC.CS_DMC_01_motion_status(ControlCard.CardNo, nodeNo, 0, ref mStatus);
             }
         }
     }
 }