
using MisDataFunDll;
using System;
using SystemFramework;
//using SystemFramework;
//using bizFacade;

namespace MesServerWork
{

  public  partial class MIS_BASE
    {


        /// <summary>
        /// 通过TagTypeName读取PLC数据
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        static private void Read_TagValueByTagTypeName(string cmd, string opName, out string tagValue)
        {
            tagValue = "-1";
            int tagTypeID;
            try
            {
                tagTypeID = Convert.ToInt32(MIS_BASE.hashtable_TagType[cmd]);
                string msg = "MES|" + tagTypeID.ToString() + "|" + opName + "|" + tagValue;
                //tagValue = ChatService.MesReadWhisperMessage(msg);
                MIS_BASE.ReadTagValue(tagTypeID, opName, out tagValue);
            }
            catch (Exception err)
            {
                ApplicationLog.WriteLog(err, "Read_TagValueByTagTypeName_FUNC；工位号：" + opName + "；命令：" + cmd + "；值：" + tagValue);
            }

        }

        /// <summary>
        /// 通过TagID读取对应值
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_TagValueByTagID(string TagID, out object tagValue)
        {
            tagValue = "0";
            try
            {
                tagValue = MIS_BASE.ReadPLC(TagID).ToString();
            }
            catch (Exception err)
            {
                ApplicationLog.WriteLog(err, "Read_TagValueByTagID_FUNC");
            }
        }

        /// <summary>
        /// 根据变量类型代码、工位号获得对应值
        /// </summary>
        /// <param name="tagType"></param>
        /// <param name="opName"></param>
        /// <param name="tagValueStr"></param>
        public static void Read_TagValueByTagTypeID(int tagTypeID, string opName, out string tagValueStr)
        {
            tagValueStr = "-1";

            try
            {
                MIS_BASE.ReadTagValue(tagTypeID, opName, out tagValueStr);
            }
            catch (Exception err)
            {
                ApplicationLog.WriteLog(err, "Read_TagValueByTagTypeID_FUNC");
            }
        }

        /// <summary>
        /// 根据变量类型代码、工位号获得对应值
        /// </summary>
        /// <param name="tagType"></param>
        /// <param name="opName"></param>
        /// <param name="tagValueStr"></param>
        public static void Read_TagValueByTagTypeID(int tagTypeID, string opName, out object tagValueStr)
        {
            tagValueStr = "-1";

            try
            {
                tagValueStr = MIS_BASE.ReadPLC(tagTypeID, opName);
            }
            catch (Exception err)
            {
                ApplicationLog.WriteLog(err, "Read_TagValueByTagTypeID_FUNC");
            }
        }
        /// <summary>
        /// 根据变量类型代码、工位号获得对应值
        /// </summary>
        /// <param name="tagType"></param>
        /// <param name="opName"></param>
        /// <param name="tagValueStr"></param>
        public static string Read_TagValueByTagTypeID(int tagTypeID, string opName)
        {
            string tagValueStr = "-1";
            try
            {
                MIS_BASE.ReadTagValue(tagTypeID, opName, out tagValueStr);
         
            }
            catch (Exception err)
            {
                ApplicationLog.WriteLog(err, "Read_TagValueByTagTypeID_FUNC");
            }
            return tagValueStr;
        }

        /// <summary>
        /// 读取数据通过(TagTypeName&opName)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValueStr"></param>
        public static void Read_TagTypeName(string cmd, string opName, out string tagValueStr)
        {
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
        }

        /// <summary>
        /// 读取数据通过(TagTypeID&opName)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValueStr"></param>
        public static void Read_TagTypeID(int tagTypeID, string opName, out string tagValueStr)
        {
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
        }






