SenGao 2 weeks ago
parent
commit
cc249f3ade
1 changed files with 9 additions and 3 deletions
  1. 9 3
      Tools/PLCIOPointTool/ViewModels/WorkAreaViewModel.cs

+ 9 - 3
Tools/PLCIOPointTool/ViewModels/WorkAreaViewModel.cs

@@ -25,13 +25,13 @@ public partial class WorkAreaViewModel : ObservableObject, IDisposable
 
     #region ObservableProperty
     [ObservableProperty]
-    private bool _isConnected=false;
+    private bool _isConnected = false;
 
     [ObservableProperty]
     private string _readSymbolName = string.Empty;
 
     [ObservableProperty]
-    private string _readValue=string.Empty;
+    private string _readValue = string.Empty;
 
     [ObservableProperty]
     private string _readValueType = string.Empty;
@@ -49,7 +49,7 @@ public partial class WorkAreaViewModel : ObservableObject, IDisposable
     private int _dataTypeId = -1;
     #endregion
 
-    public WorkAreaViewModel(ILogService logService,IClientService clientService)
+    public WorkAreaViewModel(ILogService logService, IClientService clientService)
     {
         _logService = logService;
         _clientService = clientService;
@@ -77,6 +77,12 @@ public partial class WorkAreaViewModel : ObservableObject, IDisposable
         {
             try
             {
+                if (DataTypeId < 0 || string.IsNullOrWhiteSpace(WriteValue))
+                {
+                    _logService.Warning($"Input parameters before writing");
+                    return;
+                }
+
                 var dataType = (DataType)DataTypeId;
                 object value = dataType switch
                 {