コード例 #1
0
        void OnDevInfoEvent(object sender, NurApi.DevInfoEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new MethodInvoker(delegate { OnDevInfoEvent(sender, e); }));
                return;
            }

            string mac = EthHelper.MacToString(e.data.eth.mac);

            NurApi.DevInfoData did;
            if (devices.TryGetValue(mac, out did))
            {
                devices[mac] = e.data;
            }
            else
            {
                devices.Add(mac, e.data);
            }

            deviceView.SelectedItems.Clear();
            deviceView.Items.Clear();
            foreach (NurApi.DevInfoData device in devices.Values)
            {
                string nurVersion = string.Format("{0}.{1}{2}",
                                                  device.nurVer[0].ToString(),
                                                  device.nurVer[1].ToString(),
                                                  Convert.ToChar(device.nurVer[2]));

                ListViewItem item = new ListViewItem(
                    new string[]
                {
                    device.eth.title,
                    EthHelper.IpToString(device.eth.ip),
                    device.eth.serverPort.ToString(),
                    EthHelper.EthAddrTypeToString(device.eth),
                    EthHelper.EthHostModeToString(device.eth),
                    EthHelper.EthHostModeToString(device),
                    EthHelper.MacToString(device.eth.mac),
                    new string(device.altSerial),
                    device.eth.version.ToString(),
                    nurVersion
                });

                item.Tag = device;
                deviceView.Items.Add(item);
            }

            deviceView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
        }
コード例 #2
0
 private void connectToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         ListViewItem item = deviceView.SelectedItems[0];
         if (item != null)
         {
             NurApi.DevInfoData data = (NurApi.DevInfoData)item.Tag;
             if (IsServer(data))
             {
                 if (ConnectToDevice != null)
                 {
                     connectBtn.Enabled = false;
                     ConnectToDevice(this, new DeviceArgs(EthHelper.IpToString(data.eth.ip), data.eth.serverPort));
                 }
             }
         }
     }
     catch (Exception)
     {
     }
 }