//清除数据 private void ClearData(object sender, EventArgs e) { foreach (var item in _device429.ReceiveComponents) { Channe429Receive sendChanel = (Channe429Receive)item; sendChanel.count = 0; sendChanel.errCount = 0; sendChanel.DeviceCount = 0; sendChanel.errDeviceCount = 0; for (int i = 0; i <= 377; i++) { ReceiveLabel429 label = (ReceiveLabel429)sendChanel.GetSpecificItem(i); if (label != null) { sendChanel.Delete(label); } } Channel429DriverRx channel429DriverRx = new Channel429DriverRx(_device429.DevID, sendChanel.ChannelID); uint ret = channel429DriverRx.ChannelMibClearRx(); if (ret != 0) { RunningLog.Record(string.Format("return value is {0} when clear receive data", ret)); } } }
protected void OnProcess() { while (true) { int countRe = 0; int totalError = 0; uint totalDviceCount = 0; uint totalDeviceErrCount = 0; string result = string.Empty; foreach (var ch in _device429.ReceiveComponents) { uint data = 0; Channe429Receive chennel = (Channe429Receive)ch; countRe += chennel.count; totalError += chennel.errCount; totalDviceCount += chennel.DeviceCount; totalDeviceErrCount += chennel.errDeviceCount; if (chennel.isSend == true) { if (chennel.rxpA429Result.data != 0) { data = chennel.rxpA429Result.data; } if (data != 0) { //对data进行解析 AnalysisLabel label = new AnalysisLabel(); label.ActualValue = (int)data; ReceiveLabel429 receiveLabel = new ReceiveLabel429("label_" + label.Label.ToString()); receiveLabel.ActualValue = label.ActualValue; ReceiveLabel429 receiveLabelExactHas = (ReceiveLabel429)chennel.GetSpecificItem("label_" + label.Label.ToString()); if (receiveLabelExactHas == null) { chennel.Add(receiveLabel); } result += DateTime.Now.ToString() + "\r\n" + "label:\n"; if (checkBox1.Checked == false) { result += data.ToString("x2"); } else { result += data.ToString("x8"); } //这里需要保存log textBox1.Text += result + "\r\n"; } } } if (!this.IsDisposed)//如果窗口没有释放,那么就不停的刷新tree,释放了就不在使用刷新这个方法 { UpdateTreeView1(); } label_totalCount.Text = countRe.ToString(); label_totalError.Text = totalError.ToString(); label4.Text = totalDviceCount.ToString(); label6.Text = totalDeviceErrCount.ToString(); Thread.Sleep(500); } }
//private void UpdateTreeView2() //{ // for (int i = 0; i < 16; i++) // { // string childNode = "chanel_" + i.ToString(); // TreeNode treeNode = new TreeNode(childNode); // treeNode.Checked = true; // _treeView2.Nodes.Add(treeNode); // } // foreach (var item in _treeView2.Nodes) // { // int geWei = 0; // int shiWei = 0; // TreeNode treeNode = (TreeNode)item; // for (int i = 0; i <= 377; i++) // { // geWei = i % 100 % 10; // shiWei = i % 100 / 10; // if (geWei > 7 || shiWei > 7) // { // continue; // } // string childNode = "label_" + i.ToString(); // TreeNode labelNode = new TreeNode(childNode); // labelNode.Checked = true; // for (int j = 0; j < 4; j++) // { // string SDILabel = string.Empty; // switch (j) // { // case 0: SDILabel = "SDI_00"; break; // case 1: SDILabel = "SDI_01"; break; // case 2: SDILabel = "SDI_10"; break; // case 3: SDILabel = "SDI_11"; break; // } // TreeNode SDINode = new TreeNode(SDILabel); // for (int k = 0; k < 4; k++) // { // string SSMLabel = string.Empty; // switch (k) // { // case 0: SSMLabel = "SSM_00"; break; // case 1: SSMLabel = "SSM_01"; break; // case 2: SSMLabel = "SSM_10"; break; // case 3: SSMLabel = "SSM_11"; break; // } // TreeNode SSMNode = new TreeNode(SSMLabel); // SSMNode.Checked = true; // SDINode.Nodes.Add(SSMNode); // } // SDINode.Checked = true; // labelNode.Nodes.Add(SDINode); // } // treeNode.Nodes.Add(labelNode); // } // } //} public void UpdateTreeView1() { //设备里的信息的新信息添加到_treeView1中 TreeNode node = _treeView1.TopNode; for (int i = 0; i < 16; i++) { Channe429Receive receiveCh = (Channe429Receive)_device429.GetSpecificItem(i); if (!receiveCh.Enabled) { continue; } SimpleTreeNode chNode; if (!node.Nodes.ContainsKey(receiveCh.Name)) { chNode = new SimpleTreeNode() { Text = receiveCh.Name, Name = receiveCh.Name, Path = receiveCh.Path }; node.Nodes.Add(chNode); } else { chNode = (SimpleTreeNode)node.Nodes[receiveCh.Name]; } int count = 0; while (true) { AbstractLabel label429 = null; label429 = receiveCh.GetSpecificItem(count++); if (label429 == null) { break; } if (!chNode.Nodes.ContainsKey(label429.Name)) { SimpleTreeNode labelNode = new SimpleTreeNode() { Text = label429.Name, Name = label429.Name, Path = label429.Path }; chNode.AddChildNode(labelNode); } if (!((Label429)label429).IsSelected) { chNode.Nodes[label429.Name].ForeColor = Color.Gray; } else { chNode.Nodes[label429.Name].ForeColor = Color.Black; } } } //去除Treeview中多余的条目 TreeNode topNode = _treeView1.TopNode; for (int i = 0; i < topNode.Nodes.Count; i++) { SimpleTreeNode channelNode = (SimpleTreeNode)topNode.Nodes[i]; string name = channelNode.Name; Channe429Receive channe429Receive = (Channe429Receive)_device429.GetSpecificItem(name); if (null == channe429Receive) { topNode.Nodes.Remove(channelNode); i--; } else { for (int j = 0; j < channelNode.Nodes.Count; j++) { SimpleTreeNode labelNode = (SimpleTreeNode)channelNode.Nodes[j]; Label429 label = (Label429)channe429Receive.GetSpecificItem(labelNode.Name); if (null == label) { channelNode.Nodes.Remove(labelNode); j--; } } } } node.ExpandAll(); }