Browse Source

fix PHV MES

Robert 1 year ago
parent
commit
9cc0bed62c

+ 1 - 1
GitVersion.yml

@@ -1,6 +1,6 @@
 assembly-versioning-scheme: MajorMinorPatch
 assembly-informational-format: '{ShortSha}'
-next-version: 1.0.3
+next-version: 1.0.4
 branches: {}
 ignore:
   sha: []

+ 1 - 0
MesAdaptor/ISajetConnect.cs

@@ -13,6 +13,7 @@ namespace MesAdaptor
         bool SajetTransSignIn(ref string data);
         bool SajetTransWoCheck(ref string workOrder);
         bool SajetTransSnCheck(ref string serialNumber);
+        bool SajetTransSnCheck(ref string sn, string model);
         bool SajetTranFinishSuccess();
         bool SajetTranFinishFail(MesErrorCode errorCode);
         string SajetTransRegisterHeader(string model, string header);

+ 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.2.0")]
-[assembly: AssemblyVersion("1.0.2.0")]
-[assembly: AssemblyFileVersion("1.0.2.0")]
-[assembly: AssemblyInformationalVersion("243cda0")]
+// [assembly: AssemblyVersion("1.0.3.0")]
+[assembly: AssemblyVersion("1.0.3.0")]
+[assembly: AssemblyFileVersion("1.0.3.0")]
+[assembly: AssemblyInformationalVersion("7a70bdc")]

+ 5 - 0
MesAdaptor/SajectConnectSajet.cs

@@ -74,6 +74,11 @@ namespace MesAdaptor
             return false;
         }
 
+        public bool SajetTransSnCheck(ref string sn, string model)
+        {
+            throw new NotImplementedException();
+        }
+
         public bool SajetTranFinishSuccess()
         {
             if (string.IsNullOrEmpty(userId))

+ 52 - 11
MesAdaptor/SajectConnectSajet2.cs

@@ -1,6 +1,7 @@
 using PhihongEv.Lib;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -59,7 +60,9 @@ namespace MesAdaptor
             return true;
         }
 
-        private SystemID systemID;
+        //private SystemID systemID;
+        string modelName;
+        string serialNumber;
         public bool SajetTransSnCheck(ref string serialNumber)
         {
             if (!SystemID.TryLooseParse(serialNumber, out var id))
@@ -67,19 +70,48 @@ namespace MesAdaptor
                 return false;
             }
 
-            var msg = string.Format("{0};{1};;", id.ModelName.ToString(), id.ToString());
+            this.modelName = null;
+            this.serialNumber = null;
+            var result = SajetTransSnCheck(ref serialNumber, id.ModelName.ToString());
+            if (result)
+            {
+                this.modelName = id.ModelName.ToString();
+                this.serialNumber = serialNumber;
+            }
+            return result;
+
+            //var msg = string.Format("{0};{1};;", id.ModelName.ToString(), id.ToString());
+
+            //if (SajetTransData(CMD.SnCheck, ref msg))
+            //{
+            //    if (string.IsNullOrEmpty(msg) || msg.StartsWith("NG"))
+            //    {
+            //        systemID = null;
+            //        return false;
+            //    }
+            //    systemID = id;
+            //    return true;
+            //}
+            //systemID = null;
+            //return false;
+        }
+
+        public bool SajetTransSnCheck(ref string sn, string model)
+        {
+            var msg = string.Format("{0};{1};;", model, sn);
 
+            this.serialNumber = null;
+            this.modelName = null;
             if (SajetTransData(CMD.SnCheck, ref msg))
             {
                 if (string.IsNullOrEmpty(msg) || msg.StartsWith("NG"))
                 {
-                    systemID = null;
                     return false;
                 }
-                systemID = id;
+                this.serialNumber = sn;
+                this.modelName = model;
                 return true;
             }
-            systemID = null;
             return false;
         }
 
@@ -100,12 +132,17 @@ namespace MesAdaptor
 
         public bool SajetTranFinishSuccess()
         {
+            //File.AppendAllText("debug.txt", string.Format("userId:{0}", userId));
+            //File.AppendAllText("debug.txt", string.Format("modelName:{0}", modelName));
+            //File.AppendAllText("debug.txt", string.Format("serialNumber:{0}", serialNumber));
             if (string.IsNullOrEmpty(userId))
                 return false;
-            if (systemID == null)
+            if (modelName == null)
+                return false;
+            if (serialNumber == null)
                 return false;
             //string msg = userId + ";" + systemID.ToString() + ";";
-            string msg = string.Format("{0};{1};{2};{3}:0;", userId, _MechineCode, systemID.ModelName.ToString(), systemID.ToString());
+            string msg = string.Format("{0};{1};{2};{3}:0;", userId, _MechineCode, modelName, serialNumber);
 
             if (string.IsNullOrEmpty(msg))
                 return false;
@@ -130,10 +167,12 @@ namespace MesAdaptor
         {
             if (string.IsNullOrEmpty(userId))
                 return false;
-            if (systemID == null)
+            if (modelName == null)
+                return false;
+            if (serialNumber == null)
                 return false;
             //string msg = userId + ";" + systemID.ToString() + ";";
-            string msg = string.Format("{0};{1};{2};{3}:1:", userId, _MechineCode, systemID.ModelName.ToString(), systemID.ToString());
+            string msg = string.Format("{0};{1};{2};{3}:1:", userId, _MechineCode, modelName, serialNumber);
 
             if (string.IsNullOrEmpty(msg))
                 return false;
@@ -168,7 +207,9 @@ namespace MesAdaptor
         {
             if (string.IsNullOrEmpty(userId))
                 return false;
-            if (systemID == null)
+            if (modelName == null)
+                return false;
+            if (serialNumber == null)
                 return false;
 
             var totalResult = true;
@@ -195,7 +236,7 @@ namespace MesAdaptor
                     value = "1";
                 }
 
-                var msg = string.Format("{0};{1};{2};{3};{4}:{5}:{6};", userId, _MechineCode, systemID.ModelName.ToString(), systemID.ToString(), key, value, det);
+                var msg = string.Format("{0};{1};{2};{3};{4}:{5}:{6};", userId, _MechineCode, modelName, serialNumber, key, value, det);
                 var result = SajetTransData(CMD.ValueReport, ref msg);
                 totalResult &= result;
             }

+ 2 - 0
MesAdaptor/SajectConnectTest.cs

@@ -24,6 +24,8 @@ namespace MesAdaptor
 
         public bool SajetTransSnCheck(ref string serialNumber) => true;
 
+        public bool SajetTransSnCheck(ref string sn, string model) => true;
+
         public bool SajetTransStart() => true;
 
         public bool SajetTransWoCheck(ref string workOrder) => true;

+ 3 - 2
MesAdaptor/SajetConnect.cs

@@ -25,6 +25,7 @@ namespace MesAdaptor
         public static bool SajetTransSignIn(ref string data) => Instance.SajetTransSignIn(ref data);
         public static bool SajetTransWoCheck(ref string workOrder) => Instance.SajetTransWoCheck(ref workOrder);
         public static bool SajetTransSnCheck(ref string serialNumber) => Instance.SajetTransSnCheck(ref serialNumber);
+        public static bool SajetTransSnCheck(ref string serialNumber, string model) => Instance.SajetTransSnCheck(ref serialNumber, model);
         public static bool SajetTranFinishSuccess() => Instance.SajetTranFinishSuccess();
         public static bool SajetTranFinishFail(MesErrorCode errorCode) => Instance.SajetTranFinishFail(errorCode);
         public static string SajetTransRegisterHeader(string model, string header) => Instance.SajetTransRegisterHeader(model, header);
@@ -46,11 +47,11 @@ namespace MesAdaptor
                 case "shinewave":
                     SajetConnect.Instance = new SajetConnectShinewave();
                     break;
-                case "phv":
+                //case "phv":
                 case "sajet":
                     SajetConnect.Instance = new SajectConnectSajet();
                     break;
-                //case "phv":
+                case "phv":
                 case "sajet2":
                     SajetConnect.Instance = new SajectConnectSajet2(mechineCode);
                     break;

+ 7 - 0
MesAdaptor/SajetConnectShinewave.cs

@@ -97,6 +97,11 @@ namespace MesAdaptor
             return false;
         }
 
