private void AddCarComm(int carIndex) { CarComm carComm = new CarComm { DeviceIP = IpLst[carIndex] }; Communication.CommLst.Add(carComm.CommHelper);//统计各车的通讯数据 int carType = 0; carComm.txtCarInfo.Text = carIndex % 2 + (Setting.AreaFlag ? 1 : 3) + " # " + GetCarNameAndType(carIndex, out carType); Canvas.SetTop(carComm, 24 + carType * 180); Canvas.SetLeft(carComm, 255 + carIndex % 2 * 180); mainCanvas.Children.Add(carComm);//Children在未添加carComm时的Count为14,maxIndex=13;20170923 }
/// <summary> /// 得到四个地面站无线网桥和8辆车的网络设备的通讯状态 /// 需要注意的是:mainCanvas.Children在未添加CarComm时的Count=14,最大索引maxIndex=13;方法中出现的数字13即为此含义 /// 数字8代表8辆车 /// </summary> private void AssignCommStatus() { if (Communication.CommStatus.Count == 0) { for (int i = 0; i < 9; i++) { Communication.CommStatus.Add(new CommStatus(new bool[] { false, false, false, false })); } } if (commHelper.SucceedCount[2] < 3) {//索引为2时对应的为无线网桥的状态计数 Communication.CommStatus[0] = new CommStatus(commHelper.CommStatus); } for (int i = 0; i < 8; i++) {//添加8辆车的通讯状态 CarComm carComm = (CarComm)mainCanvas.Children[14 + i]; CommStatus comm = new CommStatus(carComm.CommStatus); Communication.CommStatus[i + 1] = comm; } }