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); }
private void beepToolStripMenuItem_Click(object sender, EventArgs e) { try { if (deviceView.SelectedItems.Count > 0) { // Send BEEP broadcast to SELECTED device ListViewItem item = deviceView.SelectedItems[0]; if (item != null) { NurApi.DevInfoData data = (NurApi.DevInfoData)item.Tag; // Convert MAC address to ASCII HEX bytes byte[] fdata = new byte[16]; string fstring = EthHelper.MacToString(data.eth.mac); fstring = fstring.Replace("-", ""); // remove separators fdata = System.Text.Encoding.ASCII.GetBytes(fstring); // Create Beep buffer byte[] beepBuf = new byte[2]; beepBuf[0] = (byte)60; // BeepTime beepBuf[1] = (byte)60; // BeepDuty // Send BEEP broadcast mApi.NurApiSendBroadcast( NurApi.BC_CMD_BEEP, NurApi.BC_FILTER_TYPE_MAC, NurApi.BC_FILTER_OP_EQUAL, fdata, fstring.Length, beepBuf, beepBuf.Length); } } else { // Send BEEP broadcast to ALL devices // Create Beep buffer byte[] beepBuf = new byte[2]; beepBuf[0] = (byte)60; // BeepTime beepBuf[1] = (byte)60; // BeepDuty // Send BEEP broadcast mApi.NurApiSendBroadcast( NurApi.BC_CMD_BEEP, NurApi.BC_FILTER_TYPE_NONE, 0, null, 0, beepBuf, beepBuf.Length); } } catch (Exception) { } }