Exemplo n.º 1
0
 /// <summary>
 /// 控制按钮按下事件处理
 /// </summary>
 private void buttonPressed_Handler(object sender, ControlButtonPressdEventArgs e)
 {
     switch (e.PressedButton)
     {
         case ButtonType.Stop:
             //如果运行状态为“运行”或者“试运行”,则可以停止
             if (ProcessingManager.RunStatus != RunStatus.Stop)
             {
                 this.Dispatcher.Invoke(new Action(() => { mainWindow.btnStop_Click(null, null); }));
             }
             else
             {
                 this.Dispatcher.Invoke(new Action(() => { MessageBox.Show("请先松开急停按钮再进行下一步操作"); }));
             }
             break;
         case ButtonType.Pause:
             //如果运行状态为运行中,且“暂停”按钮使能,则可以暂停
             this.Dispatcher.Invoke(new Action(() =>
                         {
                             if (ProcessingManager.RunStatus == RunStatus.Running && btnPause.IsEnabled)
                             {
                                 mainWindow.btnPause_Click(null, null);
                             }
                         }));
             break;
         case ButtonType.StartOne:
         case ButtonType.StartTwo:
             //  如果运行状态为“暂停”或者运行状态为“停止”,则可以启动
             if (ProcessingManager.RunStatus == RunStatus.Pause || ProcessingManager.RunStatus == RunStatus.Stop)
             {
                 this.Dispatcher.Invoke(new Action(() =>
                 {
                     ProcessingManager.ChosedStationNo = (ushort)e.PressedButton;
                     mainWindow.btnStart_Click(null, null);
                 }));
             }
             break;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 刷新按钮状态
 /// </summary>
 public static void ReflashState()
 {
     ushort _portValue = 0;
     short rc = 1;
     rc = DMC.CS_DMC_01_get_rm_input_value(ControlCard.CardNo, RM32.NodeID, 0, 0, ref _portValue);
     if (rc == 0)
     {
         //先保存按钮状态
         foreach (ControlButton button in ButtonList)
         {
             button.StateLast = button.StateNow;
             button.StateNow = (_portValue & (0x01 << (ushort)button.Type)) != 0 ? ButtonState.Pressed : ButtonState.Released;
         }
         if (Pressed != null)
         {
             ControlButtonPressdEventArgs _eventArgs = null;
             //如果按下“停止”按钮
             if (Tool.StopButton.StateNow == Tool.StopButton.StateLast && Tool.StopButton.StateNow == ButtonState.Pressed)
             {
                 _eventArgs = new ControlButtonPressdEventArgs(ButtonType.Stop);
             }
             //如果按下“暂停”按钮
             else if (Tool.PauseButton.StateNow == Tool.PauseButton.StateLast && Tool.PauseButton.StateNow == ButtonState.Pressed)
             {
                 _eventArgs = new ControlButtonPressdEventArgs(ButtonType.Pause);
             }
             //如果按下“启动One”按钮
             else if (Tool.StartButtonOne.StateNow == Tool.StartButtonOne.StateLast && Tool.StartButtonOne.StateNow == ButtonState.Pressed)
             {
                 _eventArgs = new ControlButtonPressdEventArgs(ButtonType.StartOne);
             }
             //如果按下“启动Two”按钮
             else if (Tool.StartButtonTwo.StateNow == Tool.StartButtonTwo.StateLast && Tool.StartButtonTwo.StateNow == ButtonState.Pressed)
             {
                 _eventArgs = new ControlButtonPressdEventArgs(ButtonType.StartTwo);
             }
             if (_eventArgs != null)
             {
                 Pressed(null, _eventArgs);
             }
         }
     }
 }