示例#1
0
        /// <summary>
        /// Initialzes all methods that are required to setup the class. Connection is established on port 1702.
        /// </summary>
        public void Initialize(string id, string host, ushort port, string username, string password, ushort useExternalConnection)
        {
            if (!isInitialized)
            {
                try
                {
                    coreId = id;

                    externalConnection = Convert.ToBoolean(useExternalConnection);

                    if (username.Length > 0)
                    {
                        this.username = username;
                    }
                    else
                    {
                        this.username = string.Empty;
                    }

                    if (password.Length > 0)
                    {
                        this.password = password;
                    }
                    else
                    {
                        this.password = string.Empty;
                    }

                    QsysCoreManager.AddCore(this);

                    if (debug == 1)
                    {
                        ErrorLog.Notice("QsysProcessor is initializing.");
                    }

                    commandQueue       = new CrestronQueue <string>();
                    responseQueue      = new CrestronQueue <string>();
                    commandQueueTimer  = new CTimer(CommandQueueDequeue, null, 0, 50);
                    responseQueueTimer = new CTimer(ResponseQueueDequeue, null, 0, 50);

                    client    = new TCPClientDevice();
                    client.ID = 1710;
                    client.ConnectionStatus += new StatusEventHandler(client_ConnectionStatus);
                    client.ResponseString   += new ResponseEventHandler(client_ResponseString);
                    client.Connect(host, port);
                }
                catch (Exception e)
                {
                    if (debug == 1 || debug == 2)
                    {
                        ErrorLog.Error("Error in QsysProcessor Iniitialize: {0}", e.Message);
                    }
                }
            }
        }