浏览代码

Optimize Wago、Galil、Festo、MotorSimulator;

niuyx 1 月之前
父节点
当前提交
bda980a60f

+ 7 - 6
CyberX8_RT/Config/Devices/WagoControllerCfg-Simulator.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <WagoControllerConfig>
-	<WagoDeviceConfig Module="Wago0" IpAddress="127.0.0.1" Port="501" SendTimeout="2000" RecvTimeout="2000" Channel="1">
+	<WagoDeviceConfig Module="Loader" IpAddress="127.0.0.1" Port="501" SendTimeout="2000" RecvTimeout="2000" Channel="1">
 		<Dig_In>
 			<DIGroup Name="N5">
 				<DI Name="r_Cassette_1_150" Address="0" Invert="false"/>
@@ -20,7 +20,7 @@
 				<DI Name="r_Dummy_2_200"  Address="14" Invert="false"/>
 				<DI Name="DI15"  Address="15" Invert="false"/>
 			</DIGroup>
-			<DIGroup Name="N5">
+			<DIGroup Name="N6">
 				<DI Name="r_LoaderA_Wafer_Present"  Address="16" Invert="false"/>
 				<DI Name="r_LoaderB_Wafer_Present"  Address="17" Invert="false"/>
 				<DI Name="r_Cathode_Present"  Address="18" Invert="false"/>
@@ -47,8 +47,8 @@
 				<DO Name="c_Pole_Green"  Address="515" Invert="false"/>
 				<DO Name="c_Pole_Blue"  Address="516" Invert="false"/>
 				<DO Name="c_System_Alarm2"  Address="517" Invert="false"/>
-				<DO Name="c_BACKSIDE_PRESSURE_TEST"  Address="518" Invert="false"/>
-				<DO Name="c_VACUUM_TEST"  Address="519" Invert="false"/>
+				<DO Name="c_VACUUM_TEST"  Address="518" Invert="false"/>
+				<DO Name="DO7"  Address="519" Invert="false"/>
 				<DO Name="DO8"  Address="520" Invert="false"/>
 				<DO Name="DO9"  Address="521" Invert="false"/>
 				<DO Name="DO10"  Address="522" Invert="false"/>
@@ -76,10 +76,11 @@
 				<AI Name="AI1"  Address="0" Scaling="0=3276.7,-757=16383.5" DataType="short"/>
 				<AI Name="AI2"  Address="1" DataType="short"/>
 				<AI Name="AI3"  Address="2" DataType="short"/>
+				<AI Name="AI4"  Address="3" DataType="short"/>
 				<AI Name="r_LoaderA_LS_Vacuum_anlg"  Address="4" Scaling="0=3276.7,-757=16383.5" DataType="short"/>
 				<AI Name="r_LoaderB_LS_Vacuum_anlg"  Address="5" Scaling="0=3276.7,-757=16383.5" DataType="short"/>
-				<AI Name="AI6"  Address="5" DataType="short"/>
-				<AI Name="r_LOADER_GasFlowSensor_FLOW"  Address="7" Scaling="1=0,5=500" DataType="short"/>
+				<AI Name="AI6"  Address="6" DataType="short"/>
+				<AI Name="r_LOADER_GasFlowSensor_FLOW"  Address="7" Scaling="0=3370, 500=17000" DataType="short"/>
 			</AIGroup>
 			<AIGroup Name="N2">
 				<AI Name="r_LOADERA_BERNOULLI_PRESSURE"  Address="8" Scaling="0=3276.7, 145=16383.5" DataType="short"/>

+ 22 - 12
CyberX8_Simulator/Devices/FestoSocketSimulator.cs

@@ -1,6 +1,6 @@
 using Aitex.Common.Util;
 using Aitex.Core.RT.Device;
-using Aitex.Core.RT.IOCore;
+using Aitex.Core.RT.Log;
 using Aitex.Core.Util;
 using MECF.Framework.Common.Device.Festo;
 using MECF.Framework.Common.Net;
@@ -8,8 +8,6 @@ using MECF.Framework.Simulator.Core.Driver;
 using System;
 using System.Collections.Generic;
 using System.IO;
-using System.Net;
-using Xceed.Wpf.Toolkit.PropertyGrid.Attributes;
 
 namespace CyberX8_Simulator.Devices
 {
@@ -218,21 +216,33 @@ namespace CyberX8_Simulator.Devices
                 _festoOutputDataDic[i] = 0x00;
             }
             //加载对应配置文件 FestoControllerCfg-Simulator.xml
