Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions BACnetServerExample/BACnetServerExample/CASBACnetStackAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);

Expand Down
18 changes: 13 additions & 5 deletions BACnetServerExample/BACnetServerExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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");

Expand All @@ -183,8 +185,9 @@ public void Run()
for (; ; )
{
CASBACnetStackAdapter.Loop();
database.Loop();
DoUserInput();

database.Loop(); // Just for this example
DoUserInput(); // Just for this example
}
}

Expand All @@ -207,13 +210,18 @@ 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:
if (this.database.AnalogInput.Length > 0)
{
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:
Expand Down