Browse Source

plc 地址数据变更

刘彬 2 weeks ago
parent
commit
44ca485d1f
3 changed files with 164 additions and 48 deletions
  1. 126 23
      Core/Management.cs
  2. 15 2
      Model/CurrConfig.cs
  3. 23 23
      Views/WorkRunView.xaml

+ 126 - 23
Core/Management.cs

@@ -14,6 +14,7 @@ using System;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
+using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Text;
@@ -95,9 +96,13 @@ namespace DefaultEdit.Core
 
         //运行线程
         private Thread  WorkThread;
+
+        private Stopwatch[] stopwatchs = new Stopwatch[3];
         public Management()
         {
-
+            stopwatchs[0] = new Stopwatch();
+            stopwatchs[1] = new Stopwatch();
+            stopwatchs[2] = new Stopwatch();
             for ( int i = 0; i < 6; i++ )
             {
                 CurrStationRfid.Add("");
@@ -125,6 +130,7 @@ namespace DefaultEdit.Core
                 case "1工位离心开始":
                     if ( value )
                     {
+                        stopwatchs[0].Restart();
                         if ( RfIDList.Count != 0 )
                         {
                             int index= RfIDList.FindIndex(x => x.StationId == 1);
@@ -139,18 +145,32 @@ namespace DefaultEdit.Core
 
                                 LogHelper.Info(" 1工位离心开始");
                             }
+                            index = RfIDList.FindIndex(x => x.StationId == 1);
+                            if (index != -1)
+                            {
+                                RfIDList[index].StationId = 2;
+                                CurrStationRfid[2] = RfIDList[index].Rfid;
+                                LogHelper.Info(RfIDList[index].Rfid + " 1工位离心开始");
+                            }
+                            else
+                            {
+
+                                LogHelper.Info(" 1工位离心开始");
+                            }
                         }
+
                     }
                     break;
                 case "1工位离心完成":
                     if ( value )
                     {
+                        stopwatchs[0].Stop();
                         if ( RfIDList.Count != 0 )
                         {
                             int index= RfIDList.FindIndex(x => x.StationId == 2);
                             if ( index != -1 )
                             {
-                                RfIDList[ index ].StationId = 4;
+                                RfIDList[ index ].StationId = 3;
                                 LogHelper.Info(CurrStationRfid[ 1 ] + " 1工位离心完成");
                             }
                             else 
@@ -158,49 +178,90 @@ namespace DefaultEdit.Core
                                 LogHelper.Info(" 1工位离心完成");
 
                             }
+
+                            index = RfIDList.FindIndex(x => x.StationId == 2);
+                            if (index != -1)
+                            {
+                                RfIDList[index].StationId = 3;
+                                LogHelper.Info(CurrStationRfid[2] + " 1工位离心完成");
+                            }
+                            else
+                            {
+                                LogHelper.Info(" 1工位离心完成");
+
+                            }
+                            CurrStationRfid[1] = "";
+                            CurrStationRfid[2] = "";
                         }
                     }
                     break;
                 case "2工位离心开始":
                     if ( value )
                     {
+                        stopwatchs[1].Restart();
                         if ( RfIDList.Count != 0 )
                         {
-                            int index= RfIDList.FindIndex(x => x.StationId == 1);
+                            int index= RfIDList.FindIndex(x => x.StationId == 3);
                             if ( index != -1 )
                             {
-                                RfIDList[ index ].StationId = 3;
-                                CurrStationRfid[ 2 ] = RfIDList[ index ].Rfid;
+                                RfIDList[ index ].StationId = 4;
+                                CurrStationRfid[ 3 ] = RfIDList[ index ].Rfid;
                                 LogHelper.Info(RfIDList[ index ].Rfid + " 2工位离心开始");
                             }
                             else 
                             {
                                 LogHelper.Info( " 2工位离心开始");
                             }
+                            index = RfIDList.FindIndex(x => x.StationId == 1);
+                            if (index != -1)
+                            {
+                                RfIDList[index].StationId = 4;
+                                CurrStationRfid[4] = RfIDList[index].Rfid;
+                                LogHelper.Info(RfIDList[index].Rfid + " 2工位离心开始");
+                            }
+                            else
+                            {
+                                LogHelper.Info(" 2工位离心开始");
+                            }
                         }
                     }
                     break;
                 case "2工位离心完成":
                     if ( value )
                     {
+                        stopwatchs[1].Stop();
                         if ( RfIDList.Count != 0 )
                         {
-                            int index= RfIDList.FindIndex(x => x.StationId == 3);
+                            int index= RfIDList.FindIndex(x => x.StationId == 4);
                             if ( index != -1 )
                             {
-                                RfIDList[ index ].StationId = 4;
-                                LogHelper.Info(CurrStationRfid[ 2 ] + " 2工位离心完成");
+                                RfIDList[ index ].StationId = 5;
+                                LogHelper.Info(CurrStationRfid[ 3 ] + " 2工位离心完成");
                             }
                             else 
                             {
                                 LogHelper.Info(" 2工位离心完成");
                             }
+                            index = RfIDList.FindIndex(x => x.StationId == 4);
+                            if (index != -1)
+                            {
+                                RfIDList[index].StationId = 5;
+                                LogHelper.Info(CurrStationRfid[4] + " 1工位离心完成");
+                            }
+                            else
+                            {
+                                LogHelper.Info(" 1工位离心完成");
+
+                            }
+                            CurrStationRfid[3] = "";
+                            CurrStationRfid[4] = "";
                         }
                     }
                     break;
                 case "脱模开始":
                     if ( value )
                     {
+                        
                         LogHelper.Info(CurrConfig.Rfid + " 脱模开始");
                         PlateInPlace(CurrConfig.Rfid);
                     }
