Пример #1
0
        private void ReceiveData(IAsyncResult iar)
        {
            try
            {
                //Get the received message.
                Socket recvSock = (Socket)iar.AsyncState;
                EndPoint rEP = new IPEndPoint(IPAddress.Any, 0);
                int dataLen = recvSock.EndReceiveFrom(iar, ref rEP);

                // Copy data to a local buffer so we can start listening again asap
                byte[]  localData = new byte[dataLen];
                Array.Copy(_buffer, localData, dataLen);
                      
                //Start listening for a new message.
                IPEndPoint iEP = new IPEndPoint(IPAddress.Any, _port);
                EndPoint ep = iEP;
                _udpSocket.BeginReceiveFrom(_buffer, 0, _buffer.Length, SocketFlags.None, ref ep, ReceiveData, _udpSocket);
                
                // Handle the local data buffer now (after we restarted the listen server)
                string stringData = Encoding.UTF8.GetString(localData, 0, localData.Length);
                stringData = CleanString(stringData, true);
                
                // ------------------------------------------------------------------------------
                // Debug.WriteLine(stringData + "/" + ((System.Net.IPEndPoint)rEP).Address);
                // Result will look something like below: /192.168.1.36 IS TAGGED ON FROM REMOTEIP
                // ISCP&!1ECNTX-NR609/60128/XX/0009F013A3B6/192.168.1.36
                // ------------------------------------------------------------------------------

                                
                Device oDev = new Device();
                oDev.LoadDevice(stringData + "/" + ((System.Net.IPEndPoint)rEP).Address);

                //// Invoke Delegate Event here to return ct_Onkyo.Device object
                OnkyoDevice.Invoke(oDev);

                oDev = null;              
            }
            catch (SocketException ex)
            {
                Debug.WriteLine("Error: {0} {1}", ex.ErrorCode, ex.Message);
            }
        }
Пример #2
0
        private void OnkyoMessageHandler(Device oDevice)
        {
            try
            {
                if (OSAEObjectManager.GetObjectByName(oDevice.ModelName) == null)
                {
                    OSAEObjectManager.ObjectAdd(oDevice.ModelName, oDevice.ModelName, "ONKYO RECEIVER", "", "", true);
                    OSAEObjectPropertyManager.ObjectPropertySet(oDevice.ModelName, "IP", oDevice.IP, pName);
                    OSAEObjectPropertyManager.ObjectPropertySet(oDevice.ModelName, "Network Port", oDevice.Port.ToString(), pName);
                    OSAEObjectPropertyManager.ObjectPropertySet(oDevice.ModelName, "Communication Type", "Network", pName);

                }
                this.Log.Info(_ctr.ToString() + " - " + oDevice.Region + Environment.NewLine +
                        _ctr.ToString() + " - " + oDevice.ModelName + Environment.NewLine +
                            _ctr.ToString() + " - " + oDevice.Mac + Environment.NewLine +
                                _ctr.ToString() + " - " + oDevice.IP + Environment.NewLine +
                                    _ctr.ToString() + " - " + oDevice.Port + Environment.NewLine);
                    _ctr++;
            }
            catch (Exception ex)
            {

                this.Log.Error("Error receiver device info ", ex);
            }

        }
Пример #3
0
        private void OnkyoMessageHandler(Device oDevice)
        {
            try
            {
                if (osae.GetObjectByName(oDevice.ModelName) == null)
                {
                    osae.ObjectAdd(oDevice.ModelName, oDevice.ModelName, "ONKYO RECEIVER", "", "", true);
                    osae.ObjectPropertySet(oDevice.ModelName, "IP", oDevice.IP);
                    osae.ObjectPropertySet(oDevice.ModelName, "Network Port", oDevice.Port.ToString());
                    osae.ObjectPropertySet(oDevice.ModelName, "Communication Type", "Network");

                }
                 osae.AddToLog(_ctr.ToString() + " - " + oDevice.Region + Environment.NewLine +
                        _ctr.ToString() + " - " + oDevice.ModelName + Environment.NewLine +
                            _ctr.ToString() + " - " + oDevice.Mac + Environment.NewLine +
                                _ctr.ToString() + " - " + oDevice.IP + Environment.NewLine +
                                    _ctr.ToString() + " - " + oDevice.Port + Environment.NewLine, true);
                    _ctr++;
            }
            catch (Exception ex)
            {

                osae.AddToLog("Error receiver device info: " + ex.Message, true);
            }
        }