Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using write function #45

Closed
yuvalfro opened this issue Aug 12, 2021 · 2 comments
Closed

Using write function #45

yuvalfro opened this issue Aug 12, 2021 · 2 comments

Comments

@yuvalfro
Copy link

Hi,
I'm trying to use the "write" function in SunSpecModbusClientDeviceTCP.
I am having a tough time to understand what is the format of the 'data' parameter in the function.
From the comment in the function:
Parameters:

        addr :
            Starting Modbus address.

        count :
            Byte string containing register contents.

This is what I tried to do:

 d = client.SunSpecModbusClientDeviceTCP(slave_id=1, ipaddr=ip, ipport=port) 

 try:

    d.scan()
    
except Exception as e:

    print("Exception occured during Sunspec scan: ", e)
    
lst = [1,1]

byte_obj = bytes(lst)

d.write(d.DERCtlAC[0].model_addr+d.DERCtlAC[0].PFWInjEna.offset,byte_obj)

What is wrong in my code?
Thanks!

@GZPERRA
Copy link

GZPERRA commented Aug 26, 2021

First of all make sure that your model DERCtlAC (DER AC controls model, id=704) is available on your target device.
You can check that by printing the models dictionary print(d.models) and looking for two keys: 704 (model ID) and DERCtlAC (model name).

  • If you didn't find any of those keys, then your device doesn't have this model.

  • If you found the ID (704) but not the name, then you forgot to include the model definition file: model_704.json. Copy its content and put it here: sunspec2/models/json/model_704.json.

Now to change your value, it's recommended to do it this way (using the class Point):

# Enabling power factor when injecting active power.
d.DERCtlAC[0].PFWInjEna.value = 1 # The value has changed in the object
d.DERCtlAC[0].PFWInjEna.write() # The value has changed in the device

Hope it helps, although I'm late :/.

@shelcrow
Copy link
Collaborator

Please reopen if you still have an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants