Exemple #1
0
        public MainViewModel(IDataService dataService)
        {
            //注册错误显示消息
            Messenger.Default.Register <string>(this, "Error", msg => {
                Application.Current.Dispatcher.Invoke(() => ShowErrorinfo(msg));
            });

            ResultCollection = new ObservableCollection <ResultItem>()
            {
                new ResultItem()
                {
                    Index = 1, HSG_X = 1, HSG_Y = 2, HSG_R = 3, PLC_X = 5, PLC_Y = 6, PLC_R = 7
                }
            };
            SystemErrorMessageCollection = new ObservableCollection <MessageItem>();
            SystemErrorMessageCollection.CollectionChanged += SystemErrorMessageCollection_CollectionChanged;

            //加载配置文件
            Config.ConfigMgr.Instance.LoadConfig(out ErrList);
            StationInfoCollection = new ObservableCollection <string>();
            foreach (var stationCfg in Config.ConfigMgr.Instance.SoftwareCfgMgr.WorkFlowConfigs)
            {
                StationInfoCollection.Add(stationCfg.Name);
            }
            foreach (var station in WorkFlow.WorkFlowMgr.Instance.stationDic)
            {
                station.Value.OnStationInfoChanged += Value_OnStationInfoChanged1;;
            }
            for (int i = 0; i < 10; i++)
            {
                stationLock[i] = new object();
            }



            // 初始化示教点
            List <string> PrePointColumns = new List <string>();

            DataForPreSetPosition = new DataTable();
            DataForPreSetPosition.Columns.Add("PointName");
            PrePointColumns.Add("PointName");
            foreach (var it in Config.ConfigMgr.Instance.HardwareCfgMgr.AxisSettings)
            {
                DataForPreSetPosition.Columns.Add(it.AxisName);
                PrePointColumns.Add(it.AxisName);
            }


            //读取预设点文件
            PrePointSetExcel = new LogExcel();
            PrePointSetExcel.CreateExcelFile(PrePointColumns.ToArray(), POINT_FILE);
            DataTable dtPoint = new DataTable();

            PrePointSetExcel.ExcelToDataTable(ref dtPoint, "");
            DataForPreSetPosition = dtPoint;
        }
Exemple #2
0
 private void SavePrePointFile(LogExcel log, DataTable dt)
 {
     try
     {
         log.DataTableToExcel(dt, "", true, false);
     }
     catch (Exception ex)
     {
         Messenger.Default.Send <string>(ex.Message, "Error");
     }
 }
Exemple #3
0
        protected override bool UserInit()
        {
            bool bRet = false;

            #region >>>>读取模块配置信息,初始化工序Enable信息
            if (GetPresInfomation())
            {
                ShowInfo("加载参数成功");
            }
            else
            {
                ShowInfo("加载参数失败,请确认是否选择参数配方");
            }
            #endregion

            #region >>>>初始化仪表信息
            Pw1000USB_1     = InstrumentMgr.Instance.FindInstrumentByName("PowerMeter[0]") as PowerMeter;
            Pw1000USB_2     = InstrumentMgr.Instance.FindInstrumentByName("PowerMeter[1]") as PowerMeter;
            lds1            = InstrumentMgr.Instance.FindInstrumentByName("LDS[0]") as LDS;
            lds2            = InstrumentMgr.Instance.FindInstrumentByName("LDS[1]") as LDS;
            BarcodeScanner1 = InstrumentMgr.Instance.FindInstrumentByName("SR1000[0]") as Keyence_SR1000;
            BarcodeScanner2 = InstrumentMgr.Instance.FindInstrumentByName("SR1000[1]") as Keyence_SR1000;
            PLC             = InstrumentMgr.Instance.FindInstrumentByName("PLC") as QSerisePlc;


            #endregion

            LogExcel Fake_Barcode_Excel = new LogExcel(FILE_FAKE_BARCODE_FILE);
            Fake_Barcode_Excel.ExcelToDataTable(ref Fake_Barcode_Dt, "Sheet1");

            string str = Fake_Barcode_Dt.Rows[0]["Barcode"].ToString();
            str = Fake_Barcode_Dt.Rows[1]["Barcode"].ToString();


            bRet = true || Pw1000USB_1 != null &&
                   Pw1000USB_2 != null &&
                   lds1 != null &&
                   lds2 != null &&
                   BarcodeScanner1 != null &&
                   BarcodeScanner2 != null &&
                   PLC != null;
            if (!bRet)
            {
                ShowInfo("初始化失败");
            }
            return(bRet);
        }