@@ -208,6 +269,7 @@ namespace DefaultEdit.Core
                 case "脱模完成":
                     if ( value )
                     {
+                       
                         LogHelper.Info(CurrConfig.Rfid + " 脱模完成");
                         PrintInfo(processDataModels[0],"");
                     }
@@ -215,28 +277,42 @@ namespace DefaultEdit.Core
                 case "固化开始":
                     if ( value )
                     {
+                        stopwatchs[2].Restart();
                         if ( RfIDList.Count != 0 )
                         {
-                            int index= RfIDList.FindIndex(x => x.StationId ==4 );
+                            int index= RfIDList.FindIndex(x => x.StationId ==5 );
                             if ( index != -1 )
                             {
-                                RfIDList[ index ].StationId = 5;
-                                CurrStationRfid[ 3 ] = RfIDList[ index ].Rfid;
+                                RfIDList[ index ].StationId = 6;
+                                CurrStationRfid[ 5 ] = RfIDList[ index ].Rfid;
                                 LogHelper.Info(RfIDList[ index ].Rfid + " 固化开始");
                             }
                             else 
                             {
                                 LogHelper.Info( " 固化开始");
                             }
+
+                            index = RfIDList.FindIndex(x => x.StationId == 5);
+                            if (index != -1)
+                            {
+                                RfIDList[index].StationId = 6;
+                                CurrStationRfid[6] = RfIDList[index].Rfid;
+                                LogHelper.Info(RfIDList[index].Rfid + " 固化开始");
+                            }
+                            else
+                            {
+                                LogHelper.Info(" 固化开始");
+                            }
                         }
                     }
                     break;
                 case "固化完成":
                     if ( value )
                     {
+                        stopwatchs[2].Stop();
                         if ( RfIDList.Count != 0 )
                         {
-                            int index= RfIDList.FindIndex(x => x.StationId ==5 );
+                            int index= RfIDList.FindIndex(x => x.StationId ==6 );
                             if ( index != -1 )
                             {
                                 RfIDList.RemoveAt(index);
@@ -246,8 +322,21 @@ namespace DefaultEdit.Core
                             {
                                 LogHelper.Info( " 固化完成");
                             }
+
+                            index = RfIDList.FindIndex(x => x.StationId == 6);
+                            if (index != -1)
+                            {
+                                RfIDList.RemoveAt(index);
+                                LogHelper.Info(RfIDList[index].Rfid + " 固化完成");
+                            }
+                            else
+                            {
+                                LogHelper.Info(" 固化完成");
+                            }
+                            //CurrStationRfid[5] = RfIDList[index].Rfid;
+                            //CurrStationRfid[6] = RfIDList[index].Rfid;
                             int hour= DateTime.Now.Hour;
-                            ProduceData[ hour ] = ProduceData[ hour ]+1;
+                            ProduceData[ hour ] = ProduceData[ hour ]+2;
                             for ( int i = hour+1; i < ProduceData.Length; i++ )
                             {
                                 ProduceData[ i ] = 0;  
@@ -299,22 +388,36 @@ namespace DefaultEdit.Core
                         BoolPairs[ "脱模完成" ] = s7PlcCommunicate.GetBitAt(buff, 2, 1);
                         BoolPairs[ "固化开始" ] = s7PlcCommunicate.GetBitAt(buff, 3, 0);
                         BoolPairs[ "固化完成" ] = s7PlcCommunicate.GetBitAt(buff, 3, 1);
-                        CurrConfig.Speed = s7PlcCommunicate.GetShortAt(buff, 12);
-                        CurrConfig.Time = s7PlcCommunicate.GetTimeSpanAt(buff, 16);
-                        CurrConfig.Power1_1 = s7PlcCommunicate.GetShortAt(buff, 20);
-                        CurrConfig.Power1_2 = s7PlcCommunicate.GetShortAt(buff, 22);
-                        CurrConfig.Power1_3 = s7PlcCommunicate.GetShortAt(buff, 24);
-                        CurrConfig.Power1_4 = s7PlcCommunicate.GetShortAt(buff, 26);
-                        CurrConfig.Pressure1 = s7PlcCommunicate.GetRealAt(buff, 36);
-                        CurrConfig.PTime1 = s7PlcCommunicate.GetTimeSpanAt(buff, 44);
-                 
+
+                        //固化压力   792.0
+                        CurrConfig.Pressure1 = s7PlcCommunicate.GetRealAt(buff, 12);
+                        CurrConfig.PTime1 = s7PlcCommunicate.GetTimeSpanAt(buff, 16);
+
+
+                        CurrConfig.Speed = s7PlcCommunicate.GetShortAt(buff, 32);
+                        CurrConfig.Speed2 = s7PlcCommunicate.GetShortAt(buff, 34);
+                        CurrConfig.RealSpeed = s7PlcCommunicate.GetRealAt(buff, 36);
+                        CurrConfig.RealSpeed2 = s7PlcCommunicate.GetRealAt(buff, 40);
+                        CurrConfig.Time = s7PlcCommunicate.GetTimeSpanAt(buff, 44);
+                        CurrConfig.Time = s7PlcCommunicate.GetTimeSpanAt(buff, 48);
+
+                        //CurrConfig.Power1_1 = s7PlcCommunicate.GetShortAt(buff, 20);
+                        //CurrConfig.Power1_2 = s7PlcCommunicate.GetShortAt(buff, 22);
+                        //CurrConfig.Power1_3 = s7PlcCommunicate.GetShortAt(buff, 24);
+                        //CurrConfig.Power1_4 = s7PlcCommunicate.GetShortAt(buff, 26);
+
+                        CurrConfig.Realtime = (float)(stopwatchs[0].ElapsedMilliseconds / 1000.0);
+                        CurrConfig.Realtime2 = (float)(stopwatchs[1].ElapsedMilliseconds / 1000.0);
+                        CurrConfig.Realtime3 = (float)(stopwatchs[2].ElapsedMilliseconds / 1000.0);
+                       
                     }
+
                 }
                 catch
                 {
 
                 }
-
+                Thread.Sleep(50);
             }
         }
 

