/// <summary> /// Get list of servers available on network (always add localhost) /// </summary> /// <returns><c>true</c>, if discovery packet was sent, <c>false</c> otherwise.</returns> /// <param name="list">List of discovered servers</param> public List <DiscoveryResponse> GetServers() { // Send discovery packet List <DiscoveryResponse> list = new List <DiscoveryResponse>(); if (mProtocol.DiscoverRTServers(replyPort)) { if (mProtocol.DiscoveryResponses.Count > 0) { //Get list of all servers from protocol foreach (var discoveryResponse in mProtocol.DiscoveryResponses) { //add them to our list for user to pick from list.Add(discoveryResponse); } } } list.Add(new DiscoveryResponse { HostName = "Localhost", IpAddress = "127.0.0.1", Port = RTProtocol.Constants.STANDARD_BASE_PORT, InfoText = "", CameraCount = 0 }); return(list); }
private void Form1_Load(object sender, EventArgs e) { // Take the first parameter of the command line as ipaddress if any (like 192.168.10.156). var args = Environment.GetCommandLineArgs(); if (args.Length > 1) { ipAddress = args[1]; if (args.Length > 2) { // If a second command line parameter exists then use this as the body to display. // Useful if project/file contains multiple bodies since this program only displays information about one body. sixDofBodyNameToUse = args[2]; } } else { // If no command line parameters was found the try and discover servers on the network if (rtProtocol.DiscoverRTServers(4545)) { // If any found use the ipaddress of the first in the list... var discoveryResponses = rtProtocol.DiscoveryResponses; if (discoveryResponses.Count >= 1) { ipAddress = discoveryResponses.First().IpAddress; } } } // Start a timer with a 50ms tick frequency timer.Tick += Timer_Tick; timer.Interval = 50; timer.Start(); }
public void DiscoverQTMServers(ushort discoveryPort) { if (mRtProtocol.DiscoverRTServers(discoveryPort)) { var discoveryResponses = mRtProtocol.DiscoveryResponses; foreach (var discoveryResponse in discoveryResponses) { Console.WriteLine("Host:{0,20}\tIP Adress:{1,15}\tInfo Text:{2,20}\tCamera count:{3,3}", discoveryResponse.HostName, discoveryResponse.IpAddress, discoveryResponse.InfoText, discoveryResponse.CameraCount); } } }
private void RefreshDiscoveryResponses() { observableDiscoveryResponses = new ObservableCollection <ObservableDiscoveryResponse>(); if (rtProtocol.DiscoverRTServers(4547)) { HashSet <DiscoveryResponse> discoveryResponses = rtProtocol.DiscoveryResponses; foreach (DiscoveryResponse dr in discoveryResponses) { ObservableDiscoveryResponse odr = new ObservableDiscoveryResponse { HostName = dr.HostName, IpAddress = dr.IpAddress, Port = dr.Port, InfoText = dr.InfoText, CameraCount = dr.CameraCount }; observableDiscoveryResponses.Add(odr); } } ResultsListView.ItemsSource = observableDiscoveryResponses; }
private static RTProtocol EstablishConnection(string qtmName) { RTProtocol rtProtocol = new RTProtocol(); Console.WriteLine("Discovering QTM servers on the network..."); // We know the name of the computer we want to connect to, find out its IP DiscoveryResponse qtmToConnect = new DiscoveryResponse(); if (rtProtocol.DiscoverRTServers(qtmDiscoveryPort)) { var discoveryResponses = rtProtocol.DiscoveryResponses; if (discoveryResponses.Count != 0) { foreach (var discoveryResponse in discoveryResponses) { Console.WriteLine( "Discovered {0,16} {1,16} {2,16} {3,3} cameras", discoveryResponse.HostName, discoveryResponse.IpAddress, discoveryResponse.InfoText, discoveryResponse.CameraCount ); if (discoveryResponse.HostName == qtmName) { qtmToConnect = discoveryResponse; } } } else { Console.WriteLine("No QTM servers found on available networks!"); } } // Only connect if the desired computer name is found if (qtmToConnect.HostName == qtmName) { // Try max. 5 times, then admit failure for (int i = 0; i < 5; i++) { if (rtProtocol.IsConnected()) { break; } if (!rtProtocol.Connect(qtmToConnect.IpAddress)) { Console.WriteLine("Trying to connect..."); Thread.Sleep(1000); } else { Console.WriteLine( "Connected to {0} @ {1}!", qtmToConnect.HostName, qtmToConnect.IpAddress ); } } } else { Console.WriteLine("The desired QTM server ({0}) was not found!", qtmName); } // Get settings if connected to QTM, otherwise alert user and continue if (rtProtocol.IsConnected()) { // 6DOF settings Console.WriteLine("Getting 6DOF settings..."); // Try max. 5 times, then admit failure for (int i = 0; i < 5; i++) { if (rtProtocol.Get6dSettings()) { Settings6D settings6D = rtProtocol.Settings6DOF; int bodyCount = settings6D.BodyCount; Console.WriteLine("{0} 6DOF bodies found.", bodyCount); List <Settings6DOF> qtmBodies = settings6D.Bodies; foreach (Settings6DOF body in qtmBodies) { Console.WriteLine("\t Found 6DOF body: {0}", body.Name); } break; } else { Console.WriteLine("Failed to get 6DOF settings!"); } } } else { Console.WriteLine("Could not communicate with QTM!"); } // Disconnect on exit AppDomain.CurrentDomain.ProcessExit += (sender, e) => OnProcessExit(sender, e, rtProtocol); return(rtProtocol); }