User Tools

Site Tools


kb:bestpractices:codingconventions:architecture

01 Architecture

General

  • When working with clusters and SubVIs, pass only the data the SubVI needs. Do not let the SubVIs consume the entire cluster.
  • Do NOT use variant attributes for data storage unless their high performance is definitely needed.
    • Attributes hide away any information about the datatypes at edit time
  • Wrap VIs in classes (.lvclass) or libraries (.lvlib) for name spacing and generally improved encapsulation / cohesion / coupling

Reentrancy

  • If a technology supports multiple threads (more than one instance in memory at the same time), all the VIs of the corresponding driver usually need to be set to reentrant execution.

Functions/Primitives

  • Do not use “First Call?”, use an FGV instead
  • Use Compound Arithmetic instead of boolean logic gates
  • Do NOT use invert options on boolean functions and operators
    • use a separate not operator instead

Constants

  • For constants that are reused throughout the project, create a subVI that only contains a single constant on the block diagram and one indicator returning the constant value

Structures

Unwired Terminals

  • Use “Use Default If Unwired” appropriately
  • If no default value should ever be used, enable “Linked Input Tunnel”

Conditional Disable Structures

  • When using CD Structures, put them into the project tree:
    • as far up as possible (ie. direct at the project root level, as opposed to the targets)
    • as far down as necessary (eg to distinguish different FPGA targets)
  • For each CD Symbol in the project, add a log entry or similar to your project so you can identify at runtime which values were defined for the symbols
    • Put these into a subVI directly after starting the application
    • When using HSE libs, put this subVI directly after initialising the HSE-Logger

Communication

  • Transferring data from one loop to another loop (VI-local)
    • Using VI server (reference or property node) to update the value of a control or indicator is the least efficient mechanism by far.
    • Local variables come with only a slight overhead to directly writing to the terminal.
    • Global variable would be the fastest with the additional caveats of race conditions and issues when global variables are not handled correctly.
    • RT FIFO or a User Event add context and encapsulation.

Database

  • Wrap each query in a separate SubVI
    • this allows for easy reuse
    • add documentation to describe the returned values
    • optional: convert the returned 2d-array of strings into a 1d-array of typedef'ed cluster

Configuration

  • Simultaneous Creation: When creating access to a configuration file, the file and its related content must be created at the same time.
  • Focused SubVI Design: A configuration access SubVI should only contain related information. This minimizes dependencies and simplifies maintenance and testing.
  • Early Testing: Perform testing early to identify and resolve potential issues promptly, avoiding prolonged troubleshooting later.
  • Default Config Creation: Implement a VI that creates a configuration file in the correct format, even if the application does not have a “save config” requirement, ensuring consistency and avoiding potential issues.

Variables with Units

  • Units in Square Brackets: Append units in square brackets [ ] to the variable name.
    • Examples: distance[km], time[s], temperature[°C].
  • Standard Units: Use SI units where possible. Non-SI units must be consistent and documented.
    • Examples: force[N], speed[km/h].
  • No Unit: Use [-] if the variable is unitless.
    • Example: scalingFactor[-].
    • Special Note: If the variable represents a fraction (e.g., a ratio), where the value ranges from 0 to 1 without explicit scaling use [-]. If a variable represents a percantage use [%] instead.
  • No Redundancy: Do not repeat units in both the variable name and value.
    • Correct: distance[km] = 50
    • Incorrect: distance_km = 50 km.

Type Conversions

Array to Cluster

  • The Array to Cluster node has the number of elements hard-coded
  • As an array is dynamic, we need to check the size during runtime
  • To convert the generic cluster to a typedef-ed one, use the Coerce To Type function

kb/bestpractices/codingconventions/architecture.txt · Last modified: 2024/12/11 17:44 by matthias.mueller