Browse Source

add wago simulator AI/AO input ablility

chenzk 2 months ago
parent
commit
719e21ed9e

+ 1 - 1
CyberX8_RT/Config/Devices/WagoControllerCfg-Simulator.xml

@@ -24,7 +24,7 @@
 				<DI Name="DI17"  Address="17" Invert="false"/>
 				<DI Name="r_LOADERA_DOOR_UPPER_LOCKED"  Address="18" Invert="false"/>
 				<DI Name="r_LoaderA_Wafer_Present"  Address="19" Invert="false"/>
-				<DI Name="DI20"  Address="20" Invert="false"/>
+				<DI Name="r_DRIP_TRAY_FLUID_DETECTION"  Address="20" Invert="false"/>
 			</DIGroup>
 		</Dig_In>
 		<Dig_Out>

+ 56 - 14
CyberX8_Simulator/Devices/WagoSocketSimulator.cs

@@ -12,23 +12,30 @@ namespace CyberX8_Simulator.Devices
     public class WagoSocketSimulator : SocketDeviceSimulator
     {
         private const short WRITE_DO_STARTADDRESS = 0x0200;
-        private const short WRITE_AO_STARTADDRESS = 0x0200;
-       
-        
+        private const short WRITE_AO_STARTADDRESS = 0x0200;
+
+        //键是名字,值是对应数据所在的位置  注意:要和WagoControlCfg里面的地址顺序对上
+        private Dictionary<string, int> DONameIndexDic = new Dictionary<string, int>
+        {{"DO0",0 },{"c_LoaderA_LS_Vacuum",1} };
+        private Dictionary<string, int> DINameIndexDic = new Dictionary<string, int>
+        {{"r_DRIP_TRAY_FLUID_DETECTION",19 },{"DI1",1} };
+        private Dictionary<string, int> AINameIndexDic = new Dictionary<string, int>
+        {{"r_LoaderA_LS_Vacuum_anlg",0 },{"AI1",1} };
+        private Dictionary<string, int> AONameIndexDic = new Dictionary<string, int>
+        {{"AO0",0 },{"AO1",1} };
+
         private IByteTransform byteTransform = new BigEndianByteTransformBase();
 
         private byte[] DOBytes = new byte[100];
-        //键是名字,值是对应DoByte所在的位置
-        private Dictionary<string,int> DONameIndexDic = new Dictionary<string, int>
-        {{"DO0",0 },{"c_LoaderA_LS_Vacuum",1} };
-        private Dictionary<string, int> DINameIndexDic = new Dictionary<string, int>
-        {{"DI0",0 },{"DI1",1} };
 
         private short[] AOShorts = new short[50];
 
         private byte[] DIBytes = new byte[100];
 
         private short[] AIShorts = new short[50];
+
+
+
         /// <summary>
         /// 写DO锁
         /// </summary>
@@ -48,8 +55,7 @@ namespace CyberX8_Simulator.Devices
         /// </summary>
         private void InitializeData()
         {
-            AIShorts[3] = 0x1388;
-            DIBytes[2] = 0x01;
+            AIShorts[0] = 0x1388;
         }
 
         #region 公共方法
@@ -57,23 +63,59 @@ namespace CyberX8_Simulator.Devices
         {
             if (DONameIndexDic.ContainsKey(name))
             {
-                DOBytes[DONameIndexDic[name]] = value == 0 ? (byte)0 : (byte)1; 
+                if (DONameIndexDic[name] < DOBytes.Length)
+                {
+                    DOBytes[DONameIndexDic[name]] = value == 0 ? (byte)0 : (byte)1;
+                }
             }
         }
         public void UpdataDIBytes(string name, int value)
         {
             if (DINameIndexDic.ContainsKey(name))
             {
-                DIBytes[DONameIndexDic[name]] = value == 0 ? (byte)0 : (byte)1;
+                if (DINameIndexDic[name] < DIBytes.Length)
+                {
+                    DIBytes[DINameIndexDic[name]] = value == 0 ? (byte)0 : (byte)1;
+                }
             }
         }
         public void UpdataAOShorts(string name, int value)
         {
-          
+            if (AONameIndexDic.ContainsKey(name))
+            {
+                string hexValue = value.ToString("X2");
+                try
+                {
+                    short result = Convert.ToInt16(hexValue, 16);
+                    if (AONameIndexDic[name] < AOShorts.Length)
+                    {
+                        AOShorts[AONameIndexDic[name]] = result;
+                    }
+                }
+                catch (FormatException)
+                {
+
+                }
+            }
         }
         public void UpdataAIShorts(string name, int value)
         {
-           
+            if (AINameIndexDic.ContainsKey(name))
+            {
+                string hexValue = value.ToString("X2");
+                try
+                {
+                    short result = Convert.ToInt16(hexValue, 16);
+                    if(AINameIndexDic[name] < AIShorts.Length)
+                    {
+                        AIShorts[AINameIndexDic[name]] = result;
+                    }
+                }
+                catch (FormatException)
+                {
+                   
+                }
+            }
         }
         #endregion
 

+ 2 - 2
CyberX8_Simulator/Views/WagoView.xaml

@@ -36,13 +36,13 @@
             <StackPanel Orientation="Horizontal" Width="500" Height="50" Canvas.Top="50" Canvas.Left="120">
                 <Label Content="AO:" VerticalAlignment="Center"></Label>
                 <ComboBox  Width="250" Height="30" VerticalContentAlignment="Center" ItemsSource="{Binding AONameItems}" SelectedItem="{Binding AOSelectedItem}" />
-                <TextBox Text="{Binding AOInputValue,Mode=OneWayToSource}" Width="60" Height="30" Margin="5,0,0,0" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"></TextBox>
+                <TextBox Text="{Binding AOInputValue,Mode=OneWayToSource}" Width="100" Height="30" Margin="5,0,0,0" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"></TextBox>
                 <Button Content="AoInput" Height="30" Width="100" Margin="5,10,0,0" Command="{Binding SetAOCommand}"/>
             </StackPanel>
             <StackPanel Orientation="Horizontal" Width="500" Height="50" Canvas.Top="50" Canvas.Left="620">
                 <Label Content="AI:" VerticalAlignment="Center"></Label>
                 <ComboBox  Width="250" Height="30" VerticalContentAlignment="Center" ItemsSource="{Binding AINameItems}" SelectedItem="{Binding AISelectedItem}" />
-                <TextBox Text="{Binding AIInputValue,Mode=OneWayToSource}" Width="60" Height="30" Margin="5,0,0,0" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"></TextBox>
+                <TextBox Text="{Binding AIInputValue,Mode=OneWayToSource}" Width="100" Height="30" Margin="5,0,0,0" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"></TextBox>
                 <Button Content="AIInput" Height="30" Width="100" Margin="5,10,0,0" Command="{Binding SetAICommand}"/>
             </StackPanel>
 

+ 3 - 3
CyberX8_Simulator/Views/WagoView.xaml.cs

@@ -199,7 +199,7 @@ namespace CyberX8_Simulator.Views
         }
         private void SetAOAction(object obj)
         {
-            _sim.UpdataAOShorts(AISelectedItem, AIInputValue);
+            _sim.UpdataAOShorts(AOSelectedItem, AOInputValue);
         }
 
         private void InitData()
@@ -212,11 +212,11 @@ namespace CyberX8_Simulator.Views
                 "c_LOADERA_DOOR_UNLOCK","DO20","DO21"};
             
             DINameItems = new ObservableCollection<string>
-            { "r_Cassette_1_150","r_Cassette_1_100"};
+            { "r_Cassette_1_150","r_Cassette_1_100","r_DRIP_TRAY_FLUID_DETECTION"};
 
             AONameItems = new ObservableCollection<string> { "AO0", "AO1" };
 
-            AINameItems = new ObservableCollection<string> { "AI0", "AI1" };
+            AINameItems = new ObservableCollection<string> { "r_LoaderA_LS_Vacuum_anlg", "AI1" };
         }
     }