瀏覽代碼

添加复位功能

ltwork 1 年之前
父節點
當前提交
f6a4534ea0

+ 62 - 0
BlankApp1/BlankApp1/Common/PLCCom.cs

@@ -200,7 +200,69 @@ namespace PLCTool.Common
             
             return isSuccess;
         }
+        public bool WritePlcCIOObject(string address, VarType valueType, string writeValue)
+        {
+            bool isSuccess = false;
 
+            short reSuc = -1;
+            if (isConnect == false)
+            {
+                return false;
+            }
+            try
+            {
+                switch (valueType)
+                {
+                    case VarType.Bit:
+                        BitState bit = BitState.OFF;
+                        if (writeValue.Trim() == "1")
+                        {
+                            bit = BitState.ON;
+                        }
+                        else
+                        {
+                            if (writeValue.Trim() == "0")
+                            {
+                                bit = BitState.OFF;
+                            }
+
+                        }
+                        reSuc = ENT.SetBitState(PlcMemory.CIO, address, bit);
+                        //写成功
+                        if (reSuc == 0)
+                        {
+                            isSuccess = true;
+                        }
+                        break;
+                    case VarType.Byte:
+                        break;
+                    case VarType.Word:
+                        short wValue = Convert.ToInt16(writeValue);
+                        reSuc = ENT.WriteWord(PlcMemory.CIO, short.Parse(address), wValue);
+                        //写成功
+                        if (reSuc == 0)
+                        {
+                            isSuccess = true;
+                        }
+                        break;
+                    case VarType.DWord:
+                        break;
+                    case VarType.Int:
+                        break;
+                    case VarType.DInt:
+                        break;
+                    case VarType.Real:
+                        break;
+
+                }
+            }
+            catch (Exception ex)
+            {
+
+            }
+
+            return isSuccess;
+        }
         private static object GetVariableValue(VarType varType, object var)
         {
             switch (varType)

+ 1 - 1
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/PLCConfigViewModel.cs

@@ -59,7 +59,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         {
             breadCrumbs.Clear();
             breadCrumbs.Add(new CrumbViewModel { Name = "基础设置" });
-            breadCrumbs.Add(new CrumbViewModel { Name = "项目管理" });
+            breadCrumbs.Add(new CrumbViewModel { Name = "PLC配置" });
             _aggregator.GetEvent<BreadEvent>().Publish(breadCrumbs);
         }
         /// <summary>

+ 17 - 2
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/ManualTestViewModel.cs

@@ -70,6 +70,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             NextCommand = new DelegateCommand<object>(Next);
             DoneCommand = new DelegateCommand<object>(Done);
             ItemChangeCommand = new DelegateCommand(ItemChange);
+            ResetCommand = new DelegateCommand(Reset);
             BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
             InConList = new ObservableCollection<BasPlcItemConfigDto>();
             OutConList = new ObservableCollection<BasPlcItemConfigDto>();
@@ -90,8 +91,21 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                 GetDetailInfo(id);
             }
         }
-
-
+        /// <summary>
+        /// 复位PLC
+        /// </summary>
+        private async void Reset()
+        {
+            PLCCom.GetInstance().WritePlcCIOObject("1.00", VarType.Bit, "0");
+            await Task.Delay(1000);
+            PLCCom.GetInstance().WritePlcCIOObject("1.00", VarType.Bit, "1");
+            await Task.Delay(1000);
+            bool isResult=PLCCom.GetInstance().WritePlcCIOObject("1.00", VarType.Bit, "0");
+            if(isResult)
+            {
+                MessageBox.Show("复位成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+            }
+        }
 
 
         #region idialog接口实现
@@ -1314,6 +1328,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
         public DelegateCommand<object> DoneCommand { set; get; }
         public DelegateCommand ItemChangeCommand { set; get; }
+        public DelegateCommand ResetCommand { set; get; }
         
         #endregion
         #region 变量绑定

+ 2 - 1
BlankApp1/BlankApp1/Views/BusinessManageView/ManualTestView.xaml

@@ -299,11 +299,12 @@
 
                 </hc:StepBar>
             </Grid>
-            <UniformGrid  Grid.Row="5" Columns="4">
+            <UniformGrid  Grid.Row="5" Columns="5">
                 <Button  Content="开始检测" Width="80" IsEnabled="{Binding StartEnalbe}" Height="30" FontSize="12"   Command="{Binding StartCommand}" Style="{DynamicResource WD.PrimaryButton}" />
                 <Button  Content="上一项" Width="80" IsEnabled="{Binding StartEnalbe}" Height="30" FontSize="12"   Command="{Binding PreviousCommand}" Style="{DynamicResource WD.PrimaryButton}" />
                 <Button  Content="下一项" Width="80" IsEnabled="{Binding StartEnalbe}" Height="30" FontSize="12"   Command="{Binding NextCommand}" Style="{DynamicResource WD.PrimaryButton}" />
                 <Button  Content="完成" Width="80"  IsEnabled="{Binding StartEnalbe}" Height="30" FontSize="12"  Command="{Binding DoneCommand}" Style="{DynamicResource WD.PrimaryButton}" />
+                <Button  Content="复位" Width="80"   Height="30" FontSize="12"  Command="{Binding ResetCommand}" Style="{DynamicResource WD.PrimaryButton}" />
             </UniformGrid>
             <Grid Grid.Row="2">
                 <StackPanel Orientation="Vertical" HorizontalAlignment="Center">