Skip to main content

2.4 GVS

2.4.1 Definition and characteristics

  • Definition:
    • Global variables are variables defined outside a function or subroutine and visible to the entire PLC program. In Baosky IDE, global variables are usually defined in the global variable table
  • Features:
    • Wide scope: Global variables can be accessed and modified anywhere in the PLC program, as long as the program has defined the variable
    • Sharability: Global variables allow data to be shared between different program organization units (PUs, such as function blocks FB, function FC, etc.)
    • Requires prudent handling: Due to the wide scope of global variables, improper use may lead to confusing program logic, making it difficult to maintain and debug

2.4.2 Application scenarios

  • Cross-PU data sharing: When data needs to be shared between multiple PUs, global variables can be used to achieve this
  • Status Monitoring: Global variables can be used to monitor the status of the PLC system, such as equipment operating status, fault information, etc.
  • Parameter Configuration: Global variables can also be used to store system configuration parameters, such as working mode, operating parameters, etc.
warning
  • Avoid Abuse: Although global variables provide the ability to share data across PUs, excessive use of global variables may lead to complex program structures that are difficult to understand and maintain. Therefore, the use of local variables or other data sharing mechanisms should be given priority where possible
  • Naming Conflict: When defining global variables, user need to pay attention to avoid naming conflicts with local variables or other global variables. If a naming conflict occurs, the PLC compiler may report an error or cause the program to behave abnormally
  • Initialization and Protection: For important global variables, ensure correct initialization when the program starts. In addition, measures need to be taken to protect global variables from accidental modification or destruction