Browse Source

add port and custom options

Robert 1 year ago
parent
commit
fbc346c4f7

+ 4 - 4
MesAdaptor/Properties/AssemblyInfo.cs

@@ -31,7 +31,7 @@ using System.Runtime.InteropServices;
 //
 // You can specify all the values or you can default the Build and Revision Numbers
 // by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.6.0")]
-[assembly: AssemblyVersion("1.0.6.0")]
-[assembly: AssemblyFileVersion("1.0.6.0")]
-[assembly: AssemblyInformationalVersion("3825d43")]
+// [assembly: AssemblyVersion("1.0.7.0")]
+[assembly: AssemblyVersion("1.0.7.0")]
+[assembly: AssemblyFileVersion("1.0.7.0")]
+[assembly: AssemblyInformationalVersion("0db9ef0")]

+ 11 - 0
MesAdaptor/SajectConnectSajet2.cs

@@ -317,6 +317,17 @@ namespace MesAdaptor
                     return "A095";
                 case MesErrorCode.FactoryResetFail:
                     return "A096";
+
+                case MesErrorCode.SetOptionsFail:
+                    return "ST001";
+                case MesErrorCode.ProgramFail:
+                    return "ST002";
+                case MesErrorCode.RestFail:
+                    return "ST003";
+                case MesErrorCode.ProgramCheckFail:
+                    return "ST004";
+                case MesErrorCode.GetCheckSumFail:
+                    return "ST005";
             }
             return "A081";
         }

+ 7 - 1
ST-LINK_MES/MainWindow.xaml.cs

@@ -33,7 +33,11 @@ namespace ST_LINK_MES
 
             Title = Title + string.Format(" V{0}", Assembly.GetEntryAssembly().GetName().Version);
 
-            this.stlinkService = new STLinkCliPrograrmService(AppSettingService.Instance.DLinkCliPath);
+            this.stlinkService = new STLinkCliPrograrmService(
+                AppSettingService.Instance.DLinkCliPath,
+                AppSettingService.Instance.Port,
+                AppSettingService.Instance.CustomDefaultOptions
+                );
             this.fileRrecordService = new FileRrecordService();
             //this.loginWindow = new LoginWindow();
             this.resultDialog = new ResultDialog();
@@ -62,6 +66,8 @@ namespace ST_LINK_MES
                 MechineCode = currentSetting.MechineCode,
                 BinPath = uxBinFilePath.Text,
                 DLinkCliPath = currentSetting.DLinkCliPath,
+                Port = currentSetting.Port,
+                CustomDefaultOptions = currentSetting.CustomDefaultOptions
             };
             currentSetting.Save(setting);
         }

+ 4 - 4
ST-LINK_MES/Properties/AssemblyInfo.cs

@@ -50,7 +50,7 @@ using System.Windows;
 //
 // You can specify all the values or you can default the Build and Revision Numbers
 // by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.6.0")]
-[assembly: AssemblyVersion("1.0.6.0")]
-[assembly: AssemblyFileVersion("1.0.6.0")]
-[assembly: AssemblyInformationalVersion("3825d43")]
+// [assembly: AssemblyVersion("1.0.7.0")]
+[assembly: AssemblyVersion("1.0.7.0")]
+[assembly: AssemblyFileVersion("1.0.7.0")]
+[assembly: AssemblyInformationalVersion("0db9ef0")]

+ 4 - 0
ST-LINK_MES/Service/AppSettingService.cs

@@ -33,6 +33,8 @@ namespace ST_LINK_MES.Service
         public bool LOCK => appSetting == null ? false : appSetting.LOCK;
         public string DLinkCliPath => appSetting?.DLinkCliPath;
         public string BinPath => appSetting?.BinPath;
+        public string Port => appSetting?.Port;
+        public string CustomDefaultOptions => appSetting?.CustomDefaultOptions;
 
         private const string settingFileName = "Settings.ini";
         private AppSetting appSetting;