+ 15 - 2
Model/CurrConfig.cs

@@ -17,6 +17,13 @@ namespace DefaultEdit.Model
         private float _Speed2;
         private TimeSpan _Time2;
 
+
+        private float realSpeed = 0;
+        private float realSpeed2 = 0;
+
+        private float realtime ;
+        private float realtime2 ;
+        private float realtime3;
         private short _Power1_1;
         private short _Power1_2;
         private short _Power1_3;
@@ -30,7 +37,9 @@ namespace DefaultEdit.Model
 
 
         public float Speed { get => _Speed; set { SetProperty(ref _Speed, value); } }
+        public float Speed2 { get => _Speed2; set { SetProperty(ref _Speed2, value); } }
         public TimeSpan Time { get => _Time; set { SetProperty(ref _Time, value); } }
+        public TimeSpan Time2 { get => _Time2; set { SetProperty(ref _Time2, value); } }
         public short Power1_1 { get => _Power1_1; set { SetProperty(ref _Power1_1, value); } }
         public short Power1_2 { get => _Power1_2; set { SetProperty(ref _Power1_2, value); } }
         public short Power1_3 { get => _Power1_3; set { SetProperty(ref _Power1_3, value); } }
@@ -42,7 +51,11 @@ namespace DefaultEdit.Model
 
         public string Rfid { get => _Rfid; set { SetProperty(ref _Rfid, value); } }
 
