/// <summary> /// Start reading loco IO's /// </summary> protected override void OnVisibleChanged(EventArgs e) { base.OnVisibleChanged(e); if (Visible && !started && (appState != null)) { started = true; var list = appState.LocoNet.NewLocoIOs.ToList(); progressBar1.Maximum = list.Count + 1; progressBar1.Minimum = 0; foreach (var io in list) { var index = list.IndexOf(io); var programmer = new Programmer(io.Address); var config = new LocoIOConfig(); appState.LocoBuffer.BeginRequest( x => programmer.Read(x, config), x => { if (!x.HasError) { appState.Configuration.LocoIOs[config.Address] = config; } progressBar1.Value = index + 1; if (index == list.Count-1) { Close(); } }); } } }
/// <summary> /// Start reading loco IO's /// </summary> protected override void OnVisibleChanged(EventArgs e) { base.OnVisibleChanged(e); if (Visible && !started && (appState != null)) { started = true; var list = appState.LocoNet.NewLocoIOs.ToList(); progressBar1.Maximum = list.Count + 1; progressBar1.Minimum = 0; foreach (var io in list) { var index = list.IndexOf(io); var programmer = new Programmer(io.Address); var config = new LocoIOConfig(); appState.LocoBuffer.BeginRequest( x => programmer.Read(x, config), x => { if (!x.HasError) { appState.Configuration.LocoIOs[config.Address] = config; } progressBar1.Value = index + 1; if (index == list.Count - 1) { Close(); } }); } } }
/// <summary> /// Read all pins /// </summary> internal void Read() { Busy = true; var config = new LocoIOConfig(); Enabled = false; lb.BeginRequest( x => programmer.Read(x, config), x => { Enabled = true; Busy = false; if (x.HasError) { MessageBox.Show(x.Error.Message); } else { for (int i = 0; i < 16; i++) { pinControls[i].LoadFrom(config.Pins[i]); } } }); }
/// <summary> /// Try to load an item from the given element into the given configuration. /// </summary> /// <returns>True on success, false otherwise. When false, subsequent loaders are called.</returns> public override bool TryLoad(XElement element, LocoNetConfiguration configuration) { if (element.Name.LocalName != ElementName) return false; var config = new LocoIOConfig(element); return true; }
/// <summary> /// Read the port configurations. /// </summary> public IEnumerable <ILocoIOPort> ReadPorts() { var programmer = new Programmer(Address); var config = new LocoIOConfig(); programmer.Read(lb, config); for (int i = 0; i < 16; i++) { yield return(new LocoIOPort(i + 1, config.Pins[i])); } }
/// <summary> /// Connect to the given config /// </summary> public void Connect(LocoIOConfig config) { this.config = config; connector1.Connect(config.ConnectorA); connector2.Connect(config.ConnectorB); }