Example #1
0
            // Server setup and main loop
            public void Run()
            {
                Console.WriteLine("Starting Windows-BACnetServerExampleProprietaryPropertyCSharp version {0}.{1}", APPLICATION_VERSION, CIBuildVersion.CIBUILDNUMBER);
                Console.WriteLine("https://github.com/chipkin/BACnetServerExampleProprietaryPropertyCSharp");
                Console.WriteLine("FYI: BACnet Stack version: {0}.{1}.{2}.{3}",
                                  CASBACnetStackAdapter.GetAPIMajorVersion(),
                                  CASBACnetStackAdapter.GetAPIMinorVersion(),
                                  CASBACnetStackAdapter.GetAPIPatchVersion(),
                                  CASBACnetStackAdapter.GetAPIBuildVersion());

                // 1. Setup the callbacks
                // ---------------------------------------------------------------------------

                // Send/Recv callbacks.
                CASBACnetStackAdapter.RegisterCallbackSendMessage(SendMessage);
                CASBACnetStackAdapter.RegisterCallbackReceiveMessage(RecvMessage);
                CASBACnetStackAdapter.RegisterCallbackGetSystemTime(CallbackGetSystemTime);

                // Get Datatype Callbacks
                CASBACnetStackAdapter.RegisterCallbackGetPropertyCharacterString(CallbackGetPropertyCharString);

                // Set Datatype Callbacks
                CASBACnetStackAdapter.RegisterCallbackSetPropertyCharacterString(CallbackSetPropertyCharacterString);

                // 2. Setup the BACnet device
                // ---------------------------------------------------------------------------

                // Initialize database
                this.database.Setup();

                // Add the device
                CASBACnetStackAdapter.AddDevice(this.database.Device.instance);
                CASBACnetStackAdapter.SetProprietaryProperty(this.database.Device.instance, CASBACnetStackAdapter.OBJECT_TYPE_DEVICE, this.database.Device.instance, 512 + 1, false, false, CASBACnetStackAdapter.DATA_TYPE_CHARACTER_STRING, false, false, false);
                CASBACnetStackAdapter.SetProprietaryProperty(this.database.Device.instance, CASBACnetStackAdapter.OBJECT_TYPE_DEVICE, this.database.Device.instance, 512 + 2, true, true, CASBACnetStackAdapter.DATA_TYPE_CHARACTER_STRING, false, false, false);

                // 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);

                // All done with the BACnet setup
                Console.WriteLine("FYI: CAS BACnet Stack Setup, successfuly");

                // 3. Open the BACnet port to receive messages
                // ---------------------------------------------------------------------------
                this.udpServer        = new UdpClient(SETTING_BACNET_PORT);
                this.RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

                // 4. Main loop
                // ---------------------------------------------------------------------------
                Console.WriteLine("FYI: Starting main loop");
                for (; ;)
                {
                    CASBACnetStackAdapter.Loop(); // CAS BACnet stack loop

                    database.Loop();              // Update database values
                }
            }
