예제 #1
0
        /// <summary>
        /// Checks the and connect.
        /// </summary>
        /// <returns></returns>
        public XAMIOConnectionStatus CheckAndConnect()
        {
            if (dispatcher.CheckAndConnect() != XAMIOConnectionStatus.Connected)
            {
                _IdState = new XAMUmpStateFlags();
                return(XAMIOConnectionStatus.notConnected);
            }
            HandleTelegramReceived();
            if (IdState.InitRequest)
            {
                // Send Init Request
                SetIDControl();
                return(XAMIOConnectionStatus.notConnected);
            }

            if (IdState.TimeRequest)
            {
                Send(XAMUmpDateTime.Create(DateTime.Now, trace));
            }

            if (DateTime.Now.Subtract(IdState.LastStateReceived).Seconds > 10)
            {
                SendIDStateIDControlRequest();
            }

            return(XAMIOConnectionStatus.Connected);
        }
예제 #2
0
        public void IDStateIDControlRequestBlocking()
        {
            trace("Init request init for control and state!", TracePrio.MESSAGE);
            _IdControl   = -1;
            _IdState     = new XAMUmpStateFlags();
            waitPacketID = packageID;

            SendIDStateIDControlRequest();

            Stopwatch sw = new Stopwatch();

            sw.Start();
            while (_IdControl == -1 || IdState.NotInitialized)
            {
                HandleTelegramReceived();
                if (sw.ElapsedMilliseconds > 1000)
                {
                    throw new Exception("init 1 timeout!");
                }
            }
            sw.Stop();
        }
예제 #3
0
        /// <summary>
        /// Handles the telegram received.
        /// </summary>
        public void HandleTelegramReceived()
        {
            try
            {
                TelegramReceivedEventArgs <XAMUmpTelegram> e = null;
                do
                {
                    e = dispatcher.GetNextRcvTel(remoteAddressIdent);
                    if (e == null)
                    {
                        break;
                    }

                    // If there is no message in the telegrame --> it is an Ack!
                    if (AckReceived != null /*&& e.Telegram.Messages.Count == 0*/)
                    {
                        AckReceived();
                    }

                    foreach (var msg in e.Telegram.Messages)
                    {
                        try
                        {
                            switch (msg.MessageID)
                            {
                            case UmpMessageID.IdState:
                                _IdState = new XAMUmpStateFlags(msg.Value);
                                break;

                            case UmpMessageID.PageCount:
                                _PageCount = BitConverter.ToInt16(msg.Value, 0);
                                break;

                            case UmpMessageID.IdControl:
                                _IdControl = BitConverter.ToInt16(msg.Value, 0);
                                break;

                            case UmpMessageID.PageIndex:
                                _PageIndex = BitConverter.ToInt16(msg.Value, 0);
                                break;

                            case UmpMessageID.EditValue:
                            case UmpMessageID.I2C_Temperature:
                                if (ValueEvent == null)
                                {
                                    break;
                                }
                                ValueEvent(msg.MessageID, msg.ActorID, msg.Value);
                                break;

                            case UmpMessageID.VideoState:
                                if (msg.Value.Length < 12)
                                {
                                    trace("rcv VideoState: to less data", TracePrio.ERROR);
                                    break;
                                }
                                int cnt          = 0;
                                int StateFlags   = BitConverter.ToInt32(msg.Value, cnt); cnt += 4;
                                int BoundsLeft   = BitConverter.ToInt16(msg.Value, cnt); cnt += 2;
                                int BoundsTop    = BitConverter.ToInt16(msg.Value, cnt); cnt += 2;
                                int BoundsRight  = BitConverter.ToInt16(msg.Value, cnt); cnt += 2;
                                int BoundsBottom = BitConverter.ToInt16(msg.Value, cnt); cnt += 2;
                                trace("HandleTelegramReceived video state '" + StateFlags + "' left '" + BoundsLeft + "' top '" + BoundsTop + "' right '" + BoundsRight + "' bottom '" + BoundsBottom + "' ", TracePrio.MESSAGE);
                                if (VideoStateEvent != null)
                                {
                                    VideoStateEvent(StateFlags, BoundsLeft, BoundsTop, BoundsRight, BoundsBottom);
                                }

                                break;

                            default:
                            {
                                break;
                            }
                            }
                        }
                        catch (Exception ex)
                        {
                            trace("receive message exception: " + ex.Message, TracePrio.ERROR);
                        }
                    }
                } while (e != null);
            }
            catch (Exception ex1)
            {
                trace("receive exception: " + ex1.Message, TracePrio.ERROR);
            }
        }