コード例 #1
0
        private void DispatchQueryRegisterMessage(ProtocolMessage protocolMessage)
        {
            QueryRegisterMessage response = new QueryRegisterMessage(protocolMessage);

            if (response.Value == null)
            {
                // Error reading occured!
                throw new ArgumentException("Error reading occured");
            }

            if (this.Nodes.All(x => x.Id != protocolMessage.ControllerID))
            {
                throw new ArgumentException("No node found for the msg");
            }
            CpuNode node = this.Nodes.First(x => x.Id == protocolMessage.ControllerID);

            MessageCodec.GetControlByteValues(node.ProtocolVersion, response.Control, out ReadWrite readWrite, out Source source, out int derefDepth);
            Register r = node.EmbeddedConfig.GetRegister(response.Offset, readWrite);

            if (r == null)
            {
                throw new ArgumentException("No register found with this offset or readwrite");
            }
            NewValueReceived(this, new ValueReceivedEventArgs(RegisterValue.GetRegisterValueByVariableType(r.VariableType, response.Value), r, node));
        }
コード例 #2
0
        public override void QueryValue(CpuNode cpuNode, Register register)
        {
            Version protocolVersion  = cpuNode.ProtocolVersion;
            byte    control          = MessageCodec.GetControlByte(protocolVersion, register.ReadWrite, register.Source, register.DerefDepth);
            QueryRegisterMessage msg = new QueryRegisterMessage()
            {
                Offset  = register.Offset,
                Control = control,
            };

            // TODO add the msgID
            this.SendMessage(MessageCodec.EncodeMessage(msg.ToProtocolMessage(cpuNode.Id, 0x01)));
        }