public RfidController(RfidCfg pConfig) { curCfgList = new List <RfidCfg>(); curCfgList.Add(pConfig); rfidList = new List <IRfidController>(); for (int i = 0; i < curCfgList.Count; i++) { IRfidController rfid = CreateInstance(curCfgList[i]); rfid.OnShowErrorMsg += rfid_OnShowErrorMsg; rfid.onReceivedData += ReceivedDataMethod; rfidList.Add(rfid); } }
/// <summary> /// 配置文件名 /// </summary> /// <param name="pConfigFile"></param> /// <param name="isMulti"></param> public RfidController(string pConfigFile) { RFIDReaderLogger.Debug("-----------------------------开始-------------------------------", ""); //读取配置 ConfigReader cfgReader = new ConfigReader(pConfigFile); if (curCfgList == null) { curCfgList = ConfigReader.ReadListRfidConfig(); RFIDReaderLogger.Debug("读取配置文件。pConfigFile=" + pConfigFile, ""); } rfidList = new List <IRfidController>(); for (int i = 0; i < curCfgList.Count; i++) { IRfidController rfid = CreateInstance(curCfgList[i]); rfid.OnShowErrorMsg += rfid_OnShowErrorMsg; rfid.onReceivedData += ReceivedDataMethod; rfidList.Add(rfid); } }
/// <summary> /// 创建RFID实例 /// </summary> /// <returns></returns> private IRfidController CreateInstance(RfidCfg rf) { try { string driverPath = System.AppDomain.CurrentDomain.BaseDirectory; driverPath = Path.Combine(driverPath, rf.EquDll); Assembly assembly = Assembly.LoadFile(driverPath); RFIDReaderLogger.Debug("载入硬件封装模块。driverPath=" + driverPath, ""); string name = assembly.FullName.Split(',')[0] + ".RfidController"; Type type = assembly.GetType(name); IRfidController irfid = Activator.CreateInstance(type, rf) as IRfidController; return(irfid); } catch (Exception ex) { RFIDReaderLogger.Error("CreateInstance异常。", "", ex); return(null); } }