示例#1
0
文件: QA401.cs 项目: 95rade/Tractor
        public bool ConnectToDevice(out string result)
        {
            result = "";

            if (Qa401 != null)
            {
                return(true);
            }

            if (IsAppAlreadyRunning() == false)
            {
                LaunchApplication();
            }

            try
            {
                TcpChannelInst = new TcpChannel();
                ChannelServices.RegisterChannel(TcpChannelInst, false);

                Type requiredType = typeof(QA401Interface);

                Qa401 = (QA401Interface)Activator.GetObject(requiredType, "tcp://localhost:9401/QuantAsylumQA401Server");
                return(true);
            }
            catch (Exception ex)
            {
                result = ex.Message;
                Log.WriteLine(LogType.Error, "Exception in ConnectToDevice() " + ex.Message);
            }

            return(false);
        }
示例#2
0
        public Form1()
        {
            InitializeComponent();

            // Try to connect to QA400 Application. Note the code below is boilerplate, likely needed by any app that wants to connect
            // to the QA400 application. This is routine dotnet remoting code.
            try
            {
                TcpChannel tcpChannel = new TcpChannel();
                ChannelServices.RegisterChannel(tcpChannel, false);

                Type requiredType = typeof(QA401Interface);

                AudioAnalyzer = (QA401Interface)Activator.GetObject(requiredType, "tcp://localhost:9401/QuantAsylumQA401Server");
                LogData("QA401 Setup OK");
            }
            catch
            {
                // If the above fails for any reason, make sure the rest of the app can tell. We do that here by setting AudioAnalyzer to null.
                AudioAnalyzer = null;
                LogData("QA401 Setup failed");
            }
        }
示例#3
0
        // Get Name button. Retrieves the name of the equipment. Also an easy check if the remoting is working and able to talk to the host app. As we expect
        // this will be the first function called after a remoting setup, it's protected by try/catch. The subsequent calls will only check if AudioAnalyzer is
        // null. In other user code, after the setup code succeeds, use a call to GetName() to ensure the connection is working.
        private void button1_Click(object sender, EventArgs e)
        {
            if (AudioAnalyzer == null)
            {
                return;
            }

            try
            {
                Stopwatch sw = Stopwatch.StartNew();

                string name = AudioAnalyzer.GetName();

                sw.Stop();

                LogData(string.Format("{0}   [0:0.0 mS]", name, sw.Elapsed.TotalMilliseconds));
            }
            catch (Exception ex)
            {
                // If we end up here, then it means the connection to the analyzer failed.
                LogData(ex.Message);
                AudioAnalyzer = null;
            }
        }