Пример #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();
                    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);
            }
        }
Пример #2
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");
        }