Click or drag to resize

Calling classes defined in a SIMPL# library from a SIMPL+ module

All public classes and their public class members (variables, methods and properties) in your SIMPL# Library are "exposed" to the SIMPL+ module so you can create variables of this class type in your SIMPL+ module and then call and use the class’ functions and variables.

gradient

 

 

IMPORTANT: Make sure to provide a default public constructor for your class in the SIMPL# Library, otherwise the SIMPL+ module would not compile!

 

 

 

Example:

SIMPL#:

C#
	namespace SIMPLSharpLibrary1
	{
		public class Class1
		{
			int ID;

			public Class1()
			{
				//your class must have a public constructor
				//otherwise the SIMPL+ module would not compile
			}

			public int GetID()
			{
				return ID;
			}

		}
	}

 

 

To access a class defined in the SIMPL# library and call its methods and properties from a SIMPL+ module:

  1. Reference your SIMPL# library in the SIMPL+ module by using the SIMPL+ keyword #USER_SIMPLSHARP_LIBRARY:

    #USER_SIMPLSHARP_LIBRARY "SIMPLSharpLibrary1"

  2. Create an instance of the class defined in your SIMPL# Library by declaring a variable (myClass) of the same type as your SIMPL# class:

    Class1 myClass;

  3. Call the methods and properties of the class, by using the class variable name and the dot operator. For example, to call the method GetID() of Class1 from the SIMPL# example above use:

    SIGNED_LONG_INTEGER ID;

    ID = myClass.GetID();

    NOTE: Although SIMPL+ is itself case-insensitive, class, structures and variables ID names defined in SIMPL# are case-sensitive, so make sure to use their correct names when referencing them in your SIMPL+ module!

    For example:

    ID = myClass.GetID(); // correct

    ID = myClass.GETID(); //incorrect

 

SIMPL+:

C++
	function InitializeSimplSharpObjects()
	{
		// instantiate a variable of your SIMPL# class in the SIMPL+ module
		Class1 myClass;

		SIGNED_LONG_INTEGER ID;

		ID = myClass.GetID();
	}

 

 

Static Members and Classes

The fields, properties, and methods of a class can be either instance members or static members. Static members are associated with the class itself, and not with any particular instance. A static member is accessed through the name of the class in which it is declared.

Static members are declared by using the static keyword as shown below:

static public ushort currentTemperature = 0;

Since only one copy of static data is created in memory, static data is useful for sharing information/"memory sharing" across several SIMPL+ modules.

Example:

SIMPL#

C#
public class Class1
{

    static public ushort currentTemperature = 0;

    public Class1()
    {
        //empty public constructor
        //otherwise the SIMPL+ module would not compile
    }

}

 

 

SIMPL+:

C++
	#DEFAULT_VOLATILE
	#ENABLE_STACK_CHECKING
	#ENABLE_TRACE
	#ENCODING_ASCII
	#USER_SIMPLSHARP_LIBRARY "Static"

	DIGITAL_INPUT dSet, dGet;

	ANALOG_OUTPUT Value;

	PUSH dSet
	{

		Class1.currentTemperature = 20;

	}

	PUSH dGet
	{

		Value = Class1.currentTemperature;

	}

 

 

footer
Crestron Blue 400 x 100

Copyright (C) 2013 to the present, Crestron Electronics, Inc. All rights reserved. No part of this work may be reproduced in any form, machine or natural, without the express written consent of Crestron Electronics.