Example #2
0
            // Server setup and main loop
            public void Run()
            {
                Console.WriteLine("Starting Windows BACnetServer TrendLog Example CSharp version: {0}.{1}", APPLICATION_VERSION, CIBuildVersion.CIBUILDNUMBER);
                Console.WriteLine("https://github.com/chipkin/BACnetServerTrendLogExampleCSharp");
                Console.WriteLine("FYI: BACnet Stack version: {0}.{1}.{2}.{3}",
                                  CASBACnetStackAdapter.GetAPIMajorVersion(),
                                  CASBACnetStackAdapter.GetAPIMinorVersion(),
                                  CASBACnetStackAdapter.GetAPIPatchVersion(),
                                  CASBACnetStackAdapter.GetAPIBuildVersion());

                // 1. Setup the callbacks
                // ---------------------------------------------------------------------------

                // Send/Recv Callbacks
                CASBACnetStackAdapter.RegisterCallbackSendMessage(SendMessage);
                CASBACnetStackAdapter.RegisterCallbackReceiveMessage(RecvMessage);

                // System Callbacks
                CASBACnetStackAdapter.RegisterCallbackGetSystemTime(CallbackGetSystemTime);

                // Get Property Callbacks
                CASBACnetStackAdapter.RegisterCallbackGetPropertyCharacterString(CallbackGetPropertyCharString);
                CASBACnetStackAdapter.RegisterCallbackGetPropertyEnumerated(CallbackGetEnumerated);
                CASBACnetStackAdapter.RegisterCallbackGetPropertyReal(CallbackGetPropertyReal);
                CASBACnetStackAdapter.RegisterCallbackGetPropertyUnsignedInteger(CallbackGetUnsignedInteger);


                // 2. Setup the BACnet device
                // ---------------------------------------------------------------------------

                // Setup database
                database.Setup();

                // Add Objects
                // ---------------------------------------------------------------------------

                // Add the device
                CASBACnetStackAdapter.AddDevice(database.Device.Instance);
                CASBACnetStackAdapter.SetPropertyEnabled(database.Device.Instance, CASBACnetStackAdapter.OBJECT_TYPE_DEVICE, database.Device.Instance, CASBACnetStackAdapter.PROPERTY_IDENTIFIER_DESCRIPTION, true);

                // Add analog inputs
                CASBACnetStackAdapter.AddObject(database.Device.Instance, CASBACnetStackAdapter.OBJECT_TYPE_ANALOG_INPUT, database.AnalogInputAutoIncrement.Instance);
                CASBACnetStackAdapter.AddObject(database.Device.Instance, CASBACnetStackAdapter.OBJECT_TYPE_ANALOG_INPUT, database.AnalogInputManualIncrement.Instance);

                // Add binary input
                CASBACnetStackAdapter.AddObject(database.Device.Instance, CASBACnetStackAdapter.OBJECT_TYPE_BINARY_INPUT, database.BinaryInput.Instance);

                // Add multi-state input
                CASBACnetStackAdapter.AddObject(database.Device.Instance, CASBACnetStackAdapter.OBJECT_TYPE_MULTI_STATE_INPUT, database.MultiStateInput.Instance);

                // Add Trend Log
                CASBACnetStackAdapter.AddTrendLogObject(database.Device.Instance, database.TrendLog.Instance, CASBACnetStackAdapter.OBJECT_TYPE_ANALOG_INPUT, database.AnalogInputAutoIncrement.Instance, CASBACnetStackAdapter.PROPERTY_IDENTIFIER_PRESENT_VALUE, 100, false, 0);
                CASBACnetStackAdapter.SetTrendLogTypeToPolled(database.Device.Instance, CASBACnetStackAdapter.OBJECT_TYPE_TREND_LOG, database.TrendLog.Instance, true, false, 3000);

                // Add Trend Log Multiple
                CASBACnetStackAdapter.AddTrendLogMultipleObject(database.Device.Instance, database.TrendLogMultiple.Instance, 100);
                CASBACnetStackAdapter.AddLoggedObjectToTrendLogMultiple(database.Device.Instance, database.TrendLogMultiple.Instance, CASBACnetStackAdapter.OBJECT_TYPE_ANALOG_INPUT, database.AnalogInputAutoIncrement.Instance, CASBACnetStackAdapter.PROPERTY_IDENTIFIER_PRESENT_VALUE, false, 0, false, 0);
                CASBACnetStackAdapter.AddLoggedObjectToTrendLogMultiple(database.Device.Instance, database.TrendLogMultiple.Instance, CASBACnetStackAdapter.OBJECT_TYPE_ANALOG_INPUT, database.AnalogInputManualIncrement.Instance, CASBACnetStackAdapter.PROPERTY_IDENTIFIER_PRESENT_VALUE, false, 0, false, 0);
                CASBACnetStackAdapter.AddLoggedObjectToTrendLogMultiple(database.Device.Instance, database.TrendLogMultiple.Instance, CASBACnetStackAdapter.OBJECT_TYPE_BINARY_INPUT, database.BinaryInput.Instance, CASBACnetStackAdapter.PROPERTY_IDENTIFIER_PRESENT_VALUE, false, 0, false, 0);
                CASBACnetStackAdapter.AddLoggedObjectToTrendLogMultiple(database.Device.Instance, database.TrendLogMultiple.Instance, CASBACnetStackAdapter.OBJECT_TYPE_MULTI_STATE_INPUT, database.MultiStateInput.Instance, CASBACnetStackAdapter.PROPERTY_IDENTIFIER_PRESENT_VALUE, false, 0, false, 0);
                CASBACnetStackAdapter.SetTrendLogTypeToPolled(database.Device.Instance, CASBACnetStackAdapter.OBJECT_TYPE_TREND_LOG_MULTIPLE, database.TrendLogMultiple.Instance, true, false, 3000);


                // 3. Enable Services
                // ---------------------------------------------------------------------------
                // Enable Optional Properties
                CASBACnetStackAdapter.SetServiceEnabled(database.Device.Instance, CASBACnetStackAdapter.SERVICES_SUPPORTED_READ_PROPERTY_MULTIPLE, true);
                CASBACnetStackAdapter.SetServiceEnabled(database.Device.Instance, CASBACnetStackAdapter.SERVICES_SUPPORTED_WRITE_PROPERTY, true);
                CASBACnetStackAdapter.SetServiceEnabled(database.Device.Instance, CASBACnetStackAdapter.SERVICES_SUPPORTED_READ_RANGE, true);

                // All done with the BACnet Setup
                Console.WriteLine("FYI: CAS BACnet Stack Setup, successfully");


                // 4. Setup Trend Log objects
                // ---------------------------------------------------------------------------

                Console.WriteLine("FYI: Loading initial data points to Trend Log and Trend Log Multiple objects");

                // Preload Trend Log and Trend Log Multiple from file
                string currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

                _trendLogBackupPath         = Path.Combine(currentDirectory, "trendLogBackupExample.txt");
                _trendLogMultipleBackupPath = Path.Combine(currentDirectory, "trendLogMultipleBackupExample.txt");

                if (!LoadTrendLogFromFile(_trendLogBackupPath))
                {
                    Console.WriteLine("Failed to load trendLog from {0}", _trendLogBackupPath);
                    return;
                }
                if (!LoadTrendLogMultipleFromFile(_trendLogMultipleBackupPath))
                {
                    Console.WriteLine("Failed to load trendLogMultiple from {0}", _trendLogMultipleBackupPath);
                    return;
                }
                Console.WriteLine("FYI: Initial data load complete");

                // 5. Open the BACnet port to receive messages
                // ---------------------------------------------------------------------------
                udpServer        = new UdpClient(SETTING_BACNET_PORT);
                remoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);


                // 6. Main loop
                // ---------------------------------------------------------------------------
                Console.WriteLine("FYI: Starting main loop");
                for (; ;)
                {
                    CASBACnetStackAdapter.Loop(); // BACnet Stack adapter update loop

                    database.Loop();              // Update values in the example database

                    DoUserInput();                // Handle user input
                }
            }