        /// <summary>
        /// 订单号(string)(25)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_OrderForm(string opName, out string tagValue)
        {
            int tagTypeID = 39;
            tagValue = "";
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValue);
        }
        /// <summary>
        /// 总成编号(string)(26)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_AssemblyCode(string opName, out string tagValue)
        {
            tagValue = "";
            string cmd = "AssemblyCode";
            Read_TagValueByTagTypeName(cmd, opName, out tagValue);
            //tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));
        }
        /// <summary>
        /// 配方号1(dint)(27)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_Recipe1(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "Recipe1";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);
        }
        /// <summary>
        /// 配方号2(dint)(28)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_Recipe2(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "Recipe2";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);
        }

        /// <summary>
        /// 订单号(string)(116)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_OrderForm_MES(string opName, out string tagValue)
        {
            int tagTypeID = 116;
            tagValue = "";
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValue);
            //tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));
        }
        /// <summary>
        /// 总成编号(string)(62)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_AssemblyCode_MES(string opName, out string tagValue)
        {
            tagValue = "";
            string cmd = "AssemblyCode_MES";
            Read_TagValueByTagTypeName(cmd, opName, out tagValue);
            //tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));
        }
        /// <summary>
        /// 配方号1(dint)(63)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_Recipe1_MES(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "Recipe1_MES";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);
        }
        /// <summary>
        /// 配方号2(dint)(64)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_Recipe2_MES(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "Recipe2_MES";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);
        }

        /// <summary>
        /// 匹配结果(DBX3.4)(69)
        /// 匹配是否成功
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_MatchSuccess(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "Match";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// 是否匹配(DBX3.3)(68)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_MatchingCompleted(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "MatchingCompleted";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }


        /// <summary>
        /// MES保存完数据(必须MIS)(X102.2)(20)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_MesReadOver(string opName, out bool tagValue)
        {
            tagValue = false;
            int tagTypeID = 20;
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));

        }

        /// <summary>
        /// 发动机到位(X0.1)(2)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_WorkStart(string opName, out bool tagValue)
        {
            tagValue = false;
            int tagTypeID = 2;
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));
        }

        /// <summary>
        ///  发动机机型标志(INT4)(9)
        /// </summary>
        public static void Read_EngineTypeID(string opName, out int tagValue)
        {
            int tagTypeID = 9;
            tagValue = 0;
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }
        /// <summary>
        ///  发动机ID(STRING6.38)(10)
        /// </summary>
        public static void Read_EngineID(string opName, out string tagValue)
        {
            int tagTypeID = 10;
            tagValue = "";
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = tagValueStr;
        }
        //public static void Read_OrderForm(string opName, out string tagValue)
        //{
        //    tagValue = "";
        //    string tagTypeID = "39";
        //    string tagValueStr;
        //    tagValueStr = DtWebApi.ReadWritePLC.ReadPLC(tagTypeID, opName).ToString();
        //    tagValue = tagValueStr;
        //}
        /// <summary>
        ///  发动机型号(STRING46.38)(11)
        /// </summary>
        public static void Read_EngineType(string opName, out string tagValue)
        {
            int tagTypeID = 11;
            tagValue = "";
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = tagValueStr;

        }

        /// <summary>
        ///  工位直通(X101.6)(1006)
        /// </summary>
        public static void Read_PartGoOver(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "PartGoOver";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        ///  托盘到位(1)托盘离开(0) (DBX101.5)(13) 
        /// </summary>
        public static void Read_PartPalletStatus(string opName, out bool tagValue)
        {
            tagValue = false;
            string cmd = "PartPalletStatus";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));
        }

        /// <summary>
        ///  加工时间变量目标时间 (DINT 106)(17) 
        /// </summary>
        public static void Read_MachineTime_TargetTime(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "TargetTime";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }
        /// <summary>
        ///  加工时间变量实际时间 (DINT 110)(18) 
        /// </summary>
        public static void Read_MachineTime_ActualTime(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "ActualTime";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        ///  质量数据总成合格标志(INT104)(21)
        /// </summary>
        public static void Read_QualityMask(string opName, out int tagValue)
        {
            tagValue = 0;
            int tagTypeID = 21;
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            if (tagValueStr == "1" | tagValueStr.ToLower () == "true")
            {
                tagValueStr = "1";
            }
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// 机体流向标志（1 BYTE）：
        /// 0普通工位：
        /// 1：上线（发动机上线）；
        /// 2：下线（发动机下线）；(INT114)(41)
        /// </summary>
        public static void Read_PartMoveDirection(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "PartMoveDirection";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);
        }


        /// <summary>
        ///  强制MES(X103.0)(78)
        /// </summary>
        public static void Read_Mes_MustTest(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "IsMES";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }
        /// <summary>
        ///  工位三种状态：在线、离线、屏蔽（0，1，2）(DBB116)(79)
        /// </summary>
        public static void Read_OnLineState(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "OnLineState";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);
        }

        /// <summary>
        /// 变量类型代码=44 CF0.4
        /// PLC向MES传递机型，机型代码，零件编号完成，通知PLC。
        /// 机型可读
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_EngineGetOver_PLC(string opName, out bool tagValue)
        {
            tagValue = false;
            int tagTypeID = 44;
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));

        }

        /// <summary>
        /// X100.2允许保存质量数据(19)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_QualityData_Read_CF(string opName, out bool tagValue)
        {
            tagValue = false;
            int tagTypeID = 19;
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt64(tagValueStr));

        }

        /// <summary>
        /// MES向PLC传递机型(DBX2.1)(5)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_EngineTypeGetOver_MES(string opName, out bool tagValue)
        {
            tagValue = false;
            int tagTypeID = 5;
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));

        }

        /// <summary>
        /// X2.3 工作完成(7)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_MaterialVerifyOver(string opName, out bool tagValue)
        {
            tagValue = false;
            int tagTypeID = 7;
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));

        }

        /// <summary>
        /// 申请上线(DBX0.3)(43)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_PartLoad(string opName, out bool tagValue)
        {
            tagValue = false;
            int tagTypeID = 43;
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));

        }

        /// <summary>
        /// 上线完成(DBX0.3)(48)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_PartLoad_OK(string opName, out bool tagValue)
        {
            tagValue = false;
            string cmd = "PartLoadOK";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));

        }

        /// <summary>
        /// 合格放行(51)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_ConfirmOkGo(string opName, out bool tagValue)
        {
            tagValue = false;
            string cmd = "ConfirmOkGo";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));

        }

        /// <summary>
        /// 拧紧结束(DBX1.1)(59)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_FixOK(string opName, out bool tagValue)
        {
            tagValue = false;
            string cmd = "FixOK";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));

        }

        /// <summary>
        /// 蘑菇按钮(DBX1.3)(61)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_NextPushButton(string opName, out bool tagValue)
        {
            tagValue = false;
            string cmd = "NextPushButton";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));

        }

        /// <summary>
        /// 允许拧紧(DBX3.1)(66)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_FixAllow(string opName, out bool tagValue)
        {
            tagValue = false;
            int tagTypeID = 66;
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));

        }

        /// <summary>
        /// 拧紧结束确认(DBX3.2)(67)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_FixOver(string opName, out bool tagValue)
        {
            tagValue = false;
            string cmd = "FixOver";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));

        }

        /// <summary>
        ///返修上线,在上线工位，MES依据工件情况，设定为返修件，PLC见到MES设定为1后，将返修标志写入到DBX0.2为1
        ///MES设定完返修返修上线后，MES清空该信号
        ///DBX3.7(72)  
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_RepairUpline_MES(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "RepairUplineMES";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        

        /// <summary>
        /// 匹配结果(DBX3.4)(69)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_Match(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "Match";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);
        }

        /// <summary>
        /// 发动机机型代码(DBB404)(73)[false]
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="EngineTypeID"></param>
        public static void Read_EngineTypeID_MES(string opName, out int EngineTypeID)
        {
            int tagTypeID = 73;
            EngineTypeID = 0;
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            EngineTypeID = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// 发动机机型(DBB446)(75)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="EngineType"></param>
        public static void Read_EngineType_MES(string opName, out string EngineType)
        {
            int tagTypeID = 75;
            EngineType = "";
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            EngineType = tagValueStr;

        }

        /// <summary>
        /// 发动机号(DBB406)(74)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="EngineID"></param>
        public static void Read_EngineID_MES(string opName, out string EngineID)
        {
            int tagTypeID = 74;
            EngineID = "";
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            EngineID = tagValueStr;

        }

        /// <summary>
        /// 拧紧序号(77)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_ProcessCode(string opName, out int tagValue)
        {
            int tagTypeID = 77;
            tagValue = 0;
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }


        /// <summary>
        /// 套筒号、子程序代码子程序(DBB26)(2025)[false]
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_BoltCode(string opName, out int tagValue)
        {
            int tagTypeID = 88;
            tagValue = 0;
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }


        /// <summary>
        ///  托盘代码(DBB86)(80) 
        /// </summary>
        public static void Read_PalletCode(string opName, out int tagValue)
        {
            int tagTypeID = 80;
            tagValue = 0;
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);
        }
        /// <summary>
        /// 获得机型，零件编号，机型代码，托盘号，(从PLC)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="EngineTypeID"></param>
        /// <param name="EngineType"></param>
        /// <param name="EngineID"></param>
        /// <param name="PartPallet_Code"></param>
        public static void GetEngineTypeFromPLC(string opName, out int EngineTypeID, out string EngineType, out string EngineID, out int PartPallet_Code,out string OrderForm)
        {
            Read_EngineTypeID(opName,out  EngineTypeID);
            Read_EngineType(opName, out  EngineType);
            Read_EngineID(opName, out  EngineID);
            Read_OrderForm(opName, out OrderForm);
            Read_PalletCode(opName, out  PartPallet_Code);
        }
        /// <summary>
        ///  /// 获得机型，零件编号，机型代码，托盘号，(从MES)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="EngineTypeID"></param>
        /// <param name="EngineType"></param>
        /// <param name="EngineID"></param>
        /// <param name="OrderForm"></param>
        public static void GetEngineTypeFromPLC_MES(string opName, out int EngineTypeID, out string EngineType, out string EngineID, out string OrderForm)
        {
            Read_EngineTypeID_MES(opName, out EngineTypeID);
            Read_EngineType_MES(opName, out EngineType);
            Read_EngineID_MES(opName, out EngineID);
            Read_OrderForm_MES(opName, out OrderForm);
        }

        /// <summary>
        /// 获得机型，零件编号，机型代码，托盘号，(从DB)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="EngineTypeID"></param>
        /// <param name="EngineType"></param>
        /// <param name="EngineID"></param>
        /// <param name="PartPallet_Code"></param>
        public static void GetEngineTypeFromDB(string opName, out int EngineTypeID, out string EngineType, out string EngineID, out int PartPallet_Code)
        {
            string orderForm = "";
            int isRepair = 0;
            string repairCode = "";
            string palletCode = "0";
            string EngineTypeString = "";
            MisDataFun.Moby_Select(opName,
            out orderForm, out EngineTypeID, out EngineType,
            out EngineID, out palletCode, out isRepair, out repairCode, out EngineTypeString);
            PartPallet_Code = Convert.ToInt32(palletCode);
        }

        /// <summary>
        /// 0：不修改；1：可以修改。（上线工位）通知PLC。(DBX1.2)(76)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_PartPalletCode_PLC_ToMES(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "PartPalletCodePLCToMES";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// 通知写入托盘号(DBX3.5)(70)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_PartPalletCode_PLC(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "PartPalletCodePLC";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// 变量类型代码=86，打印第一行（机型）,用于线首打印机。STRING	486	.38
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_PrintBarCode1_MES(string opName, out string tagValue)
        {
            tagValue = "";
            string cmd = "PrintBarCode1MES";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = tagValueStr;

        }

        /// <summary>
        /// 变量类型代码=87，打印第二行（流水号）,用于线首打印机。STRING	526	.38
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_PrintBarCode2_MES(string opName, out string tagValue)
        {
            tagValue = "";
            string cmd = "PrintBarCode2MES";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = tagValueStr;

        }


        /// <summary>
        /// 上线工位。0：正常工作；1：空托盘放行(DBX2.2)(6)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_PartPalletGoOver(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "PartPalletGoOver";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// 自动手动申请工件编号,0是自动方式；1：手动方式。切换时，(DBX2.1)(71)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_IsAutoGetEngineID(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "IsAutoGetEngineID";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// 正常拧紧时选择(DBX100.3)(81)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_Normal(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "Normal";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// 备用拧紧时选择(DBX100.4)(82)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_UnNormal(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "UnNormal";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// 允许拧紧2(DBX100.5)(83)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_FixAllow_2(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "FixAllow2";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// 拧紧结束2(DBX100.6)(84)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_FixOK_2(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "FixOK2";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// 拧紧结束确认2(DBX100.7)(85)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_FixOver_2(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "FixOver2";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// 拧紧顺序2(DBX101.7)(1007)
        /// MES通知PLC开始拧紧顺序（0为其他位，1为第一位置）（必须MES）
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_WriteShaft_2(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "WriteShaft2";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);
        }


        /// <summary>
        /// 返修上线(DBX2.6)(52)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_PartLoadFinish(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "PartLoadFinish";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// 返修上线后，PLC确认(DBX1.0)(58)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_PartLoadOver(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "PartLoadOver";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// 变量类型代码=22，读取托盘信息 DBW126
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_PalletInfo(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "PalletInfo";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);
        }

        /// <summary>
        /// 变量类型代码=23，读取托盘信息 DBW194
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_RepairStatus_PLC(string opName, out int tagValue)
        {
            int tagTypeID = 23;
            tagValue = 0;
            string cmd = "RepairStatusPLC";
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// PLC将MOBY信息成功写入到了对应的DB，然后通知MES(DBX1.5)(63)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_PalletMobyReadOver(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "PalletMobyReadOver";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }


        /// <summary>
        /// 在线返修状态(DBX4.0)(91)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_OnlineRepair(string opName, out int tagValue)
        {
            tagValue = 0;
            string cmd = "OnlineRepair";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToInt32(tagValueStr);

        }

        /// <summary>
        /// 离线返修状态(DBX4.1)(92)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_OutLineRepair(string opName, out bool tagValue)
        {
            tagValue = false;
            string cmd = "OutLineRepair";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));

        }

        /// <summary>
        /// MES通知PLC修改托盘状态成功(DBX4.2)(93)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_UpdatePalletOK(string opName, out bool tagValue)
        {
            tagValue = false;
            string cmd = "UpdatePalletOK";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));
        }


        /// <summary>
        /// MES向PLC要求申请下线(DBX0.7)(50)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_PalletDown(string opName, out bool tagValue)
        {
            tagValue = false;
            string cmd = "PalletDown";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));

        }


        /// <summary>
        /// 物料检测(99)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_CheckMaterial(string opName, out object tagValue)
        {
            tagValue = new bool[16];
            string cmd = "CheckMaterial";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));

        }

        /// <summary>
        /// 备用功能是否启用(95)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_BakOpNameIsWork(string opName, out bool tagValue)
        {
            tagValue = false;
            string cmd = "BakOpNameIsWork";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));
        }


        /// <summary>
        /// 质量呼叫(DBX301.2)(2011)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_QualityCall(string opName, out bool tagValue)
        {
            tagValue = false;
            string cmd = "QualityCall";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));
        }

        /// <summary>
        /// 物料呼叫(DBX301.3)(2012)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_MaterialCall(string opName, out bool tagValue)
        {
            tagValue = false;
            string cmd = "MaterialCall";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));

        }

        /// <summary>
        /// 故障呼叫(DBX301.4)(2013)
        /// </summary>
        /// <param name="opName"></param>
        /// <param name="tagValue"></param>
        public static void Read_FaultCall(string opName, out bool tagValue)
        {
            tagValue = false;
            string cmd = "FaultCall";
            string tagValueStr;
            Read_TagValueByTagTypeName(cmd, opName, out tagValueStr);
            tagValue = Convert.ToBoolean(Convert.ToInt32(tagValueStr));
        }

        public static void Read_PartScanCode(int tagTypeID, string opName, out string tagValue)
        {
            tagValue = "";
            string tagValueStr;
            Read_TagValueByTagTypeID(tagTypeID, opName, out tagValueStr);
            tagValue = tagValueStr;
        }

    }
}
