diff --git a/BACnetServerExample/BACnetServerExample/CASBACnetStackAdapter.cs b/BACnetServerExample/BACnetServerExample/CASBACnetStackAdapter.cs index 7ca64d5..24190ea 100644 --- a/BACnetServerExample/BACnetServerExample/CASBACnetStackAdapter.cs +++ b/BACnetServerExample/BACnetServerExample/CASBACnetStackAdapter.cs @@ -1210,9 +1210,6 @@ unsafe class CASBACnetStackAdapter [DllImport(BACNET_API_DLL_FILENAME, EntryPoint = "BACnetStack_AddNetworkPortObject", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] public static extern int AddNetworkPortObject(); - [DllImport(BACNET_API_DLL_FILENAME, EntryPoint = "BACnetStack_SetPropertySubscribable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] - public static extern int SetPropertySubscribable(); - [DllImport(BACNET_API_DLL_FILENAME, EntryPoint = "BACnetStack_SetObjectTypeCreatable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] public static extern int SetObjectTypeCreatable(); @@ -1239,6 +1236,13 @@ unsafe class CASBACnetStackAdapter public static extern int RegisterCallbackDeleteObject(); */ + [DllImport(BACNET_API_DLL_FILENAME, EntryPoint = "BACnetStack_SetPropertyByObjectTypeSubscribable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] + public static extern int SetPropertySubscribable(UInt32 deviceInstance, UInt16 objectType, UInt32 objectInstance, UInt32 propertyIdentifier, bool subscribable); + + [DllImport(BACNET_API_DLL_FILENAME, EntryPoint = "BACnetStack_SetPropertyByObjectTypeSubscribable", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] + public static extern int SetPropertyByObjectTypeSubscribable(UInt32 deviceInstance, UInt16 objectType, UInt32 propertyIdentifier, bool subscribable); + + [DllImport(BACNET_API_DLL_FILENAME, EntryPoint = "BACnetStack_SendReadPropertyAsync", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] public static extern bool BACnetStack_SendReadPropertyAsync(Byte* sentInvokeId, Byte* connectionString, Byte connectionStringLength, Byte networkType, UInt16 network, Byte* destinationAddress, Byte destinationAddressLength, Byte propertyArraysCount, Byte* propertyArrays); diff --git a/BACnetServerExample/BACnetServerExample/Program.cs b/BACnetServerExample/BACnetServerExample/Program.cs index 8cf0cd5..d20cf51 100644 --- a/BACnetServerExample/BACnetServerExample/Program.cs +++ b/BACnetServerExample/BACnetServerExample/Program.cs @@ -61,7 +61,7 @@ public void Run() // Get Datatype Callbacks CASBACnetStackAdapter.RegisterCallbackGetPropertyCharacterString(CallbackGetPropertyCharString); CASBACnetStackAdapter.RegisterCallbackGetPropertyReal(CallbackGetPropertyReal); - CASBACnetStackAdapter.RegisterCallbackGetPropertyEnumerated(CallbackGetEnumerated); + CASBACnetStackAdapter.RegisterCallbackGetPropertyEnumerated(CallbackGetEnumerated); CASBACnetStackAdapter.RegisterCallbackGetPropertyUnsignedInteger(CallbackGetUnsignedInteger); CASBACnetStackAdapter.RegisterCallbackGetPropertyBool(CallbackGetPropertyBool); CASBACnetStackAdapter.RegisterCallbackGetPropertyDate(CallbackGetPropertyDate); @@ -98,6 +98,8 @@ public void Run() CASBACnetStackAdapter.AddObject(database.Device.instance, CASBACnetStackAdapter.OBJECT_TYPE_ANALOG_INPUT, offset); } CASBACnetStackAdapter.SetPropertyByObjectTypeEnabled(database.Device.instance, CASBACnetStackAdapter.OBJECT_TYPE_ANALOG_INPUT, CASBACnetStackAdapter.PROPERTY_IDENTIFIER_DESCRIPTION, true); + CASBACnetStackAdapter.SetPropertyByObjectTypeSubscribable(database.Device.instance, CASBACnetStackAdapter.OBJECT_TYPE_ANALOG_INPUT, CASBACnetStackAdapter.PROPERTY_IDENTIFIER_PRESENT_VALUE, true); + // AnalogOutput for (UInt32 offset = 0; offset < this.database.AnalogOutput.Length; offset++) @@ -163,14 +165,14 @@ public void Run() CASBACnetStackAdapter.AddObject(database.Device.instance, CASBACnetStackAdapter.OBJECT_TYPE_TIME_VALUE, offset); } - - // Enable optional services CASBACnetStackAdapter.SetServiceEnabled(database.Device.instance, CASBACnetStackAdapter.SERVICE_READ_PROPERTY_MULTIPLE, true); CASBACnetStackAdapter.SetServiceEnabled(database.Device.instance, CASBACnetStackAdapter.SERVICE_WRITE_PROPERTY, true); CASBACnetStackAdapter.SetServiceEnabled(database.Device.instance, CASBACnetStackAdapter.SERVICE_WRITE_PROPERTY_MULTIPLE, true); CASBACnetStackAdapter.SetServiceEnabled(database.Device.instance, CASBACnetStackAdapter.SERVICE_SUBSCRIBE_COV, true); + + // All done with the BACnet setup. Console.WriteLine("FYI: CAS BACnet Stack Setup, successfuly"); @@ -183,8 +185,9 @@ public void Run() for (; ; ) { CASBACnetStackAdapter.Loop(); - database.Loop(); - DoUserInput(); + + database.Loop(); // Just for this example + DoUserInput(); // Just for this example } } @@ -207,6 +210,10 @@ private void DoUserInput() { this.database.AnalogInput[0].presentValue += 0.01f; Console.WriteLine("FYI: Incurment Analog input {0} present value to {1:0.00}", 0, this.database.AnalogInput[0].presentValue); + + // Notify the CAS BACnet stack that this value has been updated. + // If there are any subscribers to this value, they will be sent be sent the updated value. + CASBACnetStackAdapter.ValueUpdated(database.Device.instance, CASBACnetStackAdapter.OBJECT_TYPE_ANALOG_INPUT, 0, CASBACnetStackAdapter.PROPERTY_IDENTIFIER_PRESENT_VALUE); } break; case ConsoleKey.DownArrow: @@ -214,6 +221,7 @@ private void DoUserInput() { this.database.AnalogInput[0].presentValue -= 0.01f; Console.WriteLine("FYI: Decrement Analog input {0} present value to {1:0.00}", 0, this.database.AnalogInput[0].presentValue); + CASBACnetStackAdapter.ValueUpdated(database.Device.instance, CASBACnetStackAdapter.OBJECT_TYPE_ANALOG_INPUT, 0, CASBACnetStackAdapter.PROPERTY_IDENTIFIER_PRESENT_VALUE); } break; default: