Ejemplo n.º 1
0
        // Methods

        /// <summary>
        /// Get sensor
        /// </summary>
        /// <returns></returns>
        protected override YSensor GetSensor()
        {
            string errmsg = "";

            if (hardwaredetect == 0)
            {
                YAPI.UpdateDeviceList(ref errmsg);
            }
            hardwaredetect = (hardwaredetect + 1) % 20;
            YAPI.HandleEvents(ref errmsg);
            YTemperature sensor = YTemperature.FirstTemperature();

            if (sensor is null)
            {
                throw new SensorNotDetectedException();
            }
            else if (!sensor.isOnline())
            {
                throw new SensorOfflineException();
            }
            else
            {
                return(sensor);
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string errmsg = "";
            string target;

            YTemperature tsensor;

            if (args.Length < 1)
            {
                usage();
            }
            target = args[0].ToUpper();

            // Setup the API to use local USB devices
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                tsensor = YTemperature.FirstTemperature();

                if (tsensor == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
                Console.WriteLine("Using: " + tsensor.get_module().get_serialNumber());
            }
            else
            {
                tsensor = YTemperature.FindTemperature(target + ".temperature1");
            }

            // retreive module serial
            string serial = tsensor.get_module().get_serialNumber();

            // retreive both channels
            YTemperature ch1 = YTemperature.FindTemperature(serial + ".temperature1");
            YTemperature ch2 = YTemperature.FindTemperature(serial + ".temperature2");

            if (!ch2.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }
            while (ch2.isOnline())
            {
                Console.Write("Ambiant: " + ch1.get_currentValue().ToString() + " °C  ");
                Console.Write("Infrared: " + ch2.get_currentValue().ToString() + " °C  ");
                Console.WriteLine("  (press Ctrl-C to exit)");
                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
        public static YTemperatureProxy FindTemperature(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YTemperature      func = null;
            YTemperatureProxy res  = (YTemperatureProxy)YFunctionProxy.FindSimilarUnknownFunction("YTemperatureProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YTemperatureProxy)YFunctionProxy.FindSimilarKnownFunction("YTemperatureProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YTemperature.FirstTemperature();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YTemperatureProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YTemperature.FindTemperature(name);
                if (func.get_userData() != null)
                {
                    return((YTemperatureProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YTemperatureProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
        /**
         * <summary>
         *   Enumerates all functions of type Temperature available on the devices
         *   currently reachable by the library, and returns their unique hardware ID.
         * <para>
         *   Each of these IDs can be provided as argument to the method
         *   <c>YTemperature.FindTemperature</c> to obtain an object that can control the
         *   corresponding device.
         * </para>
         * </summary>
         * <returns>
         *   an array of strings, each string containing the unique hardwareId
         *   of a device function currently connected.
         * </returns>
         */
        public static new string[] GetSimilarFunctions()
        {
            List <string> res = new List <string>();
            YTemperature  it  = YTemperature.FirstTemperature();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextTemperature();
            }
            return(res.ToArray());
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            string errmsg = "";
            string target;

            YTemperature tsensor;

            if (args.Length < 1)
            {
                usage();
            }
            target = args[0].ToUpper();

            // Setup the API to use local USB devices
            if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
            {
                Console.WriteLine("RegisterHub error: " + errmsg);
                Environment.Exit(0);
            }

            if (target == "ANY")
            {
                tsensor = YTemperature.FirstTemperature();

                if (tsensor == null)
                {
                    Console.WriteLine("No module connected (check USB cable) ");
                    Environment.Exit(0);
                }
            }
            else
            {
                tsensor = YTemperature.FindTemperature(target + ".temperature");
            }

            if (!tsensor.isOnline())
            {
                Console.WriteLine("Module not connected");
                Console.WriteLine("check identification and USB cable");
                Environment.Exit(0);
            }

            while (tsensor.isOnline())
            {
                Console.WriteLine("Current temperature: " + tsensor.get_currentValue().ToString()
                                  + " °C");
                Console.WriteLine("  (press Ctrl-C to exit)");

                YAPI.Sleep(1000, ref errmsg);
            }
            YAPI.FreeAPI();
        }
Ejemplo n.º 6
0
        private void moduleInventory()
        {
            YModule      m, currentmodule;
            YTemperature sensor;
            int          index;

            comboBox1.Items.Clear();
            currentmodule = null;
            sensor        = YTemperature.FirstTemperature();
            while (sensor != null)
            {
                m = sensor.get_module();
                comboBox1.Items.Add(m);
                sensor = sensor.nextTemperature();
            }

            if (comboBox1.Items.Count == 0)
            {
                comboBox1.Enabled          = false;
                Beacon.Enabled             = false;
                label1.Enabled             = false;
                label1.Text                = "N/A";
                toolStripStatusLabel2.Text = "Connect a device featuring a temperature sensor";
            }
            else
            {
                index             = 0;
                comboBox1.Enabled = true;
                Beacon.Enabled    = true;

                for (int i = 0; i < comboBox1.Items.Count; i++)
                {
                    if (comboBox1.Items[i].Equals(currentmodule))
                    {
                        index = i;
                    }
                }

                if (comboBox1.Items.Count == 1)
                {
                    toolStripStatusLabel2.Text = "One  device connected";
                }
                else
                {
                    toolStripStatusLabel2.Text = comboBox1.Items.Count.ToString() + " devices connected";
                }

                comboBox1.SelectedIndex = index;
            }
        }
Ejemplo n.º 7
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YTemperature tsensor;

                if (Target.ToLower() == "any")
                {
                    tsensor = YTemperature.FirstTemperature();

                    if (tsensor == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }

                    Target = await(await tsensor.get_module()).get_serialNumber();
                }

                WriteLine("Using: " + Target);
                // retreive all 6 channels
                YTemperature ch1 = YTemperature.FindTemperature(Target + ".temperature1");
                YTemperature ch2 = YTemperature.FindTemperature(Target + ".temperature2");
                YTemperature ch3 = YTemperature.FindTemperature(Target + ".temperature3");
                YTemperature ch4 = YTemperature.FindTemperature(Target + ".temperature4");
                YTemperature ch5 = YTemperature.FindTemperature(Target + ".temperature5");
                YTemperature ch6 = YTemperature.FindTemperature(Target + ".temperature6");

                while (await ch2.isOnline())
                {
                    Write("| 1: " + (await ch1.get_currentValue()).ToString(" 0.0"));
                    Write(" | 2: " + (await ch2.get_currentValue()).ToString(" 0.0"));
                    Write(" | 3: " + (await ch3.get_currentValue()).ToString(" 0.0"));
                    Write(" | 4: " + (await ch4.get_currentValue()).ToString(" 0.0"));
                    Write(" | 5: " + (await ch5.get_currentValue()).ToString(" 0.0"));
                    Write(" | 6: " + (await ch6.get_currentValue()).ToString(" 0.0"));
                    WriteLine("|  °C  ");
                    await YAPI.Sleep(1000);
                }

                WriteLine("Module not connected (check identification and USB cable)");
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
Ejemplo n.º 8
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YHumidity    hsensor;
                YTemperature tsensor;
                YPressure    psensor;

                if (Target.ToLower() == "any")
                {
                    hsensor = YHumidity.FirstHumidity();
                    tsensor = YTemperature.FirstTemperature();
                    psensor = YPressure.FirstPressure();

                    if ((hsensor == null) || (tsensor == null) || (psensor == null))
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }
                }
                else
                {
                    hsensor = YHumidity.FindHumidity(Target + ".humidity");
                    tsensor = YTemperature.FindTemperature(Target + ".temperature");
                    psensor = YPressure.FindPressure(Target + ".pressure");
                }

                while (await hsensor.isOnline())
                {
                    WriteLine("Humidity:    " + await hsensor.get_currentValue() + " %RH");
                    WriteLine("Temperature: " + await tsensor.get_currentValue() + " °C");
                    WriteLine("Pressure:    " + await psensor.get_currentValue() + " hPa");
                    await YAPI.Sleep(1000);
                }

                WriteLine("Module not connected (check identification and USB cable)");
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
Ejemplo n.º 9
0
        public override async Task <int> Run()
        {
            try {
                await YAPI.RegisterHub(HubURL);

                YTemperature tsensor;

                if (Target.ToLower() == "any")
                {
                    tsensor = YTemperature.FirstTemperature();

                    if (tsensor == null)
                    {
                        WriteLine("No module connected (check USB cable) ");
                        return(-1);
                    }

                    Target = await(await tsensor.get_module()).get_serialNumber();
                }

                WriteLine("Using: " + Target);

                // retreive both channels
                YTemperature ch1 = YTemperature.FindTemperature(Target + ".temperature1");
                YTemperature ch2 = YTemperature.FindTemperature(Target + ".temperature2");

                while (await ch2.isOnline())
                {
                    Write("Ambiant: " + await ch1.get_currentValue() + " °C  ");
                    WriteLine("Infrared: " + await ch2.get_currentValue() + " °C  ");
                    await YAPI.Sleep(1000);
                }

                WriteLine("Module not connected (check identification and USB cable)");
            } catch (YAPI_Exception ex) {
                WriteLine("error: " + ex.Message);
            }

            YAPI.FreeAPI();
            return(0);
        }
Ejemplo n.º 10
0
        private void EventThreadProc()
        {
            while (!_stop)
            {
                IsRunning = true;

                // attente 30eme seconds
                DateTime dt = DateTime.Now;
                if (dt.Second < 15)
                {
                    Thread.Sleep((15 - dt.Second) * 1000);
                }
                else
                {
                    Thread.Sleep(((59 - dt.Second) + 15) * 1000);
                }

                dt = DateTime.Now;

                if (dt.Minute == 00)
                {
                    _tempInfoClass = new tempInfo();
                }


                _isTempReceive = false;

                if (myPT100Probe == null)
                {
                    myPT100Probe = YTemperature.FirstTemperature();
                }
                if ((myPT100Probe != null) && (myPT100Probe.isOnline()))
                {
                    TempChamber    = TempBottle = myPT100Probe.get_currentValue();
                    _isTempReceive = true;
                }

                if (_isTempReceive)
                {
                    if (_tempInfoClass == null)
                    {
                        _tempInfoClass = new tempInfo();
                    }
                    AddTemp(dt, TempBottle);
                }

                dt = DateTime.Now;

                if (dt.Minute == 59)
                {
                    StoreTemp();
                }

                if (dt.Second < 59)
                {
                    Thread.Sleep(((59 - dt.Second) + 5) * 1000);
                }
                else
                {
                    Thread.Sleep(5 * 1000);
                }
            }
            IsRunning = false;
        }
        private void Timer_Tick(object sender, EventArgs eArgs)
        {
            ambiantTemp = double.MinValue;
            if (sender != Clock)
            {
                return;
            }
            if (!DisplayBadge)
            {
                if ((!CurrenRfidReader.IsConnected) || (bDoorJustClosed) ||
                    ((CurrenRfidReader.IsInScan) || (CurrenRfidReader.Door_Status == Door_Status.Door_Open)))
                {
                    return;
                }

                if (bTempReady)
                {
                    if (myPT100Probe == null)
                    {
                        myPT100Probe = YTemperature.FirstTemperature();
                    }
                    if ((myPT100Probe != null) && (myPT100Probe.isOnline()))
                    {
                        ambiantTemp = myPT100Probe.get_currentValue();
                    }
                }

                if (ambiantTemp != double.MinValue)
                {
                    WriteLCDLine(1, " - WAIT FOR USER -");
                    WriteLCDLine(2, " " + GetTime() + " - " + ambiantTemp.ToString("00.0") + "C");
                }
                else
                {
                    WriteLCDLine(1, " - WAIT FOR USER -");
                    WriteLCDLine(2, "      " + GetTime());
                }

                return;
            }
            else
            {
                Clock.Stop();
                DisplayBadge = false;
                WriteLCDLine(1, "       BADGE :");
                WriteLCDLine(2, "     " + StrBadgeRead);
                Thread.Sleep(100);
                if (!CurrenRfidReader.TCPActionPending)
                {
                    LogToFile.LogMessageToFile("Before check badge in timer");
                    if (CheckBadge(StrBadgeRead))
                    {
                        LogToFile.LogMessageToFile("Badge Checked in timer");
                        OnBadgeReader(StrBadgeRead);

                        badgeset = true;
                        LogToFile.LogMessageToFile("Unlock DOOR event in timer");
                        OpenDoor();
                        if (BadgeEvent != null)
                        {
                            BadgeEvent.Set();
                            LogToFile.LogMessageToFile("Badge event SET in timer");
                        }
                    }

                    else
                    {
                        LogToFile.LogMessageToFile("Badge not granted");
                        WriteLCDLine(1, "       BADGE :");
                        WriteLCDLine(2, " BADGE NOT GRANTED!");
                        Clock.Start();
                        //Enable TCP Scan
                        CurrenRfidReader.UserActionPending = false;
                    }
                }
                else
                {
                    LogToFile.LogMessageToFile("TCP action pending");
                    WriteLCDLine(1, "       INFO  :");
                    WriteLCDLine(2, " NETWORK QUERY");
                    Clock.Start();
                    //Enable TCP Scan
                    CurrenRfidReader.UserActionPending = false;
                }
            }
        }