Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Set up Scope
            QAConnectionManager.LaunchAppIfNotRunning(QAConnectionManager.Devices.QA100);
            Scope = (QA100Interface)QAConnectionManager.ConnectTo(QAConnectionManager.Devices.QA100);

            // Setup PowerSupply
            QAConnectionManager.LaunchAppIfNotRunning(QAConnectionManager.Devices.QA300);
            PowerSupply = (QA300Interface)QAConnectionManager.ConnectTo(QAConnectionManager.Devices.QA300);
        }
        /// <summary>
        /// Connect to multiple devices. This is a bit trickier, because we can't use the default remoting connections becuase they
        /// will both want to use the same port. So, we need to add extra code to permit assigning different ports
        /// </summary>
        /// <returns></returns>
        private bool ConnectToQA100And300()
        {
            // First, we see if the QA100 application is already running. If there are zero instances of this
            // process, then we can assume it isn't running
            if (Process.GetProcessesByName("QAScope").Length == 0)
            {
                // Power supply application isn't running. Let the user know and then return false
                MessageBox.Show("The QA100 application is not running. Please start that application before attempting to control it remotely.");
                return(false);
            }

            // Next, we see if the QA300 application is already running. If there are zero instances of this
            // process, then we can assume it isn't running
            if (Process.GetProcessesByName("QA Power Supply").Length == 0)
            {
                // Power supply application isn't running. Let the user know and then return false
                MessageBox.Show("The QA300 application is not running. Please start that application before attempting to control it remotely.");
                return(false);
            }

// Try to connect to both the scope and power supply. If either fails for any reason, then both will fail
            try
            {
                // Scope first
                TcpChannel tcpChannel = (TcpChannel)Helper.GetChannel(4301, false);
                ChannelServices.RegisterChannel(tcpChannel, false);

                Type requiredType = typeof(Com.QuantAsylum.QA100Interface);

                Scope = (Com.QuantAsylum.QA100Interface)Activator.GetObject(requiredType, "tcp://localhost:9100/QuantAsylumQA100Server");

                // Power supply next
                tcpChannel = (TcpChannel)Helper.GetChannel(4300, false);
                ChannelServices.RegisterChannel(tcpChannel, false);

                requiredType = typeof(Com.QuantAsylum.QA300Interface);

                PowerSupply = (Com.QuantAsylum.QA300Interface)Activator.GetObject(requiredType, "tcp://localhost:9300/QuantAsylumQA300Server");
            }
            catch (Exception ex)
            {
                Scope = null; PowerSupply = null;
                return(false);
            }

            // If we get here, then everything worked: Both apps were running and we successfully connected to both
            return(true);
        }