public static BacnetValue GetBacObjectPresentValue(BacnetObjectId id)
        {
            // L'index 0 c'est le nombre de valeurs associées à la propriété
            // L'index 1 pour la première valeur
            // L'index System.IO.BACnet.Serialize.ASN1.BACNET_ARRAY_ALL pour tout le tableau
            IList <BacnetValue> val = null;

            m_storage.ReadProperty(id, BacnetPropertyIds.PROP_PRESENT_VALUE, 1, out val);
            return(val[0]);
        }
Esempio n. 2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation("Worker has started.");

            while (!stoppingToken.IsCancellationRequested)
            {
                startActivity();
                _logger.LogInformation("Started");

                BacnetObjectId OBJECT_ANALOG_VALUE_0 = new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_VALUE, 0);
                BacnetObjectId OBJECT_ANALOG_INPUT_0 = new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_INPUT, 0);

                double count = 0;

                for (; ;)
                {
                    lock (m_storage)         // read and write callback are fired in a separated thread, so multiple access needs protection
                    {
                        // Read the Present Value
                        IList <BacnetValue> valtoread;
                        // index 0 : number of values in the array
                        // index 1 : first value
                        m_storage.ReadProperty(OBJECT_ANALOG_VALUE_0, BacnetPropertyIds.PROP_PRESENT_VALUE, 1, out valtoread);
                        // Get the first ... and here the only element
                        double coef = Convert.ToDouble(valtoread[0].Value);

                        float sin = (float)(coef * Math.Sin(count));
                        // Write the Present Value
                        IList <BacnetValue> valtowrite = new BacnetValue[1] {
                            new BacnetValue(sin)
                        };
                        m_storage.WriteProperty(OBJECT_ANALOG_INPUT_0, BacnetPropertyIds.PROP_PRESENT_VALUE, 1, valtowrite, true);
                    }
                    await Task.Delay(1000, stoppingToken);

                    count += 0.1;
                }

                //_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
                //await Task.Delay(1000, stoppingToken);
            }
        }
Esempio n. 3
0
        /*****************************************************************************************************/
        static void Main(string[] args)
        {
            Trace.Listeners.Add(new ConsoleTraceListener());

            try
            {
                StartActivity();
                Console.WriteLine("Started");

                BacnetObjectId OBJECT_ANALOG_VALUE_0 = new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_VALUE, 0);
                BacnetObjectId OBJECT_ANALOG_INPUT_0 = new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_INPUT, 0);

                Console.WriteLine(OBJECT_ANALOG_VALUE_0.Type + OBJECT_ANALOG_VALUE_0.Instance);

                double count = 0;

                for (; ;)
                {
                    lock (m_storage)         // read and write callback are fired in a separated thread, so multiple access needs protection
                    {
                        // Read the Present Value
                        IList <BacnetValue> valtoread;
                        // index 0 : number of values in the array
                        // index 1 : first value
                        m_storage.ReadProperty(OBJECT_ANALOG_VALUE_0, BacnetPropertyIds.PROP_PRESENT_VALUE, 1, out valtoread);
                        // Get the first ... and here the only element
                        double coef = Convert.ToDouble(valtoread[0].Value);
                        // Write the Present Value
                        float sin = (float)(coef * Math.Sin(count));
                        IList <BacnetValue> valtowrite = new BacnetValue[1] {
                            new BacnetValue(sin)
                        };
                        Console.WriteLine(valtowrite.ElementAt(0).Value);
                        m_storage.WriteProperty(OBJECT_ANALOG_INPUT_0, BacnetPropertyIds.PROP_PRESENT_VALUE, 1, valtowrite, true);
                    }
                    Thread.Sleep(1000);
                    count += 0.1;
                }
            }
            catch (Exception e) { Console.WriteLine(e.Message); };
        }
Esempio n. 4
0
 /*****************************************************************************************************/
 static void handler_OnReadPropertyRequest(BacnetClient sender, BacnetAddress adr, byte invoke_id, BacnetObjectId object_id, BacnetPropertyReference property, BacnetMaxSegments max_segments)
 {
     lock (m_storage)
     {
         try
         {
             IList <BacnetValue>      value;
             DeviceStorage.ErrorCodes code = m_storage.ReadProperty(object_id, (BacnetPropertyIds)property.propertyIdentifier, property.propertyArrayIndex, out value);
             if (code == DeviceStorage.ErrorCodes.Good)
             {
                 sender.ReadPropertyResponse(adr, invoke_id, sender.GetSegmentBuffer(max_segments), object_id, property, value);
             }
             else
             {
                 sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_PROPERTY, invoke_id, BacnetErrorClasses.ERROR_CLASS_DEVICE, BacnetErrorCodes.ERROR_CODE_OTHER);
             }
         }
         catch (Exception)
         {
             sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_PROPERTY, invoke_id, BacnetErrorClasses.ERROR_CLASS_DEVICE, BacnetErrorCodes.ERROR_CODE_OTHER);
         }
     }
 }
Esempio n. 5
0
        /*****************************************************************************************************/
        static void Main(string[] args)
        {
            //Trace.Listeners.Add(new ConsoleTraceListener());

            Input  = new List <BacnetObjectId>();
            Output = new List <BacnetObjectId>();

            try
            {
                StartActivity();
                Console.WriteLine("Running");

                BacnetObjectId Temp = new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_INPUT, 0);

                for (;;)
                {
                    Thread.Sleep(50);
                    // Refresh all input & output

                    foreach (BacnetObjectId o in Input)
                    {
                        // MemGPIO could be used in place of FileGPIO only on Raspberry, not Edison, Beaglebone, ...
                        IList <BacnetValue> valtowrite = new BacnetValue[1] {
                            new BacnetValue(Convert.ToUInt16(FileGPIO.InputPin(o.instance)))
                        };
                        lock (m_storage)
                            m_storage.WriteProperty(o, BacnetPropertyIds.PROP_PRESENT_VALUE, 1, valtowrite);
                    }

                    foreach (BacnetObjectId o in Output)
                    {
                        IList <BacnetValue> valtoread;
                        // index 0 : number of values in the array
                        // index 1 : first value
                        lock (m_storage)
                            m_storage.ReadProperty(o, BacnetPropertyIds.PROP_PRESENT_VALUE, 1, out valtoread);
                        // Get the first ... and here the only element
                        bool val = Convert.ToBoolean(valtoread[0].Value);
                        // MemGPIO could be used in place of FileGPIO only on Raspberry, not Edison, Beaglebone, ...
                        FileGPIO.OutputPin(o.instance, val);
                    }

                    // Refresh CPU Temp
                    try
                    {
                        // Change to /sys/class/hwmon/hwmon0/device/temp1_input for Beaglebone
                        // Change to /sys/class/thermal/thermal_zone3/temp ou /sys/class/thermal/thermal_zone4/temp for Intel Edison
                        string readValue = File.ReadAllText("/sys/class/thermal/thermal_zone0/temp");
                        int    tc        = Convert.ToInt32(readValue);
                        tc = tc / 100;
                        IList <BacnetValue> valtowrite = new BacnetValue[1] {
                            new BacnetValue(((double)tc) / 10.0)
                        };
                        lock (m_storage)
                            m_storage.WriteProperty(Temp, BacnetPropertyIds.PROP_PRESENT_VALUE, 1, valtowrite);
                    }
                    catch { }
                }
            }
            catch { }
        }