@@ -77,5 +79,7 @@ namespace ST_LINK_MES.Service
         public bool LOCK { get; set; }
         public string DLinkCliPath { get; set; }
         public string BinPath { get; set; }
+        public string Port { get; set; }
+        public string CustomDefaultOptions { get; set; }
     }
 }

+ 2 - 2
ST-LINK_MES/Service/STLinkCliPrograrmService.cs

@@ -10,9 +10,9 @@ namespace ST_LINK_MES.Service
 {
     public class STLinkCliPrograrmService
     {
-        public STLinkCliPrograrmService(string stlCliPath = "")
+        public STLinkCliPrograrmService(string stlCliPath = "", string port = "", string customDefaultOption = null)
         {
-            this._cli = new STLinkCliWrapService(stlCliPath);
+            this._cli = new STLinkCliWrapService(stlCliPath, port, customDefaultOption);
         }
 
         public delegate void OnMsgRecevicedEvent(string msg);

+ 32 - 6
ST-LINK_MES/Service/STLinkCliWrapService.cs

@@ -9,13 +9,17 @@ namespace ST_LINK_MES.Service
 {
     public class STLinkCliWrapService
     {
-        public STLinkCliWrapService(string cliPath)
+        public STLinkCliWrapService(string cliPath, string port = "", string customDefaultOption = null)
         {
             if (string.IsNullOrEmpty(cliPath))
             {
                 cliPath = "C:\\Program Files (x86)\\STMicroelectronics\\STM32 ST-LINK Utility\\ST-LINK Utility\\ST-LINK_CLI.exe";
             }
             this.cliPath = cliPath;
+
+            SetPortStringParam(port);
+
+            SetCustomDefaultOptionParam(customDefaultOption);
         }
 
         public delegate void OnMsgRecevicedEvent(string msg);
@@ -24,30 +28,32 @@ namespace ST_LINK_MES.Service
         public string CliPath => cliPath;
 
         private readonly string cliPath;
+        private string portParamString;
+        private string defaultOptionString;
 
         public int SetDefaultOptions()
         {
-            return RunConsole(cliPath, $"-OB RDP=0 BOR_LEV=3 IWDG_SW=1 nRST_STOP=1 nRST_STDBY=1");
+            return RunConsole(cliPath, $"{portParamString} {defaultOptionString}");
         }
 
         public int StartProgram(string filePath)
         {
-            return RunConsole(cliPath, $"-P \"{filePath}\" 0x08000000");
+            return RunConsole(cliPath, $"{portParamString} -P \"{filePath}\" 0x08000000 -V \"after_programing\"");
         }
 
         public int Rest()
         {
-            return RunConsole(cliPath, $"-Rst");
+            return RunConsole(cliPath, $"{portParamString} -Rst");
         }
 
         public int Check(string filePath)
         {
-            return RunConsole(cliPath, $"-CmpFile \"{filePath}\" 0x08000000");
+            return RunConsole(cliPath, $"{portParamString} -CmpFile \"{filePath}\" 0x08000000");
         }
 
         public int GetCheckSum(string filePath)
         {
-            return RunConsole(cliPath, $"-Cksum \"{filePath}\"");
+            return RunConsole(cliPath, $"{portParamString} -Cksum \"{filePath}\"");
         }
 
         private int RunConsole(string exePath, string param)
@@ -78,5 +84,25 @@ namespace ST_LINK_MES.Service
         {
             OnMsgReceviced?.Invoke(e.Data);
         }
+
+        private void SetPortStringParam(string port)
+        {
+            if (string.IsNullOrEmpty(port))
+            {
+                portParamString = string.Empty;
+                return;
+            }
+            portParamString = $"-c {port}";
+        }
+
+        private void SetCustomDefaultOptionParam(string customDefaultOption)
+        {
+            if (customDefaultOption != null)
+            {
+                defaultOptionString = customDefaultOption;
+                return;
+            }
+            defaultOptionString = $"-OB RDP=0 BOR_LEV=3 IWDG_SW=1 nRST_STOP=1 nRST_STDBY=1";
+        }
     }
 }