//----------------------------------------------------------------------------------------------------------- private void RefreshComPortList() { System.Collections.Generic.List <string> comPortList = new System.Collections.Generic.List <string>(); USBCDCInterface cdcIf = new USBCDCInterface(); comPortList = cdcIf.EnumerateCDCPorts(); if (comPortList.Count == 0) { comPortList.Add("No Device Found"); } bool bListsTheSame = true; if (comPortList.Count != comPortCombo.Items.Count) { bListsTheSame = false; } else { int i; for (i = 0; i < comPortList.Count; ++i) { if (comPortList[i] != comPortCombo.Items[i].ToString()) { bListsTheSame = false; } } } if (!bListsTheSame) { comPortCombo.Items.Clear(); int i; for (i = 0; i < comPortList.Count; ++i) { comPortCombo.Items.Add(comPortList[i]); } comPortCombo.SelectedIndex = 0; } }
//------------------------------------------------------------------------------------------------------------ // Connect to the LapRF at the specified IP address private async void connectButton_Click(object sender, EventArgs e) { if (USBSelected()) { if (usbcdc_itf == null) { usbcdc_itf = new USBCDCInterface(comPortCombo.Text); await UpdatePassingRecord().ConfigureAwait(false); } } else { string host = ipAddressText.Text; int portNumber = 5403; // standard port number for the LapRF IPAddress[] IPs = Dns.GetHostAddresses(host); sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //asynchronous connect request IAsyncResult result = sock.BeginConnect(IPs[0], portNumber, null, null); } }