-            string oldXmlPath = PathManager.GetCfgDir();
-            string newXmlPath = oldXmlPath.Replace("CyberX8_Simulator", "CyberX8_RT") + "Devices\\FestoControllerCfg-Simulator.xml";
-            FestoControllerCfg cfg = CustomXmlSerializer.Deserialize<FestoControllerCfg>(new FileInfo(newXmlPath));
-            foreach (FestoDeviceConfig config in cfg.FestoDeviceConfigs)
+            try
             {
-                if (port == config.Port)
+                string oldXmlPath = PathManager.GetCfgDir();
+                string newXmlPath = oldXmlPath.Replace("CyberX8_Simulator", "CyberX8_RT") + "Devices\\FestoControllerCfg-Simulator.xml";
+                FestoControllerCfg cfg = CustomXmlSerializer.Deserialize<FestoControllerCfg>(new FileInfo(newXmlPath));
+                if (cfg != null)
                 {
-                    foreach (FestoDO item in config.FestoDoes)
+                    foreach (FestoDeviceConfig config in cfg.FestoDeviceConfigs)
                     {
-                        _festoNameIndexDic[item.Name] = item;
-                        string str = $"{item.Address}-{item.Bit}";
-                        _doNameDictionary[str] = item.Name;
+                        if (port == config.Port)
+                        {
+                            foreach (FestoDO item in config.FestoDoes)
+                            {
+                                _festoNameIndexDic[item.Name] = item;
+                                string str = $"{item.Address}-{item.Bit}";
+                                _doNameDictionary[str] = item.Name;
+                            }
+                        }
                     }
                 }
             }
+            catch
+            {
+                LOG.WriteLog(eEvent.ERR_FESTO, "Festo", "Load festo FestoControllerCfg-Simulator.xml failed");
+            }
+            
+            
         }
     }
 }

+ 52 - 30
CyberX8_Simulator/Devices/GalilSocketSimulator.cs

@@ -1,4 +1,5 @@
 using Aitex.Common.Util;
+using Aitex.Core.RT.Log;
 using Aitex.Core.Util;
 using MECF.Framework.Common.Beckhoff.AxisProvider;
 using MECF.Framework.Common.Device.Galil;
@@ -21,9 +22,12 @@ namespace CyberX8_Simulator.Devices
         //GalilControllerData最大数据长度
         private const int MAX_CONTROL_DATA_LENGTH_21 = 264;
         private const int MAX_CONTROL_DATA_LENGTH_40 = 366;
-       //GalilAxisData最大数据长度
-       private const int MAX_AXIS_DATA_LENGTH_21 = 28;
+        //GalilAxisData最大数据长度
+        private const int MAX_AXIS_DATA_LENGTH_21 = 28;
         private const int MAX_AXIS_DATA_LENGTH_40 = 36;
+        //GalilType
+        private const string GALIL_21 = "Galil21";
+        private const string GALIL_40 = "Galil40";
 
         private const string TARGET_VELOCITY = "TargetVelocity";
         private const string TARGET_ACCEL = "TargetAcceleration";
@@ -34,10 +38,7 @@ namespace CyberX8_Simulator.Devices
         private const string AUXILIARY_POSITION = "AuxiliaryPosition";
         private const string HOMING_SIGNAL = "HomingSignal";
         private const string MOTION_SIGNAL = "MotionSignal";
-        private const string STOP_SIGNAL = "StopSignal";
-        private const double MOTOR_POSITION_FACTOR = 31.25;
-        private const string GALIL_21 = "Galil21";
-        private const string GALIL_40 = "Galil40";
+        private const string STOP_SIGNAL = "StopSignal";      
        
         #endregion
 
@@ -189,46 +190,66 @@ namespace CyberX8_Simulator.Devices
             for (int i = 0; i < MAX_AXIS_NUM; i++)
             {
                 _galilControlData.GalilAxisDatas.Add(new GalilAxisData());
-                _galilControlData.GalilAxisDatas[i].Status = 0x01;
+                _galilControlData.GalilAxisDatas[i].Status = 0x00;
             }
             _galilControlData.Inputs  = new byte[10];
-            _galilControlData.Outputs = new byte[10]; 
-            
+            _galilControlData.Outputs = new byte[10];             
             
             //电机数据更新事件
             MotorSimulator.Instance.OnUpdateVariableValueChanged += UpdataRealTimeMotionData;