+        public bool SajetTransSnCheck(ref string sn, string model)
+        {
+            throw new NotImplementedException();
+        }
+
         public bool SajetTranFinishSuccess()
         {
             if (string.IsNullOrEmpty(userId))
@@ -204,6 +209,8 @@ namespace MesAdaptor
 
         public bool SajetTransLog(string data)
         {
+            return true;
+
             if (string.IsNullOrEmpty(userId))
                 return false;
             if (string.IsNullOrEmpty(SN))

+ 80 - 37
ST-LINK_MES/MainWindow.xaml

@@ -1,57 +1,100 @@
-<Window x:Class="ST_LINK_MES.MainWindow"
-        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
-        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
-        xmlns:local="clr-namespace:ST_LINK_MES"
-        mc:Ignorable="d"
-        Title="ST-LINK_MES" Height="450" Width="800"
-        Foreground="White" Background="#FF646464"
-        WindowStartupLocation="CenterScreen"
-        FontSize="12">
+<Window
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:local="clr-namespace:ST_LINK_MES"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    Title="ST-LINK_MES"
+    Width="800"
+    Height="450"
+    FontSize="12"
+    Background="#FF646464"
+    Foreground="White"
+    WindowStartupLocation="CenterScreen"
+    mc:Ignorable="d"
+    x:Class="ST_LINK_MES.MainWindow">
     <Grid Margin="10">
         <Grid.RowDefinitions>
-            <RowDefinition Height="Auto"/>
-            <RowDefinition Height="Auto"/>
-            <RowDefinition Height="*"/>
+            <RowDefinition Height="Auto" />
+            <RowDefinition Height="Auto" />
+            <RowDefinition Height="*" />
         </Grid.RowDefinitions>
         <GroupBox Grid.Row="0" Header="User Setting">
             <Grid Margin="5">
                 <Grid.RowDefinitions>
-                    <RowDefinition/>
-                    <RowDefinition Height="5"/>
-                    <RowDefinition/>
+                    <RowDefinition />
+                    <RowDefinition Height="5" />
+                    <RowDefinition />
+                    <RowDefinition Height="5" />
+                    <RowDefinition />
                 </Grid.RowDefinitions>
                 <Grid.ColumnDefinitions>
-                    <ColumnDefinition Width="70"/>
-                    <ColumnDefinition/>
+                    <ColumnDefinition Width="70" />
+                    <ColumnDefinition />
                 </Grid.ColumnDefinitions>
-                <TextBlock Text="SN" VerticalAlignment="Center"/>
-                <TextBlock Grid.Row="2" Text="Bin File" VerticalAlignment="Center"/>
-                <TextBox  x:Name="uxSN" Grid.Column="1" Height="30" VerticalContentAlignment="Center"/>
-                <Grid Grid.Column="1" Grid.Row="2">
+                <TextBlock
+                    Grid.Row="2"
+                    VerticalAlignment="Center"
+                    Text="SN" />
+                <TextBlock
+                    Grid.Row="4"
+                    VerticalAlignment="Center"
+                    Text="Bin File" />
+                <TextBox
+                    x:Name="uxSN"
+                    Grid.Row="2"
+                    Grid.Column="1"
+                    Height="30"
+                    VerticalContentAlignment="Center" />
+                <Grid Grid.Row="4" Grid.Column="1">
                     <Grid.ColumnDefinitions>
-                        <ColumnDefinition Width="29*"/>
-                        <ColumnDefinition Width="287*"/>
-                        <ColumnDefinition Width="50"/>
+                        <ColumnDefinition Width="29*" />
+                        <ColumnDefinition Width="287*" />
+                        <ColumnDefinition Width="50" />
                     </Grid.ColumnDefinitions>
-                    <TextBox x:Name="uxBinFilePath" Height="30" Grid.ColumnSpan="2" Margin="0,5" VerticalContentAlignment="Center"/>
-                    <Button x:Name="uxBinFileBtn" Click="uxBinFileBtn_Click" Grid.Column="2" Width="40" Height="40" Margin="5,0" Content="."/>
+                    <TextBox
+                        x:Name="uxBinFilePath"
+                        Grid.ColumnSpan="2"
+                        Height="30"
+                        Margin="0,5"
+                        VerticalContentAlignment="Center" />
+                    <Button
+                        x:Name="uxBinFileBtn"
+                        Grid.Column="2"
+                        Width="40"
+                        Height="40"
+                        Margin="5,0"
+                        Click="uxBinFileBtn_Click"
+                        Content="." />
                 </Grid>
             </Grid>
         </GroupBox>
-        <Grid  Grid.Row="1" Height="30" Margin="5">
+        <Grid
+            Grid.Row="1"
+            Height="30"
+            Margin="5">
             <Grid.ColumnDefinitions>
-                <ColumnDefinition/>
-                <ColumnDefinition Width="30"/>
-                <ColumnDefinition Width="100"/>
+                <ColumnDefinition />
+                <ColumnDefinition Width="30" />
+                <ColumnDefinition Width="100" />
             </Grid.ColumnDefinitions>
-            <ProgressBar x:Name="uxProgressBar" VerticalAlignment="Center" Height="10"/>
-            <TextBlock Grid.Column="1" Text="0%" VerticalAlignment="Center" HorizontalAlignment="Center"/>
-            <Button Click="uxRunBtn_Click" Grid.Column="2" Content="Run" Background="LightSkyBlue"/>
+            <ProgressBar
+                x:Name="uxProgressBar"
+                Height="10"
+                VerticalAlignment="Center" />
+            <TextBlock
+                Grid.Column="1"
+                HorizontalAlignment="Center"
+                VerticalAlignment="Center"
+                Text="0%" />
+            <Button
+                Grid.Column="2"
+                Background="LightSkyBlue"
+                Click="uxRunBtn_Click"
+                Content="Run" />
         </Grid>
-        <GroupBox  Grid.Row="2" Header="Terminal">
-            <RichTextBox x:Name="uxTerminal" Background="Black"/>
+        <GroupBox Grid.Row="2" Header="Terminal">
+            <RichTextBox x:Name="uxTerminal" Background="Black" />
         </GroupBox>
     </Grid>
 </Window>

+ 21 - 2
ST-LINK_MES/MainWindow.xaml.cs

@@ -58,7 +58,8 @@ namespace ST_LINK_MES
                 LOCK = currentSetting.LOCK,
                 MES = currentSetting.MES,
                 MechineCode = currentSetting.MechineCode,
-                BinPath = uxBinFilePath.Text
+                BinPath = uxBinFilePath.Text,
+                DLinkCliPath = currentSetting.DLinkCliPath,
             };
             currentSetting.Save(setting);
         }
@@ -73,6 +74,11 @@ namespace ST_LINK_MES
             //Reset();
 
             uxBinFilePath.Text = AppSettingService.Instance.BinPath;
+            if (string.IsNullOrEmpty(AppSettingService.Instance.DLinkCliPath))
+            {
+                MessageBox.Show("DLinkCliPath should not be empty");
+            }
+
             if (AppSettingService.Instance.LOCK)
             {
                 uxBinFilePath.IsEnabled = false;
@@ -232,7 +238,7 @@ namespace ST_LINK_MES
         {
             string tmpSN;
             bool bResult = false;
-            tmpSN = uxSN.Text;
+            tmpSN = string.Format("{0}", uxSN.Text);
 
             var mesSetting = AppSettingService.Instance.MES.ToLower();
             if (mesSetting == "php" || mesSetting == "shinewave")
@@ -244,6 +250,19 @@ namespace ST_LINK_MES
                 }
                 return bResult;
             }
+            else if (mesSetting == "phv" || mesSetting == "sajet2")
+            {
+                bResult = SajetConnect.SajetTransSnCheck(ref tmpSN, "");
+                if (!bResult)
+                {
+                    MessageBox.Show("SN not found");
+                }
+                return bResult;
+            }
+            else if (mesSetting == "test")
+            {
+                return true;
+            }
 
             MessageBox.Show("Not supported MES");
             return false;

+ 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.2.0")]
-[assembly: AssemblyVersion("1.0.2.0")]
-[assembly: AssemblyFileVersion("1.0.2.0")]
-[assembly: AssemblyInformationalVersion("243cda0")]
+// [assembly: AssemblyVersion("1.0.3.0")]
+[assembly: AssemblyVersion("1.0.3.0")]
+[assembly: AssemblyFileVersion("1.0.3.0")]
+[assembly: AssemblyInformationalVersion("7a70bdc")]

+ 1 - 1
ST-LINK_MES/Service/STLinkCliWrapService.cs

@@ -42,7 +42,7 @@ namespace ST_LINK_MES.Service
 
         public int Check(string filePath)
         {
-            return RunConsole(cliPath, $"-CmpFile \"{filePath}\"");
+            return RunConsole(cliPath, $"-CmpFile \"{filePath}\" 0x08000000");
         }
 
         public int GetCheckSum(string filePath)