@@ -201,6 +201,12 @@ def __init__(self, api: cdll, running_as_python_plugin: bool = False):
201
201
self .api .currentEnvironmentNum .restype = c_int
202
202
self .api .warmupFlag .argtypes = [c_void_p ]
203
203
self .api .warmupFlag .restype = c_int
204
+ self .api .getEMSGlobalVariableHandle .argtypes = [c_void_p , c_char_p ]
205
+ self .api .getEMSGlobalVariableHandle .restype = c_int
206
+ self .api .getEMSGlobalVariableValue .argtypes = [c_void_p , c_int ]
207
+ self .api .getEMSGlobalVariableValue .restype = RealEP
208
+ self .api .setEMSGlobalVariableValue .argtypes = [c_void_p , c_int , RealEP ]
209
+ self .api .setEMSGlobalVariableValue .restype = c_void_p
204
210
self .api .getPluginGlobalVariableHandle .argtypes = [c_void_p , c_char_p ]
205
211
self .api .getPluginGlobalVariableHandle .restype = c_int
206
212
self .api .getPluginGlobalVariableValue .argtypes = [c_void_p , c_int ]
@@ -698,6 +704,82 @@ def get_construction_handle(self, state: c_void_p, var_name: Union[str, bytes])
698
704
"'{}'" .format (var_name ))
699
705
return self .api .getConstructionHandle (state , var_name )
700
706
707
+ def get_ems_global_handle (self , state : c_void_p , var_name : Union [str , bytes ]) -> int :
708
+ """
709
+ Get a handle to an EMS global variable in a running simulation.
710
+
711
+ EMS global variables are used as a way to share data between running EMS programs. First a global variable must
712
+ be declared in the input file using the EnergyManagementSystem:GlobalVariable object. Once a name has been
713
+ declared, it can be accessed by EMS programs by name, and through the Python API. For API usage, the client
714
+ should get a handle to the variable using this get_global_handle function, then
715
+ using the get_ems_global_value and set_ems_global_value functions as needed. Note all global variables are
716
+ floating point values.
717
+
718
+ The arguments passed into this function do not need to be a particular case, as the EnergyPlus API
719
+ automatically converts values to upper-case when finding matches to internal variables in the simulation.
720
+
721
+ Note also that the arguments passed in here can be either strings or bytes, as this wrapper handles conversion
722
+ as needed.
723
+
724
+ :param state: An active EnergyPlus "state" that is returned from a call to `api.state_manager.new_state()`.
725
+ :param var_name: The name of the EMS global variable to retrieve, this name must be listed in an IDF object:
726
+ `EnergyManagementSystem:GlobalVariable`
727
+ :return: An integer ID for this EMS global variable, or -1 if one could not be found.
728
+ """
729
+ if isinstance (var_name , str ):
730
+ var_name = var_name .encode ('utf-8' )
731
+ elif not isinstance (var_name , bytes ):
732
+ raise EnergyPlusException (
733
+ "`get_ems_global_handle` expects `component_type` as a `str` or UTF-8 encoded `bytes`, not "
734
+ "'{}'" .format (var_name ))
735
+ return self .api .getEMSGlobalVariableHandle (state , var_name )
736
+
737
+ def get_ems_global_value (self , state : c_void_p , handle : int ) -> float :
738
+ """
739
+ Get the current value of an EMS global variable in a running simulation.
740
+
741
+ EMS global variables are used as a way to share data between running EMS programs. First a global variable must
742
+ be declared in the input file using the EnergyManagementSystem:GlobalVariable object. Once a name has been
743
+ declared, it can be accessed by EMS programs by name, and through the Python API. For API usage, the client
744
+ should get a handle to the variable using this get_global_handle function, then
745
+ using the get_ems_global_value and set_ems_global_value functions as needed. Note all global variables are
746
+ floating point values.
747
+
748
+ :param state: An active EnergyPlus "state" that is returned from a call to `api.state_manager.new_state()`.
749
+ :param handle: An integer returned from the `get_ems_global_handle` function.
750
+ :return: Floating point representation of the EMS global variable value
751
+ """
752
+ if not is_number (handle ):
753
+ raise EnergyPlusException (
754
+ "`get_ems_global_value` expects `handle` as an `int`, not "
755
+ "'{}'" .format (handle ))
756
+ return self .api .getEMSGlobalVariableValue (state , handle )
757
+
758
+ def set_ems_global_value (self , state : c_void_p , handle : int , value : float ) -> None :
759
+ """
760
+ Set the current value of an EMS global variable in a running simulation.
761
+
762
+ EMS global variables are used as a way to share data between running EMS programs. First a global variable must
763
+ be declared in the input file using the EnergyManagementSystem:GlobalVariable object. Once a name has been
764
+ declared, it can be accessed by EMS programs by name, and through the Python API. For API usage, the client
765
+ should get a handle to the variable using this get_global_handle function, then
766
+ using the get_ems_global_value and set_ems_global_value functions as needed. Note all global variables are
767
+ floating point values.
768
+
769
+ :param state: An active EnergyPlus "state" that is returned from a call to `api.state_manager.new_state()`.
770
+ :param handle: An integer returned from the `get_ems_global_handle` function.
771
+ :param value: Floating point value to assign to the EMS global variable
772
+ """
773
+ if not is_number (handle ):
774
+ raise EnergyPlusException (
775
+ "`set_ems_global_value` expects `variable_handle` as an `int`, not "
776
+ "'{}'" .format (handle ))
777
+ if not is_number (value ):
778
+ raise EnergyPlusException (
779
+ "`set_ems_global_value` expects `value` as a `float`, not "
780
+ "'{}'" .format (value ))
781
+ self .api .setEMSGlobalVariableValue (state , handle , value )
782
+
701
783
def get_global_handle (self , state : c_void_p , var_name : Union [str , bytes ]) -> int :
702
784
"""
703
785
Get a handle to a global variable in a running simulation. This is only used for Python Plugin applications!
@@ -740,12 +822,6 @@ def get_global_value(self, state: c_void_p, handle: int) -> float:
740
822
using this get_global_value and the set_global_value functions as needed. Note all global variables are
741
823
floating point values.
742
824
743
- The arguments passed into this function do not need to be a particular case, as the EnergyPlus API
744
- automatically converts values to upper-case when finding matches to internal variables in the simulation.
745
-
746
- Note also that the arguments passed in here can be either strings or bytes, as this wrapper handles conversion
747
- as needed.
748
-
749
825
:param state: An active EnergyPlus "state" that is returned from a call to `api.state_manager.new_state()`.
750
826
:param handle: An integer returned from the `get_global_handle` function.
751
827
:return: Floating point representation of the global variable value
0 commit comments