-        public float Speed2 { get => _Speed2; set { SetProperty(ref _Speed2, value); } }
-        public TimeSpan Time2 { get => _Time2; set { SetProperty(ref _Time2, value); } }
+        public float RealSpeed { get => realSpeed; set { SetProperty(ref realSpeed, value); } }
+        public float RealSpeed2 { get => realSpeed2; set { SetProperty(ref realSpeed2, value); } }
+        public float Realtime { get => realtime; set { SetProperty(ref realtime, value); } }
+        public float Realtime2 { get => realtime2; set { SetProperty(ref realtime2, value); } }
+
+        public float Realtime3 { get => realtime3; set { SetProperty(ref realtime3, value); } }
     }
 }

+ 23 - 23
Views/WorkRunView.xaml

@@ -73,7 +73,7 @@
                       Height="300">
                     <scottplot:WpfPlot Name="plot"
                                        Grid.Column="0"
-                                       Margin="1337,-272,-1337,272" />
+                                        />
                 </Grid>
                 <Grid Grid.Column="2"
                       Margin="0,20,0,0">
@@ -97,7 +97,7 @@
                                Margin="0,0,80,0"
                                Grid.Row="0"
                                Grid.Column="0" />
-                    <TextBlock Text=""
+                    <TextBlock Text="{Binding Management.CurrStationRfid[0]}"
                                Margin="0,0,80,0"
                                Grid.Row="0"
                                Grid.Column="0" />
@@ -105,30 +105,30 @@
 
 
 
-                    <TextBlock Text="离心工位1-1"
+                    <TextBlock Text="离心工位#1-1"
                                Grid.Row="2"
                                Grid.Column="0" />
-                    <TextBlock Text="离心工位1-2"
+                    <TextBlock Text="离心工位#1-2"
                                Grid.Row="2"
                                Grid.Column="1" />
-                    <TextBlock Text="{Binding Management.CurrStationRfid[0]}"
+                    <TextBlock Text="{Binding Management.CurrStationRfid[1]}"
                                Grid.Row="1"
                                Grid.Column="0" />
-                    <TextBlock Text="{Binding Management.CurrStationRfid[1]}"
+                    <TextBlock Text="{Binding Management.CurrStationRfid[2]}"
                                Grid.Row="1"
                                Grid.Column="1" />
 
 
-                    <TextBlock Text="离心工位1-1"
+                    <TextBlock Text="离心工位#2-1"
                                Grid.Row="4"
                                Grid.Column="0" />
-                    <TextBlock Text="离心工位1-2"
+                    <TextBlock Text="离心工位#2-2"
                                Grid.Row="4"
                                Grid.Column="1" />
-                    <TextBlock Text="{Binding Management.CurrStationRfid[0]}"
+                    <TextBlock Text="{Binding Management.CurrStationRfid[3]}"
                                Grid.Row="5"
                                Grid.Column="0" />
-                    <TextBlock Text="{Binding Management.CurrStationRfid[1]}"
+                    <TextBlock Text="{Binding Management.CurrStationRfid[4]}"
                                Grid.Row="5"
                                Grid.Column="1" />
 
@@ -139,10 +139,10 @@
                     <TextBlock Text="#1固化工位#2"
                                Grid.Row="6"
                                Grid.Column="1" />
-                    <TextBlock Text=""
+                    <TextBlock Text="{Binding Management.CurrStationRfid[5]}"
                                Grid.Row="7"
                                Grid.Column="0" />
-                    <TextBlock Text=""
+                    <TextBlock Text="{Binding Management.CurrStationRfid[6]}"
                                Grid.Row="7"
                                Grid.Column="1" />
 
