Skip to content

String reading/writing

It is necessary to provide some additional information on the available operations. When the user requests a resource in the form of a string, the system returns the data in the form of JSON: this process does not create problems in the reading phase, while in the writing phase it forces the user to respect some courtships.

Take as an instance the reading of the example server present in the official gurux github repository (https://github.com/Gurux/gurux.dlms.java):

if the user requires the reading of the resource string 328 ("CLOCK") at the address 9, you get a string as a result (ie, "NONE"), because this object has only one field. Conversely, if the user requests the reading of the address 5, it is accessed to an object composed of several fields, which will be translated into a JSON:

{"status":["OK"],"meterCalendar":{"year":2022,"month":8,"dayOfMonth":1,"hourOfDay":0,"minute":0,"second":0},"skip":["DAY_OF_WEEK","SECOND","HOUR","YEAR","MILLISECOND","MINUTE"],"extra":[],"dayOfWeek":0}

From the point of view of the reading process, then, the two different data are obtained with the same procedure, because the translation is completely transparent to the user.

The same thing does not happen in the writing phase. This happens because the writing procedure consists of several phases:

  • reading the data from the server
  • modifying this data with the information provided by the user
  • sending the new data.

This sequence is not a problem if the object to be modified is composed of a single field, since the data is inserted in a JSON with single object, and only that one is modified and sent; conversely, if there are several objects in the JSON, the user is forced to write in the fillable box the whole JSON, modifying the values that you want to change, and sending it in its entirety.

Following the same example provided above, to change the resource to the address 9, just enter the new value in the fillable box, and this will be changed. In the case, however, of the resource at address 5, if the user wants to change, for example, only the field "year", it should still write in the box the entire JSON, but changing the value of the field "year", for example writing 2021 instead of 2022.