Exemple #1
0
 /*****************************************************************************************************/
 static void RaspberryGpioConfig()
 {
     FileGPIO.CleanUpAllPins();
     try
     {
         foreach (System.IO.BACnet.Storage.Object o in m_storage.Objects)
         {
             if (o.Type == BacnetObjectTypes.OBJECT_BINARY_INPUT)
             {
                 FileGPIO.InputPin(o.Instance);
                 Input.Add(new BacnetObjectId(BacnetObjectTypes.OBJECT_BINARY_INPUT, o.Instance));
                 Console.WriteLine("GPIO" + o.Instance.ToString() + " as Input in OBJECT_BINARY_INPUT:" + o.Instance.ToString());
             }
             if (o.Type == BacnetObjectTypes.OBJECT_BINARY_OUTPUT)
             {
                 FileGPIO.OutputPin(o.Instance, true);
                 Output.Add(new BacnetObjectId(BacnetObjectTypes.OBJECT_BINARY_OUTPUT, o.Instance));
                 Console.WriteLine("GPIO" + o.Instance.ToString() + " as Output in OBJECT_BINARY_OUTPUT:" + o.Instance.ToString());
             }
         }
     }
     catch { }
 }
Exemple #2
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 { }
        }