Connect() 공개 메소드

public Connect ( ) : void
리턴 void
예제 #1
0
        public void SendCommand_Network(Receiver r, String command)
        {
            try
            {
                int length = command.Length;
                length++;
                int  total = length + 16;
                char code  = (char)length;

                // build up packet header and rest of command - followed by <CR> (chr(13))
                string line = "ISCP\x00\x00\x00\x10\x00\x00\x00" + code + "\x01\x00\x00\x00" + command + "\x0D";

                if (r.tcpClient.Connected)
                {
                    // send command to receiver
                    r.clientStreamWriter.WriteLine(line);
                    r.clientStreamWriter.Flush();
                    Log.Info("Sent command: " + line);
                }
                else
                {
                    try
                    {
                        if (r.Type == "Network" && r.IP != "" && r.NetworkPort != 0)
                        {
                            Log.Debug("Creating TCP Client: ip-" + r.IP + " port-" + r.NetworkPort);
                            r.tcpClient = new TcpClient(r.IP, r.NetworkPort);

                            //get a network stream from server
                            r.clientSockStream = r.tcpClient.GetStream();

                            // create new writer and reader stream to send and receive
                            r.clientStreamWriter = new StreamWriter(r.clientSockStream);
                            r.clientStreamReader = new StreamReader(r.clientSockStream);

                            //Start listening
                            r.Connect();

                            // send command to receiver
                            //
                            r.clientStreamWriter.WriteLine(line);
                            r.clientStreamWriter.Flush();
                            Log.Info("Sent command: " + line);
                        }
                        else
                        {
                            Log.Info(r.Name + " - Properties not set");
                        }
                    }
                    catch (Exception ex)
                    { Log.Error("Error creating connection to receiver.  Command can not be sent", ex); }
                }
            }
            catch (Exception e)
            { Log.Error("Error sending command", e); }
        }
예제 #2
0
        public void SendCommand_Network(Receiver r, String command)
        {
            try
            {
                int length = command.Length;
                length++;
                int total = length + 16;
                char code = (char)length;

                // build up packet header and rest of command - followed by <CR> (chr(13))
                //
                string line = "ISCP\x00\x00\x00\x10\x00\x00\x00" + code + "\x01\x00\x00\x00" + command + "\x0D";

                if (r.tcpClient.Connected)
                {
                    // send command to receiver
                    //
                    r.clientStreamWriter.WriteLine(line);
                    r.clientStreamWriter.Flush();
                    this.Log.Info("Sent command: " + line);
                }
                else
                {
                    try
                    {
                        if (r.Type == "Network" && r.IP != "" && r.NetworkPort != 0)
                        {
                            this.Log.Debug("Creating TCP Client: ip-" + r.IP + " port-" + r.NetworkPort);
                            r.tcpClient = new TcpClient(r.IP, r.NetworkPort);

                            //get a network stream from server
                            r.clientSockStream = r.tcpClient.GetStream();

                            // create new writer and reader stream to send and receive
                            r.clientStreamWriter = new StreamWriter(r.clientSockStream);
                            r.clientStreamReader = new StreamReader(r.clientSockStream);

                            //Start listening
                            r.Connect();

                            // send command to receiver
                            //
                            r.clientStreamWriter.WriteLine(line);
                            r.clientStreamWriter.Flush();
                            this.Log.Info("Sent command: " + line);
                        }
                        else
                        {
                            this.Log.Info(r.Name + " - Properties not set");
                        }
                    }
                    catch (Exception ex)
                    {
                        this.Log.Error("Error creating connection to receiver.  Command can not be sent", ex);
                    }
                }
            }
            catch (Exception e)
            {
                this.Log.Error("Error sending command", e);
            }
        }
예제 #3
0
        public override void RunInterface(string pluginName)
        {
            this.Log.Debug("Running interface");
            pName = pluginName;
            OSAEObjectTypeManager.ObjectTypeUpdate("ONKYO RECEIVER", "ONKYO RECEIVER", "Onkyo Receiver", pluginName, "ONKYO RECEIVER", 0, 0, 0, 1);

            _UDPListen = new UDPListen();
            _UDPSend = new UDPSend();
            _UDPListen.OnkyoDevice += new DelegateOnkyoReply(OnkyoMessageHandler);

            _UDPListen.Listen();
            _UDPSend.Send();

            OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("ONKYO RECEIVER");

            foreach (OSAEObject obj in objects)
            {
                Receiver r = new Receiver(obj.Name);
                foreach (OSAEObjectProperty prop in obj.Properties)
                {
                    switch (prop.Name)
                    {
                        case "Communication Type":
                            r.Type = prop.Value;
                            break;
                        case "IP":
                            r.IP = prop.Value;
                            break;
                        case "Network Port":
                            try
                            {
                                r.NetworkPort = Int32.Parse(prop.Value);
                            }
                            catch
                            {
                                r.NetworkPort = 0;
                            }
                            break;
                        case "COM Port":
                            try
                            {
                                r.ComPort = Int32.Parse(prop.Value);
                            }
                            catch
                            {
                                r.ComPort = 0;
                            }
                            break;
                    }
                }

                receivers.Add(r);
                this.Log.Debug("Added receiver to list: " + r.Name);

                try
                {
                    if (r.Type == "Network" && r.IP != "" && r.NetworkPort != 0)
                    {
                        this.Log.Debug("Creating TCP Client: ip-" + r.IP + " port-" + r.NetworkPort);
                        r.tcpClient = new TcpClient(r.IP, r.NetworkPort);

                        //get a network stream from server
                        r.clientSockStream = r.tcpClient.GetStream();

                        // create new writer and reader stream to send and receive
                        r.clientStreamWriter = new StreamWriter(r.clientSockStream);
                        r.clientStreamReader = new StreamReader(r.clientSockStream);

                        //Start listening
                        r.Connect();
                    }
                    else if (r.Type == "Serial" && r.ComPort != 0)
                    {
                        //not implemented
                    }
                    else
                    {
                        this.Log.Info(r.Name + " - Properties not set");
                    }
                }
                catch (Exception ex)
                {
                    this.Log.Error("Error creating connection to receiver", ex);
                }
            }
            this.Log.Info("Run Interface Complete");
        }
