制作的IR协议软件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using OMT统一测试软件.Lib;
using OMT统一测试软件.PartPanel;
using System.Threading;
using System.Net.Sockets;
using System.Net;
using OMT统一测试软件.UControl;

namespace OMT统一测试软件
{
public partial class MainForm : Form
{
private ManualResetEvent sendDone = new ManualResetEvent(false);
private ManualResetEvent ReceiveDone = new ManualResetEvent(false);
private ManualResetEvent connectDone = new ManualResetEvent(false);
private String response = String.Empty;
public Socket client;
public MainForm()
{
InitializeComponent();
this.tevRRU.ExpandAll();
this.dataGridView1.AllowUserToAddRows = false;
for (int i = 0; i < 20; i++) // 假定需要显示20行空表格,具体根据需要修改此处
{
this.dataGridView1.Rows.Add(new DataGridViewRow());
}

foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
row.HeaderCell.Value = String.Format("{0}", row.Index + 1);
}

}
/// <summary>
/// Socket连接
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Connect_Click(object sender, EventArgs e)
{
try
{
client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress ipAddress = IPAddress.Parse(IPAdd.Text.Trim());
IPEndPoint point = new IPEndPoint(ipAddress, Convert.ToInt32(tbxPort.Text.Trim()));
client.BeginConnect(point, new AsyncCallback(ConnectCallback), client);
connectDone.WaitOne();
MessageBox.Show("连接成功!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// 异步调用连接方法
/// </summary>
/// <param name="ar"></param>
public void ConnectCallback(IAsyncResult ar)
{
try
{
//从state对象获取Socket
Socket client = (Socket)ar.AsyncState;
//完成连接
client.EndConnect(ar);
connectDone.Set();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// 断开连接
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DisConnect_Click(object sender, EventArgs e)
{
SocketConn sc = new SocketConn();
sc.DisConnect();
}
//全选按钮
private void AllselectOrNoSelect_Click(object sender, EventArgs e)
{
Control button = (Control)sender;
if (button.Text == "全选")
{
foreach (Control c in button.Parent.Controls)
{
if (c.GetType().Name == "UserGroupBox" && c.Enabled == true)
{
((UserGroupBox)c).MyClick = true;
((UserGroupBox)c).IsChecked = true;
}
}
button.Text = "不选";
}
else
{
foreach (Control c in button.Parent.Controls)
{
if (c.GetType().Name == "UserGroupBox" && c.Enabled == true)
{
((UserGroupBox)c).MyClick = false;
((UserGroupBox)c).IsChecked = false;
}
}
button.Text = "全选";
}
}
//查询按钮
private void btnStatusQuery_Click(object sender, EventArgs e)
{
try
{
if (client.Connected)
{
Button tempBTN = (Button)sender;
try
{
//这里对要发送的数据进行处理
ArrayList arr = new ArrayList();
CMessageType msg = new CMessageType();
int a = int.Parse(sendCount.Text);//发送消息流水号
a++;
sendCount.Text = a.ToString();
#region 小区管理
if (tblModel.SelectedIndex == 0)
{
#region 消息头
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(tblModel.SelectedTab.Tag.ToString());//193 
msg.MessageLength = int.Parse("15");
msg.SendCount = int.Parse(sendCount.Text);
byte[] b02 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b3 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Parent.Tag.ToString()).ToString());
byte[] b4 = StrConverter.strToBytes.str1ToBytes(int.Parse(bbuValue.Text).ToString());
byte[] b5 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Tag.ToString()).ToString());
byte[] b6 = StrConverter.strToBytes.str4ToBytes(msg.SendCount.ToString());
arr.AddRange(msg.MessageNumber);
arr.AddRange(b02);
arr.AddRange(b3);
arr.AddRange(b4);
arr.AddRange(b5);
arr.AddRange(b6);
#endregion
#region 小区配置
if (userGroupBox29.IsChecked)//小区配置
{
msg.LenIE = 14;
msg.MessageLength += msg.LenIE;//29
msg.SignIE = int.Parse(userGroupBox29.Tag.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());//1501 05DD
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
msg.Item = int.Parse(cbx0005.SelectedIndex.ToString());//小区配置标识
byte[] b9 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = int.Parse(tbx0013.Text);//本地小区标识
byte[] b10 = StrConverter.strToBytes.str4ToBytes(msg.Item.ToString());
msg.Item = int.Parse(tbx0014.Text);//小区功率
byte[] b11 = StrConverter.strToBytes.str2ToBytes(msg.Item.ToString());//0028
msg.Item = int.Parse(cbx0006.Text);//天线组号
byte[] b12 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = int.Parse(cbx0007.Text);//频点数
byte[] b13 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = int.Parse(cbx0008.SelectedIndex.ToString());//小区模式
byte[] b14 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
arr.AddRange(b9);
arr.AddRange(b10);
arr.AddRange(b11);
arr.AddRange(b12);
arr.AddRange(b13);
arr.AddRange(b14);
}
#endregion
#region PARCH配置
if (userGroupBox28.IsChecked)//PARCH配置
{
msg.LenIE = 9;
msg.MessageLength += msg.LenIE;//24
msg.SignIE = int.Parse(userGroupBox28.Tag.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
msg.Item = int.Parse(cbx0009.Text);//小区ID标识
byte[] b9 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = int.Parse(cbx0010.Text);
byte[] b10 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = int.Parse(cbx0011.Text);
byte[] b11 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());//0028
msg.Item = int.Parse(cbx0012.Text);
byte[] b12 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = int.Parse(cbx0013.Text);
byte[] b13 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
arr.AddRange(b9);
arr.AddRange(b10);
arr.AddRange(b11);
arr.AddRange(b12);
arr.AddRange(b13);
}
#endregion
#region 频点配置1
if (userGroupBox25.IsChecked)//频点配置1
{
msg.LenIE = 31;
msg.MessageLength += msg.LenIE;//24
msg.SignIE = int.Parse(userGroupBox25.Tag.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
msg.Item = int.Parse(cbx0002.SelectedIndex.ToString());
byte[] b9 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = int.Parse(tbx0001.Text);
byte[] b10 = StrConverter.strToBytes.str4ToBytes(msg.Item.ToString());
msg.Item = int.Parse(tbx0002.Text);
byte[] b11 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = int.Parse(tbx0003.Text);
byte[] b12 = StrConverter.strToBytes.str4ToBytes(msg.Item.ToString());
msg.Item = int.Parse(cbx0014.SelectedIndex.ToString());
byte[] b13 = StrConverter.strToBytes.str4ToBytes(msg.Item.ToString());
msg.Item = int.Parse(cbx0015.Text);
byte[] b14 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = int.Parse(cbx0016.Text);
byte[] b15 = StrConverter.strToBytes.str4ToBytes(msg.Item.ToString());
msg.Item = int.Parse(cbx0017.Text);
byte[] b16 = StrConverter.strToBytes.str4ToBytes(msg.Item.ToString());
msg.Item = int.Parse(cbx0018.Text);
byte[] b17 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = int.Parse(cbx0019.SelectedIndex.ToString());
byte[] b18 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = int.Parse(tbx0004.Text);
byte[] b19 = StrConverter.strToBytes.str2ToBytes(msg.Item.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7); arr.AddRange(b8); arr.AddRange(b9); arr.AddRange(b10);
arr.AddRange(b11);
arr.AddRange(b12);
arr.AddRange(b13);
arr.AddRange(b14);
arr.AddRange(b15);
arr.AddRange(b16);
arr.AddRange(b17);
arr.AddRange(b18);
arr.AddRange(b19);
}
#endregion
}
#endregion
#region 状态管理
else if (tblModel.SelectedIndex == 1)
{
#region 状态查询
if (QueryOrSet.SelectedIndex == 0)
{
#region 消息头
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(RRUStatusQuery.Tag.ToString());//41 00 00 00 29
msg.MessageLength = int.Parse("15");
msg.SendCount = int.Parse(sendCount.Text);
byte[] b02 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b3 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Tag.ToString()).ToString());
byte[] b4 = StrConverter.strToBytes.str1ToBytes(int.Parse(bbuValue.Text).ToString());
byte[] b5 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Tag.ToString()).ToString());
byte[] b6 = StrConverter.strToBytes.str4ToBytes(msg.SendCount.ToString());
arr.AddRange(msg.MessageNumber);
arr.AddRange(b02);
arr.AddRange(b3);
arr.AddRange(b4);
arr.AddRange(b5);
arr.AddRange(b6);
#endregion
#region 射频通道
if (RFChannel.IsChecked)//射频通道
{
msg.LenIE = 5;
msg.MessageLength += msg.LenIE;
byte[] b7 = StrConverter.strToBytes.str2ToBytes(int.Parse(RFChannel.Tag.ToString()).ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
msg.Item = lcbx0001.SelectedIndex;
byte[] b9 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
arr.AddRange(b9);
}
#endregion
#region 载波状态
if (cbxCarrierStatus.IsChecked)//载波状态
{
msg.LenIE = 4;
msg.MessageLength += msg.LenIE;//26 00 00 00 1A
msg.SignIE = int.Parse(cbxCarrierStatus.Tag.ToString());// 00 0B
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
}
#endregion
#region 本振状态
if (userGroupBox1.IsChecked)//本振状态
{
msg.LenIE = 4;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox1.Tag.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
}
#endregion
#region 时钟状态
if (userGroupBox2.IsChecked)//时钟状态
{
msg.LenIE = 4;
msg.MessageLength += msg.LenIE;//26 00 00 00 1A
msg.SignIE = int.Parse(userGroupBox2.Tag.ToString());// 00 0B
//msg.Item = int.Parse(textBox5.Text);//00 00 00 3c
//对时间进行处理2017-8-23 15:04:00
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
}
#endregion
#region RRU运行状态
if (userGroupBox3.IsChecked)//RRU运行状态
{
msg.LenIE = 4;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox3.Tag.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
}
#endregion
#region IR口工作模式
if (userGroupBox4.IsChecked)//IR口工作模式
{
msg.LenIE = 4;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox4.Tag.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
}
#endregion
#region 初始化校准
if (userGroupBox5.IsChecked)//初始化校准
{
msg.LenIE = 4;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox5.Tag.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
}
#endregion
#region 光口信息查询
if (userGroupBox6.IsChecked)//光口信息查询
{
msg.LenIE = 5;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox6.Tag.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
msg.Item = cbx0001.SelectedIndex;
byte[] b9 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
arr.AddRange(b9);
}
}
#endregion
#endregion
#region 参数查询
if (QueryOrSet.SelectedIndex == 1)
{
#region 消息头
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(ParameterQuery.Tag.ToString());//51 00 00 00 33
msg.MessageLength = int.Parse("15");
msg.SendCount = int.Parse(sendCount.Text);//00 00 00 00
byte[] b02 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b3 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Tag.ToString()).ToString());
byte[] b4 = StrConverter.strToBytes.str1ToBytes(int.Parse(bbuValue.Text).ToString());
byte[] b5 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Tag.ToString()).ToString());
byte[] b6 = StrConverter.strToBytes.str4ToBytes(msg.SendCount.ToString());
arr.AddRange(msg.MessageNumber);
arr.AddRange(b02);
arr.AddRange(b3);
arr.AddRange(b4);
arr.AddRange(b5);
arr.AddRange(b6);
#endregion
#region 系统时间查询
if (userGroupBox7.IsChecked)//系统时间查询
{
msg.LenIE = 4;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox7.Tag.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
}
#endregion
#region CPU占用率
if (userGroupBox8.IsChecked)//CPU占用率
{
msg.LenIE = 4;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox8.Tag.ToString());
byte[] b9 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b10 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b9);
arr.AddRange(b10);
}
#endregion
#region CPU占用率周期查询
if (userGroupBox9.IsChecked)//CPU占用率周期查询
{
msg.LenIE = 4;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox9.Tag.ToString());
byte[] b11 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b12 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b11);
arr.AddRange(b12);
}
#endregion
#region RRU温度
if (userGroupBox10.IsChecked)//RRU温度
{
msg.LenIE = 8;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox10.Tag.ToString());
byte[] b13 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b14 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b13);
arr.AddRange(b14);
msg.Item = RRUtemp.SelectedIndex;
byte[] b15 = StrConverter.strToBytes.str4ToBytes(msg.Item.ToString());
arr.AddRange(b15);
}
#endregion
#region 驻波比状态
if (userGroupBox11.IsChecked)//驻波比状态
{
msg.LenIE = 5;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox11.Tag.ToString());
byte[] b16 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b17 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b16);
arr.AddRange(b17);
msg.Item = cbx0023.SelectedIndex;
byte[] b18 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
arr.AddRange(b18);
}
#endregion
#region 驻波比门限查询
if (userGroupBox12.IsChecked)//驻波比门限查询
{
msg.LenIE = 4;
msg.MessageLength += msg.LenIE;//26 00 00 00 1A
msg.SignIE = int.Parse(userGroupBox12.Tag.ToString());
byte[] b21 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b22 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b21);
arr.AddRange(b22);
}
#endregion
#region 过温门限值
if (userGroupBox13.IsChecked)//过温门限值
{
msg.LenIE = 4;
msg.MessageLength += msg.LenIE;//26 00 00 00 1A
msg.SignIE = int.Parse(userGroupBox13.Tag.ToString());// 00 0B
byte[] b19 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b20 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b19);
arr.AddRange(b20);
}
#endregion
#region 输出功率
if (userGroupBox14.IsChecked)//输出功率
{
msg.LenIE = 5;
msg.MessageLength += msg.LenIE;//26 00 00 00 1A
msg.SignIE = int.Parse(userGroupBox14.Tag.ToString());
byte[] b23 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b24 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b23);
arr.AddRange(b24);
msg.Item = cbx0004.SelectedIndex;
byte[] b25 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
arr.AddRange(b25);
}
#endregion
#region 状态机
if (userGroupBox15.IsChecked)//状态机
{
msg.LenIE = 4;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox15.Tag.ToString());
byte[] b26 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b27 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b26);
arr.AddRange(b27);
}
#endregion
}
#endregion
#region 参数配置
if (QueryOrSet.SelectedIndex == 2)
{
#region 消息头
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(RRUParamSet.Tag.ToString());
msg.MessageLength = int.Parse("15");
byte[] b02 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b3 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Tag.ToString()).ToString());
byte[] b4 = StrConverter.strToBytes.str1ToBytes(int.Parse(bbuValue.Text).ToString());
byte[] b5 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Tag.ToString()).ToString());
byte[] b6 = StrConverter.strToBytes.str4ToBytes(msg.SendCount.ToString());
arr.AddRange(msg.MessageNumber);
arr.AddRange(b02);
arr.AddRange(b3);
arr.AddRange(b4);
arr.AddRange(b5);
arr.AddRange(b6);
#endregion
#region 系统时间
if (userGroupBox16.IsChecked)//系统时间
{
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(RRUParamSet.Tag.ToString());//61 00 00 00 3d
msg.LenIE = 11;
msg.MessageLength += msg.LenIE;//26 00 00 00 1A
msg.SignIE = int.Parse(userGroupBox16.Tag.ToString());// 00 0B
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
string time1 = tbx0064.Text.Replace("-", "");
string time2 = time1.Replace(" ", "");
string time = time2.Replace(":", "");//20170823150400
byte[] b9 = StrConverter.strToBytes.str1ToBytes(time.Substring(12, 2));
byte[] b10 = StrConverter.strToBytes.str1ToBytes(time.Substring(10, 2));
byte[] b11 = StrConverter.strToBytes.str1ToBytes(time.Substring(8, 2));
byte[] b12 = StrConverter.strToBytes.str1ToBytes(time.Substring(6, 2));
byte[] b13 = StrConverter.strToBytes.str1ToBytes(time.Substring(4, 2));
byte[] b14 = StrConverter.strToBytes.str2ToBytes(time.Substring(0, 4));
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
arr.AddRange(b9);
arr.AddRange(b10);
arr.AddRange(b11);
arr.AddRange(b12);
arr.AddRange(b13);
arr.AddRange(b14);
}
#endregion
#region IQ数据通道配置
if (userGroupBox21.IsChecked)//IQ数据通道配置
{
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(RRUParamSet.Tag.ToString());//00 00 00 3d
msg.LenIE = 8;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox21.Tag.ToString());// 01 f5
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
msg.Item = int.Parse(cbx0025.Text);//01
byte[] b9 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = int.Parse(cbx0026.Text);//01
byte[] b10 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = int.Parse(cbx0027.Text);//01
byte[] b11 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = int.Parse(cbx0028.Text);//01
byte[] b12 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
arr.AddRange(b9);
arr.AddRange(b10);
arr.AddRange(b11);
arr.AddRange(b12);
}
#endregion
#region AGC配置请求
if (userGroupBox22.IsChecked)//AGC配置请求
{
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(RRUParamSet.Tag.ToString());//00 00 00 3d
msg.LenIE = 7;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox22.Tag.ToString());// 27 89
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
msg.Item = int.Parse(cbx0029.Text);//01
byte[] b9 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = cbx0030.SelectedIndex;//00
byte[] b10 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Sitem = short.Parse(cbx0031.Text);//F1
byte[] b11 = StrConverter.strToBytes.str1ToBytes(msg.Sitem.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
arr.AddRange(b9);
arr.AddRange(b10);
arr.AddRange(b11);
}
#endregion
#region CPU占用率统计周期配置
if (userGroupBox17.IsChecked)//CPU占用率统计周期配置
{
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(RRUParamSet.Tag.ToString());
msg.LenIE = 8;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox17.Tag.ToString());
msg.Item = int.Parse(tbx0065.Text);
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b9 = StrConverter.strToBytes.str4ToBytes(msg.Item.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
arr.AddRange(b9);
}
#endregion
#region 驻波比门限配置
if (userGroupBox24.IsChecked)//驻波比门限配置
{
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(RRUParamSet.Tag.ToString());//00 00 00 3d
msg.LenIE = 12;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox24.Tag.ToString());// 01 f6
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
arr.AddRange(b7);
arr.AddRange(b8);
double temp = (double.Parse(tbx0066.Text)) * 10;//00 00 00 19
byte[] b9 = StrConverter.strToBytes.str4ToBytes(temp.ToString());
arr.AddRange(b9);
msg.Temp = (double.Parse(tbx0067.Text)) * 10;//00 00 00 23
byte[] b10 = StrConverter.strToBytes.str4ToBytes(msg.Temp.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b10);
}
#endregion
#region Ir口工作模式配
if (userGroupBox23.IsChecked)//Ir口工作模式配
{
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(RRUParamSet.Tag.ToString());
msg.LenIE = 8;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox23.Tag.ToString());
msg.Item = cbx0038.SelectedIndex + 1;
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b9 = StrConverter.strToBytes.str4ToBytes(msg.Item.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
arr.AddRange(b9);
}
#endregion
#region 过温门限配置
if (userGroupBox18.IsChecked)//过温门限配置
{
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(RRUParamSet.Tag.ToString());
msg.LenIE = 16;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox18.Tag.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
msg.Item = cbx0032.SelectedIndex;
byte[] b9 = StrConverter.strToBytes.str4ToBytes(msg.Item.ToString());
msg.Item = int.Parse(tbx0068.Text);
byte[] b10 = StrConverter.strToBytes.str4ToBytes(msg.Item.ToString());
msg.Item = int.Parse(tbx0069.Text);
byte[] b11 = StrConverter.strToBytes.str4ToBytes(msg.Item.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
arr.AddRange(b9);
arr.AddRange(b10);
arr.AddRange(b11);
}
#endregion
#region RRU级联功能配置
if (userGroupBox19.IsChecked)//RRU级联功能配置
{
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(RRUParamSet.Tag.ToString());
msg.LenIE = 8;
msg.MessageLength = int.Parse("15") + msg.LenIE;
msg.SignIE = int.Parse(userGroupBox19.Tag.ToString());
msg.Item = cbx0033.SelectedIndex;
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b9 = StrConverter.strToBytes.str4ToBytes(msg.Item.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
arr.AddRange(b9);
}
#endregion
#region 天线配置
if (userGroupBox20.IsChecked)//天线配置
{
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(RRUParamSet.Tag.ToString());//00 00 00 3d
msg.LenIE = 10;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox20.Tag.ToString());// 01 f6
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
msg.Item = (cbx0034.SelectedIndex) + 1;
byte[] b9 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = (cbx0035.SelectedIndex + 1);
byte[] b10 = StrConverter.strToBytes.str1ToBytes(msg.Item.ToString());
msg.Item = cbx0036.SelectedIndex;
byte[] b11 = StrConverter.strToBytes.str2ToBytes(msg.Item.ToString());
msg.Item = cbx0037.SelectedIndex;
byte[] b12 = StrConverter.strToBytes.str2ToBytes(msg.Item.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
arr.AddRange(b9);
arr.AddRange(b10);
arr.AddRange(b11);
arr.AddRange(b12);
}
#endregion
}
#endregion
}
#endregion
#region 版本信息
else if (tblModel.SelectedIndex == 2)
{
#region 消息头
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(VersionMsg.Tag.ToString());//51 00 00 00 33
msg.MessageLength = int.Parse("15");
msg.SendCount = int.Parse(sendCount.Text);//00 00 00 00
byte[] b02 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b3 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Parent.Tag.ToString()).ToString());
byte[] b4 = StrConverter.strToBytes.str1ToBytes(int.Parse(bbuValue.Text).ToString());
byte[] b5 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Tag.ToString()).ToString());
byte[] b6 = StrConverter.strToBytes.str4ToBytes(msg.SendCount.ToString());
arr.AddRange(msg.MessageNumber);
arr.AddRange(b02);
arr.AddRange(b3);
arr.AddRange(b4);
arr.AddRange(b5);
arr.AddRange(b6);
#endregion
#region 硬件版本信息
if (userGroupBox30.IsChecked)//硬件版本信息
{
msg.LenIE = 52;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox30.Tag.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
byte[] b9 = StrConverter.strToBytes.str32ToBytes("0");
byte[] b10 = StrConverter.strToBytes.str16ToBytes("0");
arr.AddRange(b9);
arr.AddRange(b10);
}
#endregion
#region 软件版本信息
if (userGroupBox31.IsChecked)//软件版本信息
{
msg.LenIE = 84;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox31.Tag.ToString());
byte[] b11 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b12 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b11);
arr.AddRange(b12);
byte[] b13 = StrConverter.strToBytes.str40ToBytes("0");
byte[] b14 = StrConverter.strToBytes.str40ToBytes("0");
arr.AddRange(b13);
arr.AddRange(b14);
}
#endregion
}
#endregion
#region 告警管理
else if (tblModel.SelectedIndex == 3)
{ }
#endregion
#region 日志管理
else if (tblModel.SelectedIndex == 4)
{ }
#endregion
#region 内部测试
else if (tblModel.SelectedIndex == 5)
{ }
#endregion
#region 时延测量
else if (tblModel.SelectedIndex == 6)
{ }
#endregion
#region 复位
else if (tblModel.SelectedIndex == 7)
{ }
#endregion
byte[] data = (byte[])arr.ToArray(typeof(byte));
Send(client, data);
tbxShowData.AppendText(DateTime.Now.ToString("G") + "发送" + tempBTN.Text + "命令: " + BitConverter.ToString(data) + "\r\n");
Receive(client);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "请连接", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void Send(Socket client, byte[] b)
{
//格式转换
byte[] byteData = b;
//开始发送数据到远程设备
client.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), client);
}
//接收数据
private void Receive(Socket client)
{
try
{
//构造容器state
StateObject state = new StateObject();
state.newsocket = client;
int i = client.Receive(state.buffer, state.buffer.Length, 0);//接收数据,返回每次接收的字节总数
byte[] data = new byte[i];
for (int j = 0; j < i; j++)
{
data[j] = state.buffer[j];
}
//这里要对接收的数据进行处理
DefaultReceived(data);
tbxShowData.AppendText(DateTime.Now.ToString("G") + "返回接收命令: " + BitConverter.ToString(data) + "\r\n");
int a = int.Parse(recieveCount.Text);
a++;
recieveCount.Text = a.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}

//tbxShowData.AppendText(DateTime.Now.ToString("G") + "返回接收命令: " + BitConverter.ToString(state.buffer) + "\r\n");

}
//对接收的数据进行处理 显示到界面上
public void DefaultReceived(byte[] s)
{
#region 消息头
byte[] Data = s;
string str = BitConverter.ToString(Data);
string str1 = str.Replace("-", "");
CMessageType msg = new CMessageType();
int MessageLength = 15 * 2;
msg.LmessageNumber1 = Convert.ToUInt32(str1.Substring(0, 8), 16);
msg.LMessageLength1 = Convert.ToUInt32(str1.Substring(8, 8), 16);
msg._RRUID1 = (int)Convert.ToUInt32(str1.Substring(16, 2), 16);
msg._BBUID1 = (int)Convert.ToUInt32(str1.Substring(18, 2), 16);
msg.FPort = (int)Convert.ToUInt32(str1.Substring(20, 2), 16);
msg.SendCount = (int)Convert.ToUInt32(str1.Substring(22, 8), 16);
#endregion
if (tblModel.SelectedIndex == 1)
{
#region 状态查询响应
if (QueryOrSet.SelectedIndex == 0)
{
#region 射频通道状态响应
if (RFChannel.IsChecked)//射频通道状态响应
{
msg.LenIE = 13 * 2;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
msg.Item = (int)Convert.ToUInt32(strRF.Substring(8, 2), 16);
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(10, 8), 16);
if (msg.Litem == 0)
tbx0015.Text = "未使能";
else if (msg.Litem == 1)
tbx0015.Text = "使能,无故障";
else if (msg.Litem == 2)
tbx0015.Text = "使能,有故障";
int Litem = (int)Convert.ToUInt32(strRF.Substring(18, 8), 16);
if (Litem == 0)
tbx0016.Text = "未使能";
else if (Litem == 1)
tbx0016.Text = "使能,无故障";
else if (Litem == 2)
tbx0016.Text = "使能,有故障";
}
#endregion
#region 载波状态响应
if (cbxCarrierStatus.IsChecked)//载波状态响应
{
txt0025.Text = "";
msg.LenIE = 10 * 12;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
int index = 0;
for (int i = 1; i < 4; i++)
{
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(index, 4), 16);
index += 4;
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(index, 4), 16);
index += 4;
msg.Item = (int)Convert.ToUInt32(strRF.Substring(index, 2), 16);
index += 2;
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(index, 2), 16);
index += 2;
int temp = (int)Convert.ToUInt32(strRF.Substring(index, 8), 16);
if (temp == 0)
{
tbx0017.Text += "天线组号:" + msg.Item.ToString() + ",载波号:" + msg.Litem.ToString() + ",状态:使能" + "\r\n";
}
else if (temp == 1)
{ tbx0017.Text += "天线组号:" + msg.Item.ToString() + ",载波号:" + msg.Litem.ToString() + ",状态:去使能" + "\r\n"; }
index += 8;
}
for (int i = 1; i < 4; i++)
{
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(index, 4), 16);
index += 4;
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(index, 4), 16);
index += 4;
msg.Item = (int)Convert.ToUInt32(strRF.Substring(index, 2), 16);
index += 2;
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(index, 2), 16);
index += 2;
int temp = (int)Convert.ToUInt32(strRF.Substring(index, 8), 16);
if (temp == 0)
{
tbx0017.Text += "天线组号:" + msg.Item.ToString() + ",载波号:" + msg.Litem.ToString() + ",状态:使能" + "\r\n";
}
else if (temp == 1)
{ tbx0017.Text += "天线组号:" + msg.Item.ToString() + ",载波号:" + msg.Litem.ToString() + ",状态:去使能" + "\r\n"; }
index += 8;
}
}
#endregion
#region 本振状态响应
if (userGroupBox1.IsChecked)//本振状态响应
{
txt0024.Text = "";
msg.LenIE = 12 * 10;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
for (int i = 1; i < 6; i++)
{
int index = 8;
msg.Item = (int)Convert.ToUInt32(strRF.Substring(index, 8), 16);
index += 8;
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(index, 8), 16);
if (msg.Litem == 0)
{
tbx0020.Text += "本振" + i + "(频率:" + ((double)msg.Item).ToString("0.00") + "MHZ,状态:" + "锁定)" + "\r\n";
}
else if (msg.Litem == 1)
{ tbx0020.Text += "本振" + i + "(频率:" + ((double)msg.Item).ToString("0.00") + "MHZ,状态:" + "失锁)" + "\r\n"; }
index += 8;
}
}
#endregion
#region 时钟状态
if (userGroupBox2.IsChecked)//时钟状态响应
{
msg.LenIE = 8 * 2;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(8, 8), 16);
if (msg.Litem == 0)
tbx0018.Text = "同步";
else if (msg.Litem == 1)
tbx0018.Text = "失步";
}
#endregion
#region RRU运行状态
if (userGroupBox3.IsChecked)//RRU运行状态响应
{
msg.LenIE = 8 * 2;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
msg.Item = (int)Convert.ToUInt32(strRF.Substring(8, 8), 16);
if (msg.Litem == 0)
tbx0019.Text = "未运营";
else if (msg.Litem == 1)
tbx0019.Text = "测试中";
else if (msg.Litem == 2)
tbx0019.Text = "运营中";
}
#endregion
#region IR口工作模式状态响应
if (userGroupBox4.IsChecked)//IR口工作模式状态响应
{
msg.LenIE = 8 * 2;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
msg.Item = (int)Convert.ToUInt32(strRF.Substring(8, 8), 16);
if (msg.Item == 1)
tbx0025.Text = "普通模式";
else if (msg.Item == 2)
tbx0025.Text = "级连模式";
else if (msg.Item == 3)
tbx0025.Text = "主备模式";
else if (msg.Item == 4)
tbx0025.Text = "负荷分担模式";
}
#endregion
#region 初始化校准状态响应
if (userGroupBox5.IsChecked)//初始化校准状态响应
{
msg.LenIE = 20 * 4;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
msg.Item = (int)Convert.ToUInt32(strRF.Substring(8, 8), 16);
if (msg.Item == 0)
tbx0021.Text = "1";
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(16, 8), 16);
if (msg.Litem == 0)
tbx0022.Text = "成功";
else if (msg.Litem == 1)
tbx0022.Text = "失败";
msg.Item = (int)Convert.ToUInt32(strRF.Substring(24, 8), 16);
if (msg.Item == 0)
tbx0023.Text = "1";
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(32, 8), 16);
if (msg.Litem == 0)
tbx0024.Text = "成功";
else if (msg.Litem == 1)
tbx0024.Text = "失败";
}
#endregion
#region 光口信息查询状态响应
if (userGroupBox6.IsChecked)//光口信息查询状态响应
{
msg.LenIE = 37 * 2;
string strRF = str1.Substring(MessageLength, msg.LenIE);//000000030000
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
msg.Item = (int)Convert.ToUInt32(strRF.Substring(8, 2), 16);
if (msg.Item == 0)
cbx0021.SelectedIndex = 0;
else if (msg.Item == 1)
cbx0021.SelectedIndex = 1;
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(10, 4), 16);
tbx0026.Text = msg.Litem.ToString().Replace("FF", "");
msg.Item = (int)Convert.ToUInt32(strRF.Substring(14, 4), 16);
tbx0027.Text = msg.Item.ToString().Replace("FF", "");
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(18, 2), 16);
if (msg.Litem == 0)
tbx0028.Text = "不在位";
else if (msg.Litem == 1)
tbx0028.Text = "在位";
string Item = strRF.Substring(20, 32);//7A68656E677765690000000000000000
char[] cc = Item.ToArray();
for (int i = 0; i < Item.Length; i = i + 2)
{
int temp = (int)Convert.ToUInt32(Item.Substring(i, 2), 16);
cc[i / 2] = (char)temp;
}
Item = new string(cc);
tbx0029.Text = Item.Replace("\0", "").Replace("0", "").Replace("FF", "").Replace("ÿ", "");
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(52, 4), 16);
tbx0030.Text = msg.Litem.ToString().Replace("FF", "");
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(56, 2), 16);
tbx0031.Text = msg.Litem.ToString().Replace("FF", "");
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(58, 4), 16);
tbx0032.Text = msg.Litem.ToString().Replace("FF", "");
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(62, 4), 16);
tbx0033.Text = msg.Litem.ToString().Replace("FF", "");
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(66, 2), 16);
tbx0034.Text = msg.Litem.ToString().Replace("FF", "");
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(68, 2), 16);
tbx0035.Text = msg.Litem.ToString().Replace("FF", "");
//string str6 = strRF.Substring(72, 2);
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(70, 2), 16);
tbx0036.Text = msg.Litem.ToString();
string str6 = strRF.Substring(72, 2);
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(72, 2), 16);
tbx0037.Text = msg.Litem.ToString();
}
}
#endregion
#endregion
#region 参数查询
if (QueryOrSet.SelectedIndex == 1)
{
#region 消息头
msg.LmessageNumber1 = Convert.ToUInt32(str1.Substring(0, 8), 16); //42 0000002A
msg.LMessageLength1 = Convert.ToUInt32(str1.Substring(8, 8), 16);//28 0000001C
msg._RRUID1 = (int)Convert.ToUInt32(str1.Substring(16, 2), 16); //01
msg._BBUID1 = (int)Convert.ToUInt32(str1.Substring(18, 2), 16);// 00
msg.FPort = (int)Convert.ToUInt32(str1.Substring(20, 2), 16);//00
msg.SendCount = (int)Convert.ToUInt32(str1.Substring(22, 8), 16);//00000001
#endregion
#region 系统时间查询
if (userGroupBox7.IsChecked)//系统时间查询
{
msg.LenIE = 11 * 2;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
string second = ((int)Convert.ToUInt32(strRF.Substring(8, 2), 16)).ToString();
string minute = ((int)Convert.ToUInt32(strRF.Substring(10, 2), 16)).ToString();
string hour = ((int)Convert.ToUInt32(strRF.Substring(12, 2), 16)).ToString();
string day = ((int)Convert.ToUInt32(strRF.Substring(14, 2), 16)).ToString();
string month = ((int)Convert.ToUInt32(strRF.Substring(16, 2), 16)).ToString();
string year = ((int)Convert.ToUInt32(strRF.Substring(18, 4), 16)).ToString();
tbx0038.Text = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
}
#endregion
#region CPU占用率
if (userGroupBox8.IsChecked)//CPU占用率
{
msg.LenIE = 8 * 2;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
msg.Item = (int)Convert.ToUInt32(strRF.Substring(8, 8), 16);
tbx0039.Text = msg.Item.ToString();
}
#endregion
#region CPU占用率周期查询
if (userGroupBox9.IsChecked)//CPU占用率周期查询
{
msg.LenIE = 8 * 2;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
msg.Item = (int)Convert.ToUInt32(strRF.Substring(8, 8), 16);
tbx0040.Text = msg.Item.ToString();
}
#endregion
#region RRU温度
if (userGroupBox10.IsChecked)//RRU温度
{
tbx0041.Text = "";
msg.LenIE = 13 * 4;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
int index = 0;
for (int i = 1; i < 3; i++)
{
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(index, 4), 16);
index += 4;
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(index, 4), 16);
index += 4;
msg.Item = (int)Convert.ToUInt32(strRF.Substring(index, 8), 16);
cbx0022.SelectedIndex = msg.Item;
index += 8;
msg.Item = (int)Convert.ToUInt32(strRF.Substring(index, 2), 16);
index += 2;
msg.Litem = Convert.ToUInt32(strRF.Substring(index, 8), 16);
index += 8;
tbx0041.Text += "射频通道号[" + msg.Item.ToString() + "] 温度:" + msg.Litem.ToString() + "℃" + "\r\n";
}

}
#endregion
#region 驻波比状态
if (userGroupBox11.IsChecked)//驻波比状态
{
msg.LenIE = 9 * 2;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
msg.Item = (int)Convert.ToUInt32(strRF.Substring(8, 2), 16);
cbx0023.SelectedIndex = msg.Item;
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(10, 8), 16);
tbx0042.Text = msg.Litem.ToString();
}
#endregion
#region 驻波比门限查询
if (userGroupBox12.IsChecked)//驻波比门限查询
{
msg.LenIE = 12 * 2;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
msg.Item = (int)Convert.ToUInt32(strRF.Substring(8, 8), 16);
tbx0045.Text = ((double)((double)msg.Item / 10)).ToString();
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(16, 8), 16);
tbx0046.Text = ((double)((double)msg.Litem / 10)).ToString();
}
#endregion
#region 过温门限值
if (userGroupBox13.IsChecked)//过温门限值
{
msg.LenIE = 12 * 2;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
msg.Item = (int)Convert.ToUInt32(strRF.Substring(8, 8), 16);
tbx0043.Text = msg.Item.ToString();
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(16, 8), 16);
tbx0044.Text = msg.Litem.ToString();
}
#endregion
#region 输出功率
if (userGroupBox14.IsChecked)//输出功率
{
msg.LenIE = 7 * 2;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
msg.Item = (int)Convert.ToUInt32(strRF.Substring(8, 2), 16);
cbx0024.SelectedIndex = msg.Item;
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(10, 4), 16);
tbx0047.Text = ((double)((double)msg.Litem / 10)).ToString("0.00"); ;
}
#endregion
#region 状态机
if (userGroupBox15.IsChecked)//状态机
{
msg.LenIE = 5 * 2;
string strRF = str1.Substring(MessageLength, msg.LenIE);
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(8, 2), 16);
if (msg.Litem == 0)
{ tbx0048.Text = "State A"; }
else if (msg.Litem == 1)
{ tbx0048.Text = "State B"; }
else if (msg.Litem == 2)
{ tbx0048.Text = "State C"; }
else if (msg.Litem == 3)
{ tbx0048.Text = "State D"; }
else if (msg.Litem == 4)
{ tbx0048.Text = "State E"; }
else if (msg.Litem == 5)
{ tbx0048.Text = "State F"; }
else if (msg.Litem == 6)
{ tbx0048.Text = "State G"; }
}
#endregion
}
#endregion
}
else if (tblModel.SelectedIndex == 2)
{
#region 硬件版本信息响应
if (userGroupBox31.IsChecked || userGroupBox30.IsChecked)//硬件版本信息响应
{
msg.LenIE = 136 * 2;
string strRF = str1.Substring(MessageLength, msg.LenIE);//0006 0054 475700000000000000000000000000000000000000000000000000000000000000000000000000004757000000000000
MessageLength += msg.LenIE;
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
#region 软件版本信息
string Item = strRF.Substring(8, 80);
char[] cc = Item.ToArray();
for (int i = 0; i < Item.Length; i = i + 2)
{
int temp = (int)Convert.ToUInt32(Item.Substring(i, 2), 16);
cc[i / 2] = (char)temp;
}
Item = new string(cc);
tbx0054.Text = Item.Replace("\0", "").Replace("0", "").Replace("FF", "").Replace("ÿ", "");
string LItem = strRF.Substring(88, 80);
char[] cc1 = LItem.ToArray();
for (int i = 0; i < LItem.Length; i = i + 2)
{
int temp = (int)Convert.ToUInt32(LItem.Substring(i, 2), 16);
cc1[i / 2] = (char)temp;
}
LItem = new string(cc1);
tbx0055.Text = Item.Replace("\0", "").Replace("0", "").Replace("FF", "").Replace("ÿ", "");
#endregion
msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(168, 4), 16);
msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(172, 4), 16);
string ItemL = strRF.Substring(176, 32);//00344765576569202020202020202020
char[] cc2 = Item.ToArray();
for (int i = 0; i < ItemL.Length; i = i + 2)
{
int temp = (int)Convert.ToUInt32(ItemL.Substring(i, 2), 16);
cc2[i / 2] = (char)temp;
}
Item = new string(cc2);
tbx0049.Text = Item.Replace("\0", "").Replace("0", "").Replace("FF", "").Replace("ÿ", "").Replace(" ", "");
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(208, 4), 16);//3032
tbx0050.Text = msg.Litem.ToString();
msg.Item = (int)Convert.ToUInt32(strRF.Substring(212, 4), 16);//3033
tbx0051.Text = msg.Item.ToString();
msg.Litem = (int)Convert.ToUInt32(strRF.Substring(216, 4), 16);//3436
tbx0052.Text = msg.Litem.ToString();
msg.Item = (int)Convert.ToUInt32(strRF.Substring(220, 20), 16);//00000000000000000000
tbx0053.Text = msg.Item.ToString();
string Item1 = strRF.Substring(240, 32);//30304857303100000000000000000000
char[] cc3 = Item.ToArray();
for (int i = 0; i < Item1.Length; i = i + 2)
{
int temp = (int)Convert.ToUInt32(Item1.Substring(i, 2), 16);
cc3[i / 2] = (char)temp;
}
Item = new string(cc3);
tbx0063.Text = Item.Replace("\0", "").Replace("0", "").Replace("FF", "").Replace("ÿ", "").Replace(" ", "");
}
#endregion
#region 软件版本信息响应
//if (userGroupBox31.IsChecked || userGroupBox30.IsChecked)//软件版本信息响应
//{
// msg.LenIE = 136 * 2;
// string strRF = str1.Substring(MessageLength, msg.LenIE);//0006 0054 475700000000000000000000000000000000000000000000000000000000000000000000000000004757000000000000
// MessageLength += msg.LenIE;
// msg.SignIE = (int)Convert.ToUInt32(strRF.Substring(0, 4), 16);
// msg.UlenIE1 = Convert.ToUInt32(strRF.Substring(4, 4), 16);
// #region 软件版本信息
// string Item = strRF.Substring(8, 32);
// char[] cc = Item.ToArray();
// for (int i = 0; i < Item.Length; i = i + 2)
// {
// int temp = (int)Convert.ToUInt32(Item.Substring(i, 2), 16);
// cc[i / 2] = (char)temp;
// }
// Item = new string(cc);
// tbx0054.Text = Item.Replace("\0", "").Replace("0", "").Replace("FF", "").Replace("ÿ", "");
// string LItem = strRF.Substring(40, 32);
// char[] cc1 = LItem.ToArray();
// for (int i = 0; i < LItem.Length; i = i + 2)
// {
// int temp = (int)Convert.ToUInt32(LItem.Substring(i, 2), 16);
// cc1[i / 2] = (char)temp;
// }
// LItem = new string(cc1);
// tbx0055.Text = Item.Replace("\0", "").Replace("0", "").Replace("FF", "").Replace("ÿ", "");
// #endregion
// string ItemL = strRF.Substring(72, 32);
// char[] cc2 = Item.ToArray();
// for (int i = 0; i < ItemL.Length; i = i + 2)
// {
// int temp = (int)Convert.ToUInt32(ItemL.Substring(i, 2), 16);
// cc2[i / 2] = (char)temp;
// }
// Item = new string(cc2);
// tbx0049.Text = Item.Replace("\0", "").Replace("0", "").Replace("FF", "").Replace("ÿ", "");
// msg.Litem = (int)Convert.ToUInt32(strRF.Substring(104, 4), 16);
// tbx0050.Text = msg.Litem.ToString();
// msg.Item = (int)Convert.ToUInt32(strRF.Substring(108, 4), 16);
// tbx0051.Text = msg.Item.ToString();
// msg.Litem = (int)Convert.ToUInt32(strRF.Substring(112, 4), 16);
// tbx0052.Text = msg.Litem.ToString();
// msg.Item = (int)Convert.ToUInt32(strRF.Substring(116, 20), 16);
// tbx0053.Text = msg.Item.ToString();
//}
#endregion

}
}
//private void ReceiveCallback(IAsyncResult ar)
//{
// try
// {
// //从输入参数异步state对象中获取state和socket对象
// StateObject state = (StateObject)ar.AsyncState;//ar.AsyncState as Socket;
// Socket client = state.newsocket;
// int bytesRead =client.EndReceive(ar);
// if (bytesRead > 0)
// {
// state.sb.Append(BitConverter.ToString(state.buffer, 0, bytesRead));
// //继续读取
// client.BeginReceive(state.buffer, 0, bytesRead, 0, new AsyncCallback(ReceiveCallback), state);
// }
// else
// {
// //所有数据读取完毕
// if (state.sb.Length > 1)
// {
// response = state.sb.ToString();
// }
// //所有数据读取完毕的指示信号
// ReceiveDone.Set();
// }

// }
// catch (Exception e)
// {
// MessageBox.Show(e.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
// }
//}
/// <summary>
/// 发送数据中的异步
/// </summary>
/// <param name="ar"></param>
private void SendCallback(IAsyncResult ar)
{
try
{
//从state对象中获取socket
Socket client = (Socket)ar.AsyncState;
//完成数据发送
int bytesSend = client.EndSend(ar);
//指示数据已经发送完成,主线程继续
sendDone.Set();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// 清空所有TextBox里的内容
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void AllTextClear_Click_1(object sender, EventArgs e)
{
Control tempBTN = (Control)sender;
foreach (Control c in tempBTN.Parent.Controls)
{
if (c.GetType().Name == "TextBox")
{
c.Text = "";
}
//foreach (Control ctl in c.Controls)
//{
//if (ctl.GetType().Name == "TextBox")
//{
// ctl.Text = "";
//}

//}
}
}
//参数配置重置
private void btnReset_Click(object sender, EventArgs e)
{
textBox42.Text = "2017-08-23 15:04:00";
textBox5.Text = "60";
tbx0007.Text = "2.5";
textBox37.Text = "3.5";
textBox26.Text = "50";
textBox25.Text = "0";
}

private void MainForm_Load(object sender, EventArgs e)
{
cbx0002.SelectedIndex = 0;
cbx0005.SelectedIndex = 0;
cbx0008.SelectedIndex = 0;
cbx0009.SelectedIndex = 0;
cbx0010.SelectedIndex = 0;
cbx0011.SelectedIndex = 0;
cbx0012.SelectedIndex = 0;
cbx0013.SelectedIndex = 0;
cbx0014.SelectedIndex = 0;
cbx0019.SelectedIndex = 0;
cbx0022.SelectedIndex = 0;
cbx0023.SelectedIndex = 1;
cbx0040.SelectedIndex = 0;
}

private void button15_Click(object sender, EventArgs e)
{
try
{
if (client.Connected)
{
Button tempBTN = (Button)sender;
try
{
//这里对要发送的数据进行处理
ArrayList arr = new ArrayList();
CMessageType msg = new CMessageType();
int a = int.Parse(sendCount.Text);//发送消息流水号
a++;
sendCount.Text = a.ToString();
#region 消息头
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(tblModel.SelectedTab.Tag.ToString());//141
msg.MessageLength = int.Parse("15");
msg.SendCount = int.Parse(sendCount.Text);
byte[] b02 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b3 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Parent.Tag.ToString()).ToString());
byte[] b4 = StrConverter.strToBytes.str1ToBytes(int.Parse(bbuValue.Text).ToString());
byte[] b5 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Tag.ToString()).ToString());
byte[] b6 = StrConverter.strToBytes.str4ToBytes(msg.SendCount.ToString());
arr.AddRange(msg.MessageNumber);
arr.AddRange(b02);
arr.AddRange(b3);
arr.AddRange(b4);
arr.AddRange(b5);
arr.AddRange(b6);
#endregion
#region 复位
if (tblModel.SelectedIndex == 7)
{
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(tbpReset.Tag.ToString());//00 00 00 3d
msg.LenIE = 8;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(groupBox1.Tag.ToString());// 01 f6
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
msg.Item = cbx0036.SelectedIndex;
byte[] b11 = StrConverter.strToBytes.str4ToBytes(msg.Item.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
arr.AddRange(b11);
}
#endregion
else if (tblModel.SelectedIndex == 2)
{
#region 硬件版本信息
if (userGroupBox30.IsChecked)//硬件版本信息
{
msg.LenIE = 52;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox30.Tag.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
byte[] b9 = StrConverter.strToBytes.str32ToBytes("0");
byte[] b10 = StrConverter.strToBytes.str16ToBytes("0");
arr.AddRange(b9);
arr.AddRange(b10);
}
#endregion
}
byte[] data = (byte[])arr.ToArray(typeof(byte));
Send(client, data);
tbxShowData.AppendText(DateTime.Now.ToString("G") + "发送" + tempBTN.Text + "命令: " + BitConverter.ToString(data) + "\r\n");

}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);

}
}

private void tevRRU_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
//tblModel.Enabled = false;


tblModel.Enabled = true;

}
/// <summary>
/// 版本管理下载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button13_Click(object sender, EventArgs e)
{
try
{
if (client.Connected)
{
Button tempBTN = (Button)sender;
try
{
//这里对要发送的数据进行处理
ArrayList arr = new ArrayList();
CMessageType msg = new CMessageType();
int a = int.Parse(sendCount.Text);//发送消息流水号
a++;
sendCount.Text = a.ToString();
#region 消息头
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(tblModel.SelectedTab.Tag.ToString());//141
msg.MessageLength = int.Parse("15");
msg.SendCount = int.Parse(sendCount.Text);
byte[] b02 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b3 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Parent.Tag.ToString()).ToString());
byte[] b4 = StrConverter.strToBytes.str1ToBytes(int.Parse(bbuValue.Text).ToString());
byte[] b5 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Tag.ToString()).ToString());
byte[] b6 = StrConverter.strToBytes.str4ToBytes(msg.SendCount.ToString());
arr.AddRange(msg.MessageNumber);
arr.AddRange(b02);
arr.AddRange(b3);
arr.AddRange(b4);
arr.AddRange(b5);
arr.AddRange(b6);
#endregion
if (tblModel.SelectedIndex == 2)
{
#region 硬件版本信息
if (userGroupBox30.IsChecked)//硬件版本信息
{
msg.LenIE = 52;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox30.Tag.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
byte[] b9 = StrConverter.strToBytes.str32ToBytes("0");
byte[] b10 = StrConverter.strToBytes.str16ToBytes("0");
arr.AddRange(b9);
arr.AddRange(b10);
}
#endregion
}
byte[] data = (byte[])arr.ToArray(typeof(byte));
Send(client, data);
tbxShowData.AppendText(DateTime.Now.ToString("G") + "发送" + tempBTN.Text + "命令: " + BitConverter.ToString(data) + "\r\n");

}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);

}
}
/// <summary>
/// 版本管理激活
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button14_Click(object sender, EventArgs e)
{
try
{
if (client.Connected)
{
Button tempBTN = (Button)sender;
try
{
//这里对要发送的数据进行处理
ArrayList arr = new ArrayList();
CMessageType msg = new CMessageType();
int a = int.Parse(sendCount.Text);//发送消息流水号
a++;
sendCount.Text = a.ToString();
#region 消息头
msg.MessageNumber = StrConverter.strToBytes.str4ToBytes(tblModel.SelectedTab.Tag.ToString());//141
msg.MessageLength = int.Parse("15");
msg.SendCount = int.Parse(sendCount.Text);
byte[] b02 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
byte[] b3 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Parent.Tag.ToString()).ToString());
byte[] b4 = StrConverter.strToBytes.str1ToBytes(int.Parse(bbuValue.Text).ToString());
byte[] b5 = StrConverter.strToBytes.str1ToBytes(int.Parse(tevRRU.SelectedNode.Tag.ToString()).ToString());
byte[] b6 = StrConverter.strToBytes.str4ToBytes(msg.SendCount.ToString());
arr.AddRange(msg.MessageNumber);
arr.AddRange(b02);
arr.AddRange(b3);
arr.AddRange(b4);
arr.AddRange(b5);
arr.AddRange(b6);
#endregion
if (tblModel.SelectedIndex == 2)
{
#region 硬件版本信息
if (userGroupBox30.IsChecked)//硬件版本信息
{
msg.LenIE = 52;
msg.MessageLength += msg.LenIE;
msg.SignIE = int.Parse(userGroupBox30.Tag.ToString());
byte[] b7 = StrConverter.strToBytes.str2ToBytes(msg.SignIE.ToString());
byte[] b8 = StrConverter.strToBytes.str2ToBytes(msg.LenIE.ToString());
byte[] b2 = StrConverter.strToBytes.str4ToBytes(msg.MessageLength.ToString());
arr[4] = b2[0];
arr[5] = b2[1];
arr[6] = b2[2];
arr[7] = b2[3];
arr.AddRange(b7);
arr.AddRange(b8);
byte[] b9 = StrConverter.strToBytes.str32ToBytes("0");
byte[] b10 = StrConverter.strToBytes.str16ToBytes("0");
arr.AddRange(b9);
arr.AddRange(b10);
}
#endregion
}
byte[] data = (byte[])arr.ToArray(typeof(byte));
Send(client, data);
tbxShowData.AppendText(DateTime.Now.ToString("G") + "发送" + tempBTN.Text + "命令: " + BitConverter.ToString(data) + "\r\n");

}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);

}
}
}
}
View Code

 

posted @ 2018-01-18 23:11  (时光)光阴飞逝  阅读(308)  评论(0)    收藏  举报