/// <summary> /// /// </summary> /// <param name="cpCfg"></param> /// <returns></returns> public ICommuniPort GetOrCreateCommuniPort(ICommuniPortConfig cpCfg) { if (cpCfg == null) { throw new ArgumentNullException("cpCfg"); } ICommuniPort r = null; foreach (ICommuniPort cp in this.CommuniPorts) { if (cpCfg.IsMatch(cp)) { r = cp; break; } } if (r == null) { if (cpCfg.CanCreate) { CommuniPortFactory f = CommuniPortFactory.Default; bool added = f.Add(cpCfg); _log.Info("add " + cpCfg + " to communiport factory: " + added); } } return(r); }
/// <summary> /// /// </summary> /// <param name="cp"></param> /// <param name="hardware"></param> static public StationCollection Bind(ICommuniPort cp, Hardware hardware) { StationCollection binded = new StationCollection(); foreach (IStation station in hardware.Stations) { ICommuniPortConfig cpConfig = station.CommuniPortConfig; if (cpConfig.IsMatch(cp)) { ICommuniPort old = station.CommuniPort; if (old != cp) { if (old != null) { old.Close(); } station.CommuniPort = cp; binded.Add(station); } } } return(binded); }