private void XmlRespond(byte[] buffer, int len) { if (this.cbbDeviceID.InvokeRequired) { byte[] copy = new byte[len]; Array.Copy(buffer, copy, len); this.Invoke(UDPServices.GetInstance().xmlRespond_, new object[] { copy, len }); return; } int index = 0; int version = ISocket.GetInt(buffer, ref index); UDPServices.HCmdType cmd = (UDPServices.HCmdType)ISocket.GetShort(buffer, ref index); string id = ISocket.GetString(buffer, ref index, UDPServices.MAX_DEVICE_ID_LENGHT); if (id.IndexOf('\0') >= 0) { id = id.Remove(id.IndexOf('\0')); } if (id != this.cbbDeviceID.Text) { return; } string xml = ISocket.GetString(buffer, ref index, len - 6 - UDPServices.MAX_DEVICE_ID_LENGHT); this.ParseXml(xml); }
public AddressSet() { InitializeComponent(); //Initialize the socket listener, start the thread for socket monitoring SocketHelper.GetInstance().Init(); //Create udp service: support search control card, set control card IP address UDPServices.GetInstance(); UDPServices.GetInstance().xmlRespond_ += this.XmlRespond; }
public AddressSet() { InitializeComponent(); //初始化socket监听器, 开启线程进行socket监听 SocketHelper.GetInstance().Init(); //创建udp服务: 支持搜索控制卡、设置控制卡IP地址 UDPServices.GetInstance(); UDPServices.GetInstance().xmlRespond_ += this.XmlRespond; }
private void btnReget_Click(object sender, EventArgs e) { if (this.cbbDeviceID.Text == "") { return; } string cmd = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<sdk>\n" + " <in method=\"GetEth0Info\"/>" + "</sdk>\n"; UDPServices.GetInstance().SendCmd(this.cbbDeviceID.Text, cmd); }
//Control card ID number refresh event function private void btnRefresh_Click(object sender, EventArgs e) { //1. Clear items in the list //2. Get the control card list and add the control card ID to the list this.cbbDeviceID.Items.Clear(); HDeviceInfo[] devices = UDPServices.GetInstance().GetDevices(); for (int i = 0; i < devices.Length; i++) { this.cbbDeviceID.Items.Add(devices[i].id); } //3. Select the 0th item if (this.cbbDeviceID.Items.Count > 0) { this.cbbDeviceID.Text = (string)this.cbbDeviceID.Items[0]; } }
//控制卡ID号刷新事件函数 private void btnRefresh_Click(object sender, EventArgs e) { //1. 清空列表中的项 //2. 获取控制卡列表, 将控制卡ID添加到列表中 this.cbbDeviceID.Items.Clear(); HDeviceInfo[] devices = UDPServices.GetInstance().GetDevices(); for (int i = 0; i < devices.Length; i++) { this.cbbDeviceID.Items.Add(devices[i].id); } //3. 选中第0个项 if (this.cbbDeviceID.Items.Count > 0) { this.cbbDeviceID.Text = (string)this.cbbDeviceID.Items[0]; } }
private void btnSVOK_Click(object sender, EventArgs e) { if (this.cbbDeviceID.Text == "") { return; } string host = this.tbHost.Text; string port = this.tbPort.Text; string cmd = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<sdk>\n" + " <in method=\"SetSDKTcpServer\">\n" + " <server host=\"##host\" port=\"##port\"/>\n" + " </in>\n" + "</sdk>\n"; cmd = cmd.Replace("##host", host); cmd = cmd.Replace("##port", port); UDPServices.GetInstance().SendCmd(this.cbbDeviceID.Text, cmd); }
private void btnOK_Click(object sender, EventArgs e) { if (this.cbbDeviceID.Text == "") { return; } HnEthernetInfo nInfo = new HnEthernetInfo(); nInfo.valid = true; nInfo.enable = true; nInfo.dhcp = this.cbDhcpEnable.Checked; nInfo.ip = this.tbIP.Text; nInfo.mask = this.tbMask.Text; nInfo.gateway = this.tbGateway.Text; nInfo.dns = this.tbDNS.Text; HEthernetInfo info = this.N2Str(nInfo); string cmd = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<sdk>\n" + " <in method=\"SetEth0Info\">\n" + " <eth valid=\"true\">\n" + " <enable value=\"true\"/>\n" + " <dhcp auto=\"##dhcp\"/>\n" + " <address ip=\"##ip\" netmask=\"##netmask\" gateway=\"##gateway\" dns=\"##dns\"/>\n" + " </eth>\n" + " </in>\n" + "</sdk>\n"; cmd = cmd.Replace("##dhcp", info.dhcp); cmd = cmd.Replace("##ip", info.ip); cmd = cmd.Replace("##netmask", info.mask); cmd = cmd.Replace("##gateway", info.gateway); cmd = cmd.Replace("##dns", info.dns); UDPServices.GetInstance().SendCmd(this.cbbDeviceID.Text, cmd); }