I just want to simply read and write value to an object and I use Client example for that by passing the required values arguments through an api request . But the write operation returns an error.
Also I will I pass my desired value to be written on to write function , i think doesn't use a value argument . Could you help me to figure this out?
//After Association view
self.getReadOut()
self.getProfileGenerics()
data = GXDLMSData("0.2.0.0.0.255")
print(self.read(data,2))
self.write(data,2)
except (KeyboardInterrupt, SystemExit):
#Don't send anything if user is closing the app.
self.media = None
raise
finally:
self.close()
Out:
100 #value as requested
DisconnectRequest
Access Error : Device reports Read-Write denied.
Ended. Press any key to continue.
Hi,
Thank you so much for your fast help. I am new to this environment . When I try to run write function with mentioned given
data = GXDLMSData("0.2.0.0.0.255")
data.value= GXInt16(200)
reader.write(data,2)
return an error in write function client.py line no937 mentioning that invalid parameter and value type must give
if value is not None and type_ == DataType.NONE:
raise Exception("Invalid parameter. In python value type must give.")
error:
Traceback (most recent call last):
File "main.py", line 124, in main
print(reader.write(data,2))
File "/media/sf_shared/Gurux.DLMS.Python-master/Gurux.DLMS.Client.Example.python/GXDLMSReader.py", line 365, in write
data = self.client.write(item, int(attributeIndex))
File "/home/ajuzz/venv_aj/lib/python3.8/site-packages/gurux_dlms/GXDLMSClient.py", line 927, in write
return self.__write(item.name, value, type_, item.objectType, index)
File "/home/ajuzz/venv_aj/lib/python3.8/site-packages/gurux_dlms/GXDLMSClient.py", line 938, in __write
raise Exception("Invalid parameter. In python value type must give.")
Exception: Invalid parameter. In python value type must give.
Ended. Press any key to continue.
I'm sorry. I didn't remember this. There is a legacy reason for this. I hope it can be removed at some point. You need to set the data type like this at the moment:
data = GXDLMSData("0.2.0.0.0.255")
item.setDataType(index, DataType.UINT32)
data.value= GXInt16(200)
reader.write(data,2)
The data is write using UINT32, because datatype overrides the GXInt16.
The data can be directly int like this:
data.value= 200;
The device reports an unmatched type means that you try to write value where types don't match. Read the value from the meter and check the data type. You need to use the same data type when you write a value for the meter.
I have already solved my mistake and I have already managed to learn to write with your program.
Now I need to write an octet string and I don't know how I should pass it to my computer, I am using GXbytebuffer and I have generated a buffer with my code, would it be passed in the same way? putting data.value = buffer that I just created with my code.
Hi,
Hi,
I believe that you have connected without authentication and you don't have the access right to write the object. You need to check that first.
BR,
Mikko
Hi,
Hi,
I also have another doubt. If I want to write or set value 200 into my object item how will i pass that value into our write function?
def write(self, item, attributeIndex):
data = self.client.write(item, attributeIndex)
self.readDLMSPacket(data)
Hi,
Hi,
You can do it like this:
data = GXDLMSData("0.2.0.0.0.255")
#Change GXInt16 to data type what you want to write.
data.value = GXInt16(200)
write(data, 2)
BR,
Mikko
Hi,
Hi,
Thank you so much for your fast help. I am new to this environment . When I try to run write function with mentioned given
data = GXDLMSData("0.2.0.0.0.255")
data.value= GXInt16(200)
reader.write(data,2)
return an error in write function client.py line no937 mentioning that invalid parameter and value type must give
if value is not None and type_ == DataType.NONE:
raise Exception("Invalid parameter. In python value type must give.")
error:
Traceback (most recent call last):
File "main.py", line 124, in main
print(reader.write(data,2))
File "/media/sf_shared/Gurux.DLMS.Python-master/Gurux.DLMS.Client.Example.python/GXDLMSReader.py", line 365, in write
data = self.client.write(item, int(attributeIndex))
File "/home/ajuzz/venv_aj/lib/python3.8/site-packages/gurux_dlms/GXDLMSClient.py", line 927, in write
return self.__write(item.name, value, type_, item.objectType, index)
File "/home/ajuzz/venv_aj/lib/python3.8/site-packages/gurux_dlms/GXDLMSClient.py", line 938, in __write
raise Exception("Invalid parameter. In python value type must give.")
Exception: Invalid parameter. In python value type must give.
Ended. Press any key to continue.
Hi,
Hi,
I'm sorry. I didn't remember this. There is a legacy reason for this. I hope it can be removed at some point. You need to set the data type like this at the moment:
data = GXDLMSData("0.2.0.0.0.255")
item.setDataType(index, DataType.UINT32)
data.value= GXInt16(200)
reader.write(data,2)
BR,
Mikko
Hi
Hi
Yeah. It works fine ,was issue with datatype was not set.
Thanks
Ajith
Hi I need help with this…
Hi
I need help with this code, i dont understand this:
data = GXDLMSData("0.2.0.0.0.255")
item.setDataType(index, DataType.UINT32)
data.value= GXInt16(200)
reader.write(data,2)
you want write 200 in your device, and the type es int16, why you set data type first to UINT32?
I want write a UINT8 data and the device return: gurux_dlms.GXDLMSException.GXDLMSException: Access Error : Device reports a unmatched type.
thanks
Hi Aritza, The data is write…
Hi Aritza,
The data is write using UINT32, because datatype overrides the GXInt16.
The data can be directly int like this:
data.value= 200;
The device reports an unmatched type means that you try to write value where types don't match. Read the value from the meter and check the data type. You need to use the same data type when you write a value for the meter.
BR,
Mikko
thanks for your answer. I…
thanks for your answer.
I have already solved my mistake and I have already managed to learn to write with your program.
Now I need to write an octet string and I don't know how I should pass it to my computer, I am using GXbytebuffer and I have generated a buffer with my code, would it be passed in the same way? putting data.value = buffer that I just created with my code.
Sorry for the inconvenience. Thank you
Hi, You can write the value…
Hi,
You can write the value by returning bytebuffers value as byte array. Like this:
GXByteBuffer bb = new GXByteBuffer();
// Set bb value....
GXDLMSData d = new GXDLMSData();
d.Value = bb.ToArray();
//Write value for the meter.
BR,
Mikko