public static YTemperatureProxy FindTemperature(string name) { // cases to handle: // name ="" no matching unknwn // name ="" unknown exists // name != "" no matching unknown // name !="" unknown exists YTemperature func = null; YTemperatureProxy res = (YTemperatureProxy)YFunctionProxy.FindSimilarUnknownFunction("YTemperatureProxy"); if (name == "") { if (res != null) { return(res); } res = (YTemperatureProxy)YFunctionProxy.FindSimilarKnownFunction("YTemperatureProxy"); if (res != null) { return(res); } func = YTemperature.FirstTemperature(); if (func != null) { name = func.get_hardwareId(); if (func.get_userData() != null) { return((YTemperatureProxy)func.get_userData()); } } } else { func = YTemperature.FindTemperature(name); if (func.get_userData() != null) { return((YTemperatureProxy)func.get_userData()); } } if (res == null) { res = new YTemperatureProxy(func, name); } if (func != null) { res.linkToHardware(name); if (func.isOnline()) { res.arrival(); } } return(res); }
// called when a device is unplugged public void deviceRemoval(YModule m) { //Cycle on All DropDown gauges for (int j = 0; j < gauges.GetLength(0); j++) { ComboBox d = gauges[j].getDropDown(); int selected = d.SelectedIndex; // cycle on all gauge dropdown items for (int i = d.Items.Count - 1; i >= 0; i--) { //search for function stored in the drop down list MyTemperature mt = (MyTemperature)d.Items[i]; YTemperature t = mt.getYTemperature(); // test if the fucntion parent module is the the one removed // note : it's too late to use get_module on t, so with use // a little trick: with stored the module serial in the function // userdate. if ((string)t.get_userData() == m.get_serialNumber()) { // remove it from the drop down d.Items.RemoveAt(i); // selected index update if (selected == i) { selected--; } if (selected >= d.Items.Count) { selected = d.Items.Count - 1; } } } if (selected >= 0) { d.SelectedIndex = selected; } } // disable empty dropdowns for (int j = 0; j < gauges.GetLength(0); j++) { ComboBox d = gauges[j].getDropDown(); if (d.Enabled && d.Items.Count <= 0) { d.Enabled = false; } } }