/// <summary> /// Switches the active meter tab after a user has moved the optical port to a different meter /// </summary> /// <returns></returns> public async Task SwitchMeters() { // Retrieves the serial number of the meter currently attached to the serial port string serialIdx = CurrentTab.SerialIdx; string currSerialNo = Serial[serialIdx].SerialNo; var tabs = _tabs.Where(x => x.MeterSerialNo == currSerialNo); CurrentTab.Visible = false; // If the meter exists and there is a tab already created for it then switch to that tab // and change to Commissioning page if (Meters.ContainsKey(currSerialNo) && tabs.Count() == 1) { await CurrentTab.StopAsync(); var tab = tabs.ElementAt(0); CurrentTab = tab; tab.Visible = true; tab.CurrentPage = tab.Pages[1]; } // If the meter exists (imported) but there is not a tab created for it then create the tab // and change to the Commissioning page else if (Meters.ContainsKey(currSerialNo)) { await CurrentTab.StopAsync(); CreateTab(new Tuple <string, string>(serialIdx, currSerialNo)); CurrentTab.CurrentPage = CurrentTab.Pages[1]; } // If the meter does not exist, create a new meter and a new tab // then change to the Commissioning page else { Meter m = new Meter(); m.ID = currSerialNo; Meters.Add(currSerialNo, m); // Sets the size of the meter based on the type of meter connected string version = await Serial[serialIdx].GetVersion(); string[] lines = version.Split(new char[] { '\n', '\r' }, System.StringSplitOptions.RemoveEmptyEntries); if (lines[2].Split(new char[0], System.StringSplitOptions.RemoveEmptyEntries)[1].StartsWith("593")) { string[] serials = (await Serial[serialIdx].GetChildSerial()).Split(','); for (int i = 0; i < 12; i++) { m.Channels.Add(new Channel(i + 1)); m.Channels[i].Serial = serials[i]; } } await CurrentTab.StopAsync(); CreateTab(new Tuple <string, string>(serialIdx, currSerialNo)); CurrentTab.CurrentPage = CurrentTab.Pages[1]; } // Initiate the async processes for the current page and modify navigation buttons CurrentTab.StartAsync(); ModifyNavigation(); // Modifies the collections that represent which tabs should be visible in the menu and which tabs // are present in the tab control for user interaction Application.Current.Dispatcher.Invoke(() => { ModifyTabs(); }); }