예제 #1
0
        public virtual BlockResponse SendGetBlockStateCommand(int blockId)
        {
            Block block = DA.Current.Single <Block>(blockId);

            if (block == null)
            {
                throw new InvalidOperationException($"Block not found with BlockID = {blockId}");
            }

            using (var sender = Connect(block))
            {
                byte[] buffer = CreateGetBlockStateBuffer();

                Log.Write(block.BlockID, $"WagoConnection: Sending GetBlockState message to block: BlockID = {block.BlockID}, Data = {WagoUtility.GetDataString(buffer)}");

                byte[] recvBuffer = new byte[65];

                int bytesRecv = SendMessageToBlock(sender, buffer, recvBuffer, true);

                if (bytesRecv > 0)
                {
                    Log.Write(block.BlockID, $"WagoConnection: Received {bytesRecv} bytes [{WagoUtility.BytesToString(recvBuffer, bytesRecv)}] from block {block.BlockID}");
                }
                else
                {
                    Log.Write(block.BlockID, $"WagoConnection: Block {block.BlockID} did not return any data");
                }

                BlockResponse result = block.CreateBlockResponse();
                result.BlockState.Points = block.Points.Select(x => WagoUtility.GetPointState(x, recvBuffer)).ToArray();

                return(result);
            }
        }
예제 #2
0
        protected virtual byte[] CreateSetPointStateBuffer(Point point, bool state)
        {
            // When setting point state filterDirection must be true!!
            WagoAddress addr = WagoUtility.MapToMemory(point, filterDirection: true);

            byte[] result = addr.GetBuffer(state);
            return(result);
        }
예제 #3
0
        public PointResponse SendSetPointStateCommand(int pointId, bool state)
        {
            Point point = DA.Current.Single <Point>(pointId);

            if (point == null)
            {
                throw new InvalidOperationException($"Point not found with PointID = {pointId}");
            }

            using (var sender = Connect(point.Block))
            {
                byte[] buffer = CreateSetPointStateBuffer(point, state);

                Log.Write(point.Block.BlockID, $"WagoConnection: Sending SetPointState message to block: BlockID = {point.Block.BlockID}, PointID = {point.PointID}, Data = {WagoUtility.GetDataString(buffer)}");

                byte[] recvBuffer = new byte[65];

                int bytesRecv = SendMessageToBlock(sender, buffer, recvBuffer, false);

                // the recvBuffer is not used for SetPointState because there is no response

                PointResponse result = point.CreatePointResponse();

                return(result);
            }
        }