コード例 #1
0
        public PointResponse SetPointState(int blockId, int pointId, bool state, uint duration = 0)
        {
            // This method is better because it doesn't need NHibernate

            // Compose Action object
            PointAction action = new PointAction(pointId, state);

            // SetPointState messages do not have a return value because we do not wait for any data back from Wago like we do in GetBlockState.

            // Get RequestQueue, and push data into queue
            IRequestQueue queue = QueueCollection.Current.Item(blockId);

            if (queue == null)
            {
                throw new InvalidOperationException($"Could not find queue with BlockID {blockId}");
            }

            // Send request for block state
            queue.Push(action);

            // Wait a bit for the the response to appear
            PointResponse result = (PointResponse)queue.GetResponse(action.MessageID);

            // When duration is zero only send one message otherwise send the first message and then send another using a Timer.
            if (!result.Error && duration > 0)
            {
                PointAction futureAction = new PointAction(pointId, !action.State);
                HandleFutureAction(queue, action, futureAction, duration);
            }

            return(result);
        }
コード例 #2
0
        public BlockResponse GetBlockState(int blockId)
        {
            // Compose Action object
            BlockAction action = new BlockAction(blockId);

            // Get RequestQueue, and push data into queue
            IRequestQueue queue = QueueCollection.Current.Item(blockId);

            if (queue == null)
            {
                throw new InvalidOperationException($"Could not find queue with BlockID {blockId}");
            }

            // Send request for block state
            queue.Push(action);

            // Wait a bit for the the response to appear
            BlockResponse result = (BlockResponse)queue.GetResponse(action.MessageID);

            return(result);
        }