Coder Social home page Coder Social logo

Priority Array about bacpypes HOT 2 CLOSED

kheldaroz402 avatar kheldaroz402 commented on July 17, 2024
Priority Array

from bacpypes.

Comments (2)

JoelBender avatar JoelBender commented on July 17, 2024

You are expecting [None] to be "cast" as [PriorityValue(None)] but that isn't provided, PriorityValue is a Choice with no element selected and there needs to be at least one. If you specified [PriorityValue()] * 16 you would eventually be tripped up because it would be the same item repeated 16 times, and the same for [PriorityValue(null=())] * 16.

The definition of PriorityArray includes a "prototype" value that sets the null option and this is copied for each item of the array when an instance is created so to create a new empty array, just call PriorityArray().

from bacpypes.

kheldaroz402 avatar kheldaroz402 commented on July 17, 2024

thanks - that got that sorted

`def create_analog_output(row):
try:
ArrayOfPropertyIdentifier = ArrayOf(PropertyIdentifier)
property_list = ArrayOfPropertyIdentifier([
'presentValue', 'statusFlags', 'eventState', 'outOfService', 'units',
'minPresValue', 'maxPresValue', 'resolution', 'covIncrement', 'description',
'highLimit', 'lowLimit', 'limitEnable'
])

    analog_output = AnalogOutputObject(
        objectName=row['Object_Name'],
        objectIdentifier=(AnalogOutputObject.objectType, row['Object_Identifier']),
        presentValue=row['Present_Value'],
        statusFlags=calculate_status_flags(row),
        eventState=row.get('Event_State', 0),  # Assuming default value is 0
        outOfService=bool(row['Out_Of_Service']),  # Convert to bool
        units=row['BACnet_Engineering_Units'],
        minPresValue=row['Min_Pres_Value'],
        maxPresValue=row['Max_Pres_Value'],
        resolution=row.get('Resolution', None),
        covIncrement=row.get('COV_Increment', 1),
        description=row['Description'],
        highLimit=row.get('High_Limit', None),
        lowLimit=row.get('Low_Limit', None),
        limitEnable=row.get('Limit_Enable', [False, False]),
        propertyList=property_list,
    )

    # Initialize the priority array with default values
    priority_array = PriorityArray()

    # Set the Present_Value at the specified priority position if within range
    if 'Priority' in row and 1 <= row['Priority'] <= 16:
        priority_index = row['Priority']   # Don't need to Adjust for 0-based index
        priority_array[priority_index] = PriorityValue(real=Real(row['Present_Value']))

    # Assign the priority array to the object
    analog_output.priorityArray = priority_array

    # Print out the priority array
    logging.info(f"Priority Array Contents: Current Priority is {row['Priority']} with a value of {row['Present_Value']}")
    # for i, priority_value in enumerate(priority_array):
    #     # Log the actual value contained in the PriorityValue object
    #     if priority_value:
    #         logging.info(f"Priority {i+1}: {priority_value.real}")
    #     else:
    #         logging.info(f"Priority {i+1}: None")

    logging.debug(f"Created AnalogOutputObject: {analog_output}")

    return analog_output

except Exception as e:
    logging.error(f"{color.RED}An error occurred in create_analog_output: {e}{color.END}")
    return None`

from bacpypes.

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.