@@ -196,14 +196,14 @@
                                   Grid.Column="0">
                         <TextBlock Text="离心1转速"
                                    Margin="0,0,80,0" />
-                        <TextBlock Text="{Binding Management.CurrConfig.Speed}"
+                        <TextBlock Text="{Binding Management.CurrConfig.RealSpeed}"
                                    Margin="0,0,80,0" />
                     </StackPanel>
                     <StackPanel   Grid.Row="0"
                                   Grid.Column="1">
                         <TextBlock Text="离心1时间"
                                    Margin="0,0,80,0" />
-                        <TextBlock Text="{Binding Management.CurrConfig.Time,StringFormat=hh\\:mm\\:ss}"
+                        <TextBlock Text="{Binding Management.CurrConfig.Realtime}"
                                    Margin="0,0,80,0" />
                     </StackPanel>
 
@@ -211,7 +211,7 @@
                                   Grid.Column="2">
                         <TextBlock Text="离心2转速"
                                    Margin="0,0,80,0" />
-                        <TextBlock Text="{Binding Management.CurrConfig.Power1_1}"
+                        <TextBlock Text="{Binding Management.CurrConfig.RealSpeed2}"
                                    Margin="0,0,80,0" />
                     </StackPanel>
 
@@ -219,7 +219,7 @@
                                   Grid.Column="3">
                         <TextBlock Text="离心2时间"
                                    Margin="0,0,80,0" />
-                        <TextBlock Text="{Binding Management.CurrConfig.Power1_2}"
+                        <TextBlock Text="{Binding Management.CurrConfig.Realtime2}"
                                    Margin="0,0,80,0" />
                     </StackPanel>
                  
@@ -228,14 +228,14 @@
                                   Grid.Column="0">
                         <TextBlock Text="固化箱压力"
                                    Margin="0,0,80,0" />
-                        <TextBlock Text="{Binding Management.CurrConfig.PTime1}"
+                        <TextBlock Text="{Binding Management.CurrConfig.Pressure1}"
                                    Margin="0,0,80,0" />
                     </StackPanel>
                     <StackPanel   Grid.Row="1"
                                   Grid.Column="1">
                         <TextBlock Text="光固化时间"
                                    Margin="0,0,80,0" />
-                        <TextBlock Text="{Binding Management.CurrConfig.PTime2}"
+                        <TextBlock Text="{Binding Management.CurrConfig.Realtime3}"
                                    Margin="0,0,80,0" />
                     </StackPanel>
                 </Grid>
@@ -289,35 +289,35 @@
                         <TextBlock Text="第一次离心转速"
                                    Grid.Row="1"
                                    Grid.Column="0" />
-                        <TextBlock Text="180"
+                        <TextBlock Text="{Binding Management.CurrConfig.Speed}"
                                    Grid.Row="1"
                                    Grid.Column="1" />
 
                         <TextBlock Text="第一次离心时间"
                                    Grid.Row="2"
                                    Grid.Column="0" />
-                        <TextBlock Text="180"
+                        <TextBlock Text="{Binding Management.CurrConfig.Time,StringFormat=ss}"
                                    Grid.Row="2"
                                    Grid.Column="1" />
 
                         <TextBlock Text="第二次离心转速"
                                    Grid.Row="3"
                                    Grid.Column="0" />
-                        <TextBlock Text="180"
+                        <TextBlock Text="{Binding Management.CurrConfig.Speed2}"
                                    Grid.Row="3"
                                    Grid.Column="1" />
 
                         <TextBlock Text="第二次离心时间"
                                    Grid.Row="4"
                                    Grid.Column="0" />
-                        <TextBlock Text="180"
+                        <TextBlock Text="{Binding Management.CurrConfig.Time,StringFormat=ss}"
                                    Grid.Row="4"
                                    Grid.Column="1" />
                         
                         <TextBlock Text="光固化时间"
                                    Grid.Row="5"
                                    Grid.Column="0" />
-                        <TextBlock Text="180"
+                        <TextBlock Text="{Binding Management.CurrConfig.PTime1,StringFormat=ss}"
                                    Grid.Row="5"
                                    Grid.Column="1" />
                     </Grid>