Exemple #4
0
        //public static
        public void LoadConfig()
        {
            #region >>>>Hardware init
            try
            {
                var json_string = File.ReadAllText(File_HardwareCfg);
                HardwareCfgMgr = JsonConvert.DeserializeObject <HardwareCfgManager>(json_string);
                CameraCfgs     = HardwareCfgMgr.CameraCfgs;
            }
            catch (Exception ex)
            {
                Messenger.Default.Send <string>(String.Format("Unable to load config file {0}, {1}", File_HardwareCfg, ex.Message), "ShowError");
                throw new Exception(ex.Message);
            }
            InstrumentBase             inst     = null;
            HardwareCfgLevelManager1[] instCfgs = null;
            string         strClassName         = "";
            Type           t             = HardwareCfgMgr.GetType();
            PropertyInfo[] PropertyInfos = t.GetProperties();
            for (int i = 0; i < PropertyInfos.Length; i++)
            {
                if (PropertyInfos[i].Name.ToUpper().Contains("COMPORT") || PropertyInfos[i].Name.ToUpper().Contains("ETHERNET") ||
                    PropertyInfos[i].Name.ToUpper().Contains("GPIB") || PropertyInfos[i].Name.ToUpper().Contains("NIVISA") ||
                    PropertyInfos[i].Name.ToUpper().Contains("CAMERACFG"))
                {
                    continue;
                }
                PropertyInfo pi = PropertyInfos[i];
                instCfgs     = pi.GetValue(HardwareCfgMgr) as HardwareCfgLevelManager1[];
                strClassName = pi.Name.Substring(0, pi.Name.Length - 1);
                foreach (var it in instCfgs)
                {
                    if (!it.Enabled)
                    {
                        continue;
                    }
                    inst = t.Assembly.CreateInstance("CPAS.Instrument." + strClassName, true, BindingFlags.CreateInstance, null, new object[] { it }, null, null) as InstrumentBase;
                    if (inst != null && it.Enabled)
                    {
                        if (inst.Init())
                        {
                            InstrumentMgr.Instance.AddInstrument(it.InstrumentName, inst);
                        }
                        else
                        {
                            Messenger.Default.Send <string>(string.Format("Instrument :{0} init failed", it.InstrumentName), "ShowError");
                        }
                    }
                }
            }
            #endregion

            #region >>>>Software init
            try
            {
                var json_string = File.ReadAllText(File_SoftwareCfg);
                SoftwareCfgMgr = JsonConvert.DeserializeObject <SoftwareCfgManager>(json_string);
            }
            catch (Exception ex)
            {
                Messenger.Default.Send <string>(String.Format("Unable to load config file {0}, {1}", File_SoftwareCfg, ex.Message), "ShowError");
                throw new Exception(ex.Message);
            }

            Type           tStationCfg = SoftwareCfgMgr.GetType();
            PropertyInfo[] pis         = tStationCfg.GetProperties();
            SoftwareManager.WorkFlowConfig[] WorkFlowCfgs = null;
            WorkFlowBase workFlowBase = null;
            foreach (PropertyInfo pi in pis)
            {
                WorkFlowCfgs = pi.GetValue(SoftwareCfgMgr) as SoftwareManager.WorkFlowConfig[];
                foreach (var it in WorkFlowCfgs)
                {
                    if (it.Enable)
                    {
                        workFlowBase = tStationCfg.Assembly.CreateInstance("CPAS.WorkFlow." + it.Name, true, BindingFlags.CreateInstance, null, new object[] { it }, null, null) as WorkFlowBase;
                        WorkFlowMgr.Instance.AddStation(it.Name, workFlowBase);
                    }
                }
            }
            #endregion

            #region >>>>PrescriptionCfg Init
            try
            {
                var json_string = File.ReadAllText(File_PrescriptionCfg);
                PrescriptionCfgMgr = JsonConvert.DeserializeObject <PrescriptionCfgManager>(json_string);
            }
            catch (Exception ex)
            {
                Messenger.Default.Send <string>(String.Format("Unable to load config file {0}, {1}", File_SoftwareCfg, ex.Message), "ShowError");
                throw new Exception(ex.Message);
            }
            #endregion

            #region >>>>SystemCfg
            try
            {
                var json_string = File.ReadAllText(File_SystemParaCfg);
                SystemParaCfgMgr = JsonConvert.DeserializeObject <SystemParaCfgManager>(json_string);
            }
            catch (Exception ex)
            {
                Messenger.Default.Send <string>(String.Format("Unable to load config file {0}, {1}", File_SystemParaCfg, ex.Message), "ShowError");
                throw new Exception(ex.Message);
            }
            #endregion

            #region >>>> UserCfg init
            try
            {
                var json_string = File.ReadAllText(File_UserCfg);
                UserCfgMgr = JsonConvert.DeserializeObject <UserCfgManager>(json_string);
            }
            catch (Exception ex)
            {
                Messenger.Default.Send <string>(String.Format("Unable to load config file {0}, {1}", File_UserCfg, ex.Message), "ShowError");
                throw new Exception(ex.Message);
            }
            #endregion

            #region >>>>PLCError Init
            logexcel = new LogExcel(File_PLCError);
            logexcel.ExcelToDataTable(ref PLCErrorDataTable, "Sheet1");
            #endregion
        }