-            //加载对应配置文件 GalilControllerCfg-Simulator.xml
-            string oldXmlPath = PathManager.GetCfgDir();
-            string newXmlPath = oldXmlPath.Replace("CyberX8_Simulator", "CyberX8_RT") + "Devices\\GalilControllerCfg-Simulator.xml";
-            GalilControllerCfg cfg = CustomXmlSerializer.Deserialize<GalilControllerCfg>(new FileInfo(newXmlPath));
-            foreach (GalilDeviceConfig config in cfg.GalilDeviceConfigs)
+
+            //加载GalilControllerCfg-Simulator.xml
+            try
             {
-                if (port == config.Port)
+                string oldXmlPath = PathManager.GetCfgDir();
+                string newXmlPath = oldXmlPath.Replace("CyberX8_Simulator", "CyberX8_RT") + "Devices\\GalilControllerCfg-Simulator.xml";
+                GalilControllerCfg cfg = CustomXmlSerializer.Deserialize<GalilControllerCfg>(new FileInfo(newXmlPath));
+                if(cfg != null)
                 {
-                    _moduleName = config.Module;
-                    _galilType = config.GalilType;                   
-                    foreach (GalilAxisConfig item in config.GalilAxises)
+                    foreach (GalilDeviceConfig config in cfg.GalilDeviceConfigs)
                     {
-                        _axisNameIndexDic[$"{config.Module}.{item.Name}"] = item.Index;
-                        _nameAxisList[item.Index] = $"{config.Module}.{item.Name}";
+                        if (port == config.Port)
+                        {
+                            _moduleName = config.Module;
+                            _galilType = config.GalilType;
+                            foreach (GalilAxisConfig item in config.GalilAxises)
+                            {
+                                _axisNameIndexDic[$"{config.Module}.{item.Name}"] = item.Index;
+                                _nameAxisList[item.Index] = $"{config.Module}.{item.Name}";
+                            }
+                        }
                     }
-                }
+                }               
+            }
+            catch
+            {
+                LOG.WriteLog(eEvent.ERR_GALIL, "Galil", "Load galil GalilControllerCfg-Simulator.xml failed");
             }
             //加载AxisProviderCfg.xml
-            oldXmlPath = PathManager.GetCfgDir();
-            newXmlPath = oldXmlPath.Replace("CyberX8_Simulator", "CyberX8_RT") + "Devices\\AxisProviderCfg.xml";
-            BeckhoffAxisProviderCfg axisProviderCfg = CustomXmlSerializer.Deserialize<BeckhoffAxisProviderCfg>(new FileInfo(newXmlPath));
-            foreach(BeckhoffProviderAxis item in axisProviderCfg.Axes)
+            try
             {
-                for (int i = 0; i < MAX_AXIS_NUM; i++)
+                string oldXmlPath = PathManager.GetCfgDir();
+                string newXmlPath = oldXmlPath.Replace("CyberX8_Simulator", "CyberX8_RT") + "Devices\\AxisProviderCfg.xml";
+                BeckhoffAxisProviderCfg axisProviderCfg = CustomXmlSerializer.Deserialize<BeckhoffAxisProviderCfg>(new FileInfo(newXmlPath));
+                if (axisProviderCfg != null)
                 {
-                    if (_nameAxisList[i] == item.Name)
+                    foreach (BeckhoffProviderAxis item in axisProviderCfg.Axes)
                     {
-                        _motorPositionRateDic[item.Name] = item.MotorPositionRate;
+                        for (int i = 0; i < MAX_AXIS_NUM; i++)
+                        {
+                            if (_nameAxisList[i] == item.Name)
+                            {
+                                _motorPositionRateDic[item.Name] = item.MotorPositionRate;
+                            }
+                        }
                     }
-                }                   
+                }
             }
-
+            catch
+            {
+                LOG.WriteLog(eEvent.ERR_AXIS, "axisProvider", "Load AxisProviderCfg.xml failed");
+            }
+            //初始化对应Galiltype数据       
             if (_galilType == GALIL_40)
             {
                 _controlDataLength = MAX_CONTROL_DATA_LENGTH_40;
@@ -552,6 +573,7 @@ namespace CyberX8_Simulator.Devices
             _galilControlData.GalilAxisDatas[index].Torque = data.ActualTorque;
             _galilControlData.GalilAxisDatas[index].StopCode = data.StopCode;
         }
+
         #region AxisOperation
         /// <summary>
         /// 开/关电机

+ 72 - 118
CyberX8_Simulator/Devices/WagoSocketSimulator.cs

@@ -1,14 +1,13 @@
-using Aitex.Core.RT.Device;
+using Aitex.Common.Util;
+using Aitex.Core.RT.Device;
+using Aitex.Core.RT.Log;
+using Aitex.Core.Util;
+using MECF.Framework.Common.Device.Wago;
 using MECF.Framework.Common.Net;
 using MECF.Framework.Simulator.Core.Driver;
 using System;
 using System.Collections.Generic;
-using System.Diagnostics.Eventing.Reader;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using System.Timers;
+using System.IO;
 
 namespace CyberX8_Simulator.Devices
 {
@@ -79,120 +78,75 @@ namespace CyberX8_Simulator.Devices
         /// </summary>
         private void InitializeData(int port)  //端口用于初始化不同Wago设备的字典
         {
-            switch (port)
+            //加载对应配置文件 WagoControllerCfg-Simulator.xml
+            try
             {
-                case 501:
-                    DONameIndexDic = new Dictionary<string, int>
-                    {{"c_System_Alarm",0 },
-                     {"c_Pole_Red",1},
-                     {"c_Pole_Amber",2},
-                     {"c_Pole_Green",3},
-                     {"c_Pole_Blue",4},
-                     {"c_System_Alarm2",5},
-                     {"c_BACKSIDE_PRESSURE_TEST",6},
-                     {"c_VACUUM_TEST",7},
-                     {"DO8",8},
-                     {"DO9",9},
-                     {"DO10",10},
-                     {"DO11",11},
-                     {"DO12",12},
-                     {"DO13",13},
-                     {"DO14",14},
-                     {"DO15",15},
-                     {"DO16",16},
-                     {"DO17",17},
-                     {"DO18",18},
-                     {"DO19",19},
-                     {"DO20",20},
-                     {"DO21",21}};
-
-                    DINameIndexDic = new Dictionary<string, int>
-                    {{"r_Cassette_1_150",0 },
-                     {"r_Cassette_1_100",1},
-                     {"r_Cassette_1_200",2},
-                     {"r_Cassette_2_150",3},
-                     {"r_Cassette_2_100",4},
-                     {"r_Cassette_2_200",5},
-                     {"r_Cassette_3_150",6},
-                     {"r_Cassette_3_100",7},
-                     {"r_Cassette_3_200",8 },
-                     {"r_Dummy_1_150",9},
-                     {"r_Dummy_1_100",10},
-                     {"r_Dummy_1_200",11},
-                     {"r_Dummy_2_150",12},
-                     {"r_Dummy_2_100",13},
-                     {"r_Dummy_2_200",14},
-                     {"DI15",15},
-                     {"r_LoaderA_Wafer_Present",16},
-                     {"r_LoaderB_Wafer_Present",17},
-                     {"r_Cathode_Present",18},
-                     {"DI19",19},
-                     {"DI20",20},
-                     {"DI21",21},
-                     {"DI22",22},
-                     {"DI23",23},
-                     {"DI24",24},
-                     {"DI25",25},
-                     {"r_LOADERA_CRS_CURTAIN_1",26},
-                     {"r_LOADERA_CRS_CURTAIN_2",27},
-                     {"r_LOADERA_CRS_CURTAIN_3",28},
-                     {"r_LOADERA_CRS_CURTAIN_4",29},
-                     {"r_LOADERA_CRS_CURTAIN_5",30},
-                     {"r_LOADERA_CRS_CURTAIN_6",31}};
-
-                    AINameIndexDic = new Dictionary<string, int>
-                    {{"AI1",0 },
-                     {"AI2",1},
-                     {"AI3",2},
-                     {"r_LoaderA_LS_Vacuum_anlg",3},
-                     {"r_LoaderB_LS_Vacuum_anlg",4},
-                     {"AI6",5},
-                     {"r_LOADER_GasFlowSensor_FLOW",6},
-                     {"r_LOADERA_BERNOULLI_PRESSURE",7},
-                     {"r_LOADERB_BERNOULLI_PRESSURE",8},
-                     {"r_LOADERA_CHUCK_BLADDER",9},
-                     {"r_LOADERB_CHUCK_BLADDER",10},
-                     {"r_LOADERA_WS_BLADDER_PRESSURE",11},
-                     {"r_LOADERB_WS_BLADDER_PRESSURE",12},
-                     {"r_SPUF_VAC",13},
-                     {"r_LOADER_GasFlowSensor_VACUUM",14},};
+                string oldXmlPath = PathManager.GetCfgDir();
+                string newXmlPath = oldXmlPath.Replace("CyberX8_Simulator", "CyberX8_RT") + "Devices\\WagoControllerCfg-Simulator.xml";
+                WagoControllerCfg cfg = CustomXmlSerializer.Deserialize<WagoControllerCfg>(new FileInfo(newXmlPath));
+                if (cfg != null)
+                {
+                    foreach (WagoDeviceConfig config in cfg.WagoDeviceConfigs)
+                    {
+                        if (port == config.Port)
+                        {
+                            //加载DO
+                            int i = 0;
+                            DONameIndexDic = new Dictionary<string, int>();
+                            foreach (var group in config.WagoDigOut.WagoDOGroups)
+                            {
+                                foreach (var item in group.WagoDOs)
+                                {
+                                    DONameIndexDic[item.Name] = i;
+                                }
+                            }
+                            //加载DI
+                            i = 0;
+                            DINameIndexDic = new Dictionary<string, int>();
+                            foreach (var group in config.WagoDigIn.WagoDIGroups)
+                            {
+                                foreach(var item in group.WagoDIs)
+                                {
+                                    DINameIndexDic[item.Name] = i;
+                                    i++;
+                                }
+                            }
+                            //加载AO
+                            i = 0;
+                            AONameIndexDic = new Dictionary<string, int>();
+                            foreach (var group in config.WagoAnoOut.WagoAOGroups)
+                            {
+                                foreach (var item in group.WagoAOs)
+                                {
+                                    AONameIndexDic[item.Name] = i;
+                                    i++;
+                                }
+                            }
+                            //加载AI
+                            i = 0;
+                            AINameIndexDic = new Dictionary<string, int>();
+                            foreach (var group in config.WagoAnoIn.WagoAIGroups)
+                            {
+                                foreach (var item in group.WagoAIs)
+                                {
+                                    AINameIndexDic[item.Name] = i;
+                                    i++;
+                                }
+                            }
 
-                    AONameIndexDic = new Dictionary<string, int>
-                    {{"AO1",0},
-                     {"AO2",1},
-                     {"AO3",2},
-                     {"AO4",3},
-                     {"AO5",4},
-                     {"AO6",5},
-                     {"AO7",6},
-                     {"AO8",7},
-                     {"AO9",8},
-                     {"AO10",9},
-                     {"AO11",10},
-                     {"AO12",11},
-                     {"AO13",12},
-                     {"AO14",13},
-                     {"AO15",14},
-                     {"AO16",15}};
+                        }
+                    }
+                }
+            }
+            catch
+            {
+                LOG.WriteLog(eEvent.ERR_WAGO, "Wago", "Load wago WagoControllerCfg-Simulator.xml failed");
+            }
 
-                    //设置IO变量默认值
-                    AIShorts[AINameIndexDic["r_LoaderA_LS_Vacuum_anlg"]] = 0x32C8;
-                    AIShorts[AINameIndexDic["r_LoaderB_LS_Vacuum_anlg"]] = 0x32C8;
-                        break;
-                case 550:
-                    DONameIndexDic = new Dictionary<string, int>
-                    {{"DO0",0 }, {"DO1",1 }};
-                    DINameIndexDic = new Dictionary<string, int>
-                    {{"DI0",0 }, {"DI1",1 }};
-                    AONameIndexDic = new Dictionary<string, int>
-                    {{"AO0",0 }, {"AO1",0 }};
-                    AINameIndexDic = new Dictionary<string, int>
-                    {{"AI0",0 }, {"AI1",0 }};
-                    break;
-                default:
-                    break;
-            }
-   
+            //设置IO变量默认值
+            if(AINameIndexDic.ContainsKey("r_LoaderA_LS_Vacuum_anlg")) AIShorts[AINameIndexDic["r_LoaderA_LS_Vacuum_anlg"]] = 0x32C8;
+            if(AINameIndexDic.ContainsKey("r_LoaderB_LS_Vacuum_anlg")) AIShorts[AINameIndexDic["r_LoaderB_LS_Vacuum_anlg"]] = 0x32C8;
+            
         }
         #region 公共方法
         public void UpdataDOBytes(string name,int value)

+ 1 - 0
Framework/Common/Simulator/MotorSimulator.cs

@@ -88,6 +88,7 @@ namespace MECF.Framework.Common.Simulator
                     _motorNameDataDic[$"{config.Module}.{item.Name}"].RevSoftLimit = item.ReverseSoftwareLimit;
                     _motorNameDataDic[$"{config.Module}.{item.Name}"].NegativeTorqueLimit = item.NegativeTorqueLimit;
                     _motorNameDataDic[$"{config.Module}.{item.Name}"].PositiveTorqueLimit = item.PositiveTorqueLimit;
+                    _motorNameDataDic[$"{config.Module}.{item.Name}"].SwitchSignal = true;
                 }
             }
         }