예제 #4
0
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);
            Log.Debug("Running interface");

            OSAEObjectType objt = OSAEObjectTypeManager.ObjectTypeLoad("ONKYO RECEIVER");

            OSAEObjectTypeManager.ObjectTypeUpdate(objt.Name, objt.Name, objt.Description, pName, "THING", objt.Owner, objt.SysType, objt.Container, objt.HideRedundant);

            _UDPListen              = new UDPListen();
            _UDPSend                = new UDPSend();
            _UDPListen.OnkyoDevice += new DelegateOnkyoReply(OnkyoMessageHandler);

            _UDPListen.Listen();
            _UDPSend.Send();

            OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("ONKYO RECEIVER");

            foreach (OSAEObject obj in objects)
            {
                Receiver r = new Receiver(obj.Name);
                foreach (OSAEObjectProperty prop in obj.Properties)
                {
                    switch (prop.Name)
                    {
                    case "Communication Type":
                        r.Type = prop.Value;
                        break;

                    case "IP":
                        r.IP = prop.Value;
                        break;

                    case "Network Port":
                        try
                        { r.NetworkPort = Int32.Parse(prop.Value); }
                        catch
                        { r.NetworkPort = 0; }
                        break;

                    case "COM Port":
                        try
                        { r.ComPort = Int32.Parse(prop.Value); }
                        catch
                        { r.ComPort = 0; }
                        break;
                    }
                }

                receivers.Add(r);
                Log.Debug("Added receiver to list: " + r.Name);

                try
                {
                    if (r.Type == "Network" && r.IP != "" && r.NetworkPort != 0)
                    {
                        Log.Debug("Creating TCP Client: ip-" + r.IP + " port-" + r.NetworkPort);
                        r.tcpClient = new TcpClient(r.IP, r.NetworkPort);

                        //get a network stream from server
                        r.clientSockStream = r.tcpClient.GetStream();

                        // create new writer and reader stream to send and receive
                        r.clientStreamWriter = new StreamWriter(r.clientSockStream);
                        r.clientStreamReader = new StreamReader(r.clientSockStream);

                        //Start listening
                        r.Connect();
                    }
                    else if (r.Type == "Serial" && r.ComPort != 0)
                    { //not implemented
                    }
                    else
                    {
                        Log.Info(r.Name + " - Properties not set");
                    }
                }
                catch (Exception ex)
                { Log.Error("Error creating connection to receiver", ex); }
            }
            Log.Info("Run Interface Complete");
        }
예제 #5
0
        public void RunInterface(string pluginName)
        {
            osae.AddToLog("Running interface", false);
            pName = pluginName;
            osae.ObjectTypeUpdate("ONKYO RECEIVER", "ONKYO RECEIVER", "Onkyo Receiver", pluginName, "ONKYO RECEIVER", 0, 0, 0, 1);

            _UDPListen              = new UDPListen();
            _UDPSend                = new UDPSend();
            _UDPListen.OnkyoDevice += new DelegateOnkyoReply(OnkyoMessageHandler);

            _UDPListen.Listen();
            _UDPSend.Send();

            List <OSAEObject> objects = osae.GetObjectsByType("ONKYO RECEIVER");

            foreach (OSAEObject obj in objects)
            {
                Receiver r = new Receiver(obj.Name);
                foreach (ObjectProperty prop in obj.Properties)
                {
                    switch (prop.Name)
                    {
                    case "Communication Type":
                        r.Type = prop.Value;
                        break;

                    case "IP":
                        r.IP = prop.Value;
                        break;

                    case "Network Port":
                        try
                        {
                            r.NetworkPort = Int32.Parse(prop.Value);
                        }
                        catch
                        {
                            r.NetworkPort = 0;
                        }
                        break;

                    case "COM Port":
                        try
                        {
                            r.ComPort = Int32.Parse(prop.Value);
                        }
                        catch
                        {
                            r.ComPort = 0;
                        }
                        break;
                    }
                }

                receivers.Add(r);
                osae.AddToLog("Added receiver to list: " + r.Name, false);

                try
                {
                    if (r.Type == "Network" && r.IP != "" && r.NetworkPort != 0)
                    {
                        osae.AddToLog("Creating TCP Client: ip-" + r.IP + " port-" + r.NetworkPort, false);
                        r.tcpClient = new TcpClient(r.IP, r.NetworkPort);

                        //get a network stream from server
                        r.clientSockStream = r.tcpClient.GetStream();

                        // create new writer and reader stream to send and receive
                        r.clientStreamWriter = new StreamWriter(r.clientSockStream);
                        r.clientStreamReader = new StreamReader(r.clientSockStream);

                        //Start listening
                        r.Connect();
                    }
                    else if (r.Type == "Serial" && r.ComPort != 0)
                    {
                        //not implemented
                    }
                    else
                    {
                        osae.AddToLog(r.Name + " - Properties not set", true);
                    }
                }
                catch (Exception ex)
                {
                    osae.AddToLog("Error creating connection to receiver: " + ex.Message, true);
                }
            }
            osae.AddToLog("Run Interface Complete", false);
        }