internal void Save(XmlElement parent) { XmlElement node = Helper.CreateElement(parent, "ConnectionInformation"); Helper.AppendAttributeAndValue(node, "ConnectionType", ConnectionType.ToString()); if (ConnectionInfo is UdpConnectionInfo) { UdpConnectionInfo info = ConnectionInfo as UdpConnectionInfo; Helper.AppendAttributeAndValue(node, "SendIPAddress", info.SendIPAddress.ToString()); Helper.AppendAttributeAndValue(node, "SendPort", info.SendPort.ToString()); Helper.AppendAttributeAndValue(node, "AdapterIPAddress", info.AdapterIPAddress.ToString()); Helper.AppendAttributeAndValue(node, "ReceivePort", info.ReceivePort); Helper.AppendAttributeAndValue(node, "AdapterName", info.AdapterName); } else if (ConnectionInfo is SerialConnectionInfo) { SerialConnectionInfo info = ConnectionInfo as SerialConnectionInfo; Helper.AppendAttributeAndValue(node, "PortName", info.PortName); Helper.AppendAttributeAndValue(node, "BaudRate", info.BaudRate); Helper.AppendAttributeAndValue(node, "RtsCtsEnabled", info.RtsCtsEnabled); } else if (ConnectionInfo is SDCardFileConnectionInfo) { SDCardFileConnectionInfo info = ConnectionInfo as SDCardFileConnectionInfo; Helper.AppendAttributeAndValue(node, "FilePath", info.FilePath); } parent.AppendChild(node); }
public UdpConnectionImplementation(Connection connection, UdpConnectionInfo info, OscCommunicationStatistics statistics) { this.connection = connection; udpConnectionInfo = info; oscReceiver = new OscReceiver(info.AdapterIPAddress, info.ReceivePort, OscReceiver.DefaultMessageBufferSize, OscReceiver.DefaultPacketSize); oscReceiver.Statistics = statistics; oscSender = new OscSender(info.AdapterIPAddress, 0, info.SendIPAddress, info.SendPort, OscSender.DefaultMulticastTimeToLive, OscSender.DefaultMessageBufferSize, OscSender.DefaultPacketSize); oscSender.Statistics = statistics; }
private void UdpConnectionDialog_Load(object sender, EventArgs e) { UdpConnectionInfo defaults = new UdpConnectionInfo(); m_AdapterIPAddress.Items.Add(new IntefaceInfo() { NetworkInterface = defaults.NetworkAdapter, String = defaults.AdapterName, InterfaceName = defaults.AdapterName, IpAddress = defaults.AdapterIPAddress }); if (OnlyIpV4 == false) { UdpConnectionInfo defaultsIPv6 = UdpConnectionInfo.DefaultIPv6; m_AdapterIPAddress.Items.Add(new IntefaceInfo() { NetworkInterface = defaultsIPv6.NetworkAdapter, String = defaultsIPv6.AdapterName, InterfaceName = defaultsIPv6.AdapterName, IpAddress = defaultsIPv6.AdapterIPAddress }); } NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in interfaces) { var ipProps = adapter.GetIPProperties(); foreach (var ip in ipProps.UnicastAddresses) { if (ip.Address.AddressFamily == AddressFamily.InterNetwork || OnlyIpV4 == false && ip.Address.AddressFamily == AddressFamily.InterNetworkV6) { m_AdapterIPAddress.Items.Add(new IntefaceInfo() { NetworkInterface = adapter, String = adapter.Description + " (" + ip.Address + ")", InterfaceName = adapter.Description, IpAddress = ip.Address }); } } } m_AdapterIPAddress.SelectedIndex = 0; NetworkAdapter = null; prefixOscWithName = prefixName.Checked; LocalHost_CheckedChanged(this, EventArgs.Empty); SendIPAddress_TextChanged(this, EventArgs.Empty); SendPort_TextChanged(this, EventArgs.Empty); }
public void ConnectTo(ConnectionSearchResult info) { SelectTab(ConnectionTab.ModelView); ErrorsText.text = "No errors"; reporter.Clear(); Debug.Log($"ConnectTo ({info.DeviceDescriptor})"); HeaderName.text = info.DeviceDescriptor; HeaderDetails.text = info.ConnectionInfo.ToIDString(); switch (info.ConnectionType) { case ConnectionType.Udp: UdpConnectionInfo udpInfo = info.ConnectionInfo as UdpConnectionInfo; Thread thread = new Thread( delegate() { try { Debug.Log("Configure unique UDP connection"); UdpConnectionInfo newInfo = Connection.ConfigureUniqueUdpConnection(udpInfo, reporter); ConnectTo(newInfo); } catch (Exception ex) { reporter.OnException(this, new ExceptionEventArgs("The device could not be configured to use a unique connection. " + ex.Message, ex)); } } ); thread.Name = "Configure Unique UDP Connection"; thread.Start(); break; case ConnectionType.Serial: ConnectTo(info.ConnectionInfo as SerialConnectionInfo); break; default: break; } }
public void ConnectTo(ConnectionSearchInfo info) { reporter.Clear(); Debug.Log("ConnectTo (ConnectionSearchInfo)"); switch (info.ConnectionType) { case ConnectionType.Udp: UdpConnectionInfo udpInfo = info.ConnectionInfo as UdpConnectionInfo; Thread thread = new Thread(delegate() { try { Debug.Log("Configure unique UDP connection"); UdpConnectionInfo newInfo = Connection.ConfigureUniqueUdpConnection(udpInfo, reporter); ConnectTo(newInfo); } catch (Exception ex) { reporter.OnException(this, new ExceptionEventArgs("The device could not be configured to use a unique connection. " + ex.Message, ex)); } }); thread.Name = "Configure Unique UDP Connection"; thread.Start(); break; case ConnectionType.Serial: ConnectTo(info.ConnectionInfo as SerialConnectionInfo); break; default: break; } }
// TODO refactor this method to a helper / class of some kind private DialogResult ConnectToAllDevices(List <ConnectionSearchResult> connectionSearchResults, out List <Connection> resultConnections) { if (connectionSearchResults.Count == 0) { resultConnections = new List <Connection>(); return(DialogResult.OK); } List <Connection> connections = new List <Connection>(); DialogResult result = System.Windows.Forms.DialogResult.Cancel; // Begin ProgressDialog progress = new ProgressDialog(); progress.Text = "Connecting"; progress.Style = ProgressBarStyle.Continuous; progress.ProgressMessage = ""; progress.Progress = 0; progress.ProgressMaximum = (connectionSearchResults.Count * 4) - 1; Reporter reporter = new Reporter(); bool canceled = false; int currentProgress = 0; string currentConnectionString = ""; Thread connectingToMultipleConnections = new Thread(() => { progress.OnCancel += (o, args) => { canceled = true; }; EventHandler <MessageEventArgs> reportInfo = (o, args) => { progress.UpdateProgress(currentProgress, currentConnectionString + args.Message); }; reporter.Info += reportInfo; try { progress.UpdateProgress(0); for (int i = 0; i < connectionSearchResults.Count; i++) { if (canceled == true) { progress.UpdateProgress(currentProgress, string.Empty); return; } ConnectionSearchResult autoConnectionInfo = connectionSearchResults[i]; currentConnectionString = "Connecting to " + autoConnectionInfo.DeviceDescriptor + ". "; progress.UpdateProgress(currentProgress++, autoConnectionInfo.DeviceDescriptor); Connection connection = null; if (autoConnectionInfo.ConnectionType == ConnectionType.Udp) { #region Configure Unique Connection bool retryThis = true; do { try { UdpConnectionInfo udpConnectionInfo = NgimuApi.Connection.ConfigureUniqueUdpConnection( autoConnectionInfo.ConnectionInfo as UdpConnectionInfo, reporter); connection = new Connection(udpConnectionInfo); break; } catch (Exception ex) { StringBuilder fullMessageString = new StringBuilder(); fullMessageString.AppendLine("Error while connecting to " + autoConnectionInfo.DeviceDescriptor + "."); fullMessageString.AppendLine(); fullMessageString.Append("Could not configure a unique UDP connection."); switch (this.InvokeShowError(fullMessageString.ToString(), MessageBoxButtons.AbortRetryIgnore)) { case DialogResult.Abort: CloseAllConnections(connections); progress.DialogResult = DialogResult.Cancel; return; case DialogResult.Retry: break; case DialogResult.Ignore: retryThis = false; break; default: break; } } }while (retryThis == true); #endregion } else { connection = new Connection(autoConnectionInfo); } if (connection == null) { currentProgress += 3; progress.UpdateProgress(currentProgress); continue; } progress.UpdateProgress(currentProgress++); if (canceled == true) { progress.UpdateProgress(currentProgress); return; } #region Read Settings try { connection.Connect(); progress.UpdateProgress(currentProgress++); bool retryThis = false; do { if (connection.Settings.Read(reporter) != CommunicationProcessResult.Success) { bool allValuesFailed; bool allValuesSucceeded; string messageString = Settings.GetCommunicationFailureString(connection.Settings.Values, 20, out allValuesFailed, out allValuesSucceeded); StringBuilder fullMessageString = new StringBuilder(); fullMessageString.AppendLine("Error while connecting to " + autoConnectionInfo.DeviceDescriptor + "."); fullMessageString.AppendLine(); if (allValuesFailed == true) { fullMessageString.Append("Failed to read all settings."); } else { fullMessageString.Append("Failed to read the following settings:" + messageString); } switch (this.InvokeShowError(fullMessageString.ToString(), MessageBoxButtons.AbortRetryIgnore)) { case DialogResult.Abort: connection.Dispose(); CloseAllConnections(connections); progress.DialogResult = DialogResult.Cancel; return; case DialogResult.Retry: retryThis = true; break; case DialogResult.Ignore: retryThis = false; break; default: break; } } connections.Add(connection); }while (retryThis); } catch (Exception ex) { connection?.Dispose(); } #endregion progress.UpdateProgress(currentProgress++); } progress.DialogResult = System.Windows.Forms.DialogResult.OK; } finally { reporter.Info -= reportInfo; } }); connectingToMultipleConnections.Name = "Connecting to multiple connections"; connectingToMultipleConnections.Start(); result = progress.ShowDialog(this); resultConnections = new List <Connection>(connections); return(result); }