Giter Club home page Giter Club logo

Comments (7)

nauful avatar nauful commented on July 28, 2024

Hello,

Nodes on the server are not writable by default. If you want to write to a node, you must handle storing that value for later reads.

Implement this virtual method in your Application:
https://github.com/nauful/LibUA/blob/837d0072a338e690d1c30ec32649499ae12ee10c/NET%20Core/LibUA/Application.cs#L474C4-L474C88
The default implementation returns BadNotWritable for write attempts. If your node is writable, you can store the new value (to return on reads, possibly also store in a historical time series) and return Good for that node. If your node isn't writable, you can return BadNotWritable.

WriteValue is determined here:

public class WriteValue

This includes NodeId and Value.

from libua.

nauful avatar nauful commented on July 28, 2024

To return the written value when a node is read, look at this:

protected override DataValue HandleReadRequestInternal(NodeId id)

And this is to handle historical reads:

public override UInt32 HandleHistoryReadRequest(object session, object readDetails, HistoryReadValueId id,

from libua.

petruh1n avatar petruh1n commented on July 28, 2024

I return Good in the HandleWriteRequest method, the error no longer appears, but the value is still not displayed.
I didn't quite understand what it means to store the new value.
Could you share some example, please?

from libua.

petruh1n avatar petruh1n commented on July 28, 2024

I managed to write down the value in this way. Is this the right decision?
093034

from libua.

nauful avatar nauful commented on July 28, 2024

Look at this sample code:

			private Dictionary<NodeId, DataValue> writtenValues = new Dictionary<NodeId, DataValue>();

			public override uint[] HandleWriteRequest(object session, WriteValue[] writeValues)
			{
				var respStatus = new UInt32[writeValues.Length];
				for (int i = 0; i < writeValues.Length; i++)
				{
					if (writeValues[i].AttributeId == NodeAttribute.Value)
					{
						writtenValues[writeValues[i].NodeId] = writeValues[i].Value;
						MonitorNotifyDataChange(writeValues[i].NodeId, writeValues[i].Value);
						respStatus[i] = (UInt32)StatusCode.Good;
					}
					else
					{
						respStatus[i] = (UInt32)StatusCode.BadNodeAttributesInvalid;
					}
				}

				return respStatus;
			}

			protected override DataValue HandleReadRequestInternal(NodeId id)
			{
				if (writtenValues.TryGetValue(id, out DataValue value))
				{
					return value;
				}

				Node node = null;
				if (id.NamespaceIndex == 2 &&
					AddressSpaceTable.TryGetValue(id, out node))
				{
					if (node == Node1D)
					{
						return new DataValue(new float[] { 1.0f, 2.0f, 3.0f }, StatusCode.Good, DateTime.Now);
					}
					else if (node == Node2D)
					{
						return new DataValue(new float[2, 2]
						{
							{ 1.0f, 2.0f },
							{ 3.0f, 4.0f }
						}, StatusCode.Good, DateTime.Now);
					}
					else
					{
						return new DataValue(3.14159265, StatusCode.Good, DateTime.Now);
					}
				}

				return base.HandleReadRequestInternal(id);
			}

You need to store the written value somewhere, publish data change, then return it on read.

from libua.

petruh1n avatar petruh1n commented on July 28, 2024

Thank you very much.
Why do I need to return a value in HandleReadRequestInternal?
Is my example incorrect?

from libua.

nauful avatar nauful commented on July 28, 2024

For read internal, you need to return the value of the node involved. This is the sent back to the client.

from libua.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.