Example #3
0
            ConsoleKey subOption = ConsoleKey.NoName;   // If set to NoName, no suboption.  See CheckUserInput for more info

            // Server setup and main loop
            public void Run()
            {
                Console.WriteLine("Starting BACnet Client Example CSharp version {0}.{1}", APPLICATION_VERSION, CIBuildVersion.CIBUILDNUMBER);
                Console.WriteLine("https://github.com/chipkin/BACnetClientExampleCSharp");
                Console.WriteLine("FYI: BACnet Stack version: {0}.{1}.{2}.{3}",
                                  CASBACnetStackAdapter.GetAPIMajorVersion(),
                                  CASBACnetStackAdapter.GetAPIMinorVersion(),
                                  CASBACnetStackAdapter.GetAPIPatchVersion(),
                                  CASBACnetStackAdapter.GetAPIBuildVersion());

                // 1. Setup the hooks and callbacks
                // ---------------------------------------------------------------------------
                // Send/Recv callbacks
                CASBACnetStackAdapter.RegisterCallbackSendMessage(SendMessage);
                CASBACnetStackAdapter.RegisterCallbackReceiveMessage(RecvMessage);
                CASBACnetStackAdapter.RegisterCallbackGetSystemTime(CallbackGetSystemTime);
                CASBACnetStackAdapter.RegisterCallbackGetPropertyUnsignedInteger(CallbackGetUnsignedInteger);

                // Data type hooks
                CASBACnetStackAdapter.BACnetStack_RegisterHookIAm(CallbackHookIAm);
                CASBACnetStackAdapter.BACnetStack_RegisterHookIHave(CallbackHookIHave);
                CASBACnetStackAdapter.BACnetStack_RegisterHookError(CallbackHookError);
                CASBACnetStackAdapter.BACnetStack_RegisterHookReject(CallbackHookReject);
                CASBACnetStackAdapter.BACnetStack_RegisterHookAbort(CallbackHookAbort);
                CASBACnetStackAdapter.BACnetStack_RegisterHookSimpleAck(CallbackHookSimpleAck);
                CASBACnetStackAdapter.BACnetStack_RegisterHookTimeout(CallbackHookTimeout);
                CASBACnetStackAdapter.BACnetStack_RegisterHookPropertyBitString(CallbackHookPropertyBitString);
                CASBACnetStackAdapter.BACnetStack_RegisterHookPropertyBool(CallbackHookPropertyBool);
                CASBACnetStackAdapter.BACnetStack_RegisterHookPropertyCharString(CallbackHookPropertyCharString);
                CASBACnetStackAdapter.BACnetStack_RegisterHookPropertyDate(CallbackHookPropertyDate);
                CASBACnetStackAdapter.BACnetStack_RegisterHookPropertyDouble(CallbackHookPropertyDouble);
                CASBACnetStackAdapter.BACnetStack_RegisterHookPropertyEnum(CallbackHookPropertyEnum);
                CASBACnetStackAdapter.BACnetStack_RegisterHookPropertyNull(CallbackHookPropertyNull);
                CASBACnetStackAdapter.BACnetStack_RegisterHookPropertyObjectIdentifier(CallbackHookPropertyObjectIdentifier);
                CASBACnetStackAdapter.BACnetStack_RegisterHookPropertyOctString(CallbackHookPropertyOctString);
                CASBACnetStackAdapter.BACnetStack_RegisterHookPropertyInt(CallbackHookPropertyInt);
                CASBACnetStackAdapter.BACnetStack_RegisterHookPropertyReal(CallbackHookPropertyReal);
                CASBACnetStackAdapter.BACnetStack_RegisterHookPropertyTime(CallbackHookPropertyTime);
                CASBACnetStackAdapter.BACnetStack_RegisterHookPropertyUInt(CallbackHookPropertyUInt);

                // 2. Setup the BACnet device
                // ---------------------------------------------------------------------------

                CASBACnetStackAdapter.AddDevice(SETTING_BACNET_DEVICE_INSTANCE);

                // 3. Enable Services
                // ---------------------------------------------------------------------------
                // Enable I-Am Service
                CASBACnetStackAdapter.SetServiceEnabled(SETTING_BACNET_DEVICE_INSTANCE, CASBACnetStackAdapter.SERVICES_SUPPORTED_I_AM, true);

                // Disabling WhoIs processing so this example does not respond to the WhoIs message it sends
                CASBACnetStackAdapter.SetServiceEnabled(SETTING_BACNET_DEVICE_INSTANCE, CASBACnetStackAdapter.SERVICES_SUPPORTED_WHO_IS, false);

                // All done with the BACnet setup.
                Console.WriteLine("FYI: CAS BACnet Stack Setup, successfuly");


                // 4. Open the BACnet port to receive messages
                // ---------------------------------------------------------------------------
                this.udpServer        = new UdpClient(SETTING_BACNET_PORT);
                this.RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);


                // 5. Start the main loop
                // ---------------------------------------------------------------------------
                Console.WriteLine("FYI: Starting main loop");
                PrintHelp();
                for (; ;)
                {
                    // Main BACnet stack loop
                    CASBACnetStackAdapter.Loop();

                    // Exit program if Q is hit on main menu
                    if (!CheckUserInput())
                    {
                        break;
                    }
                }
            }