public static bool HW_Init()
        {
            ALLINIT = false;
            try
            {
                ALLINIT = true;
                ONLINE = false;
                // LEDS
                OutPorts = new OutputPort[6];

                OutPorts[(int)PINS.led_A] = new OutputPort(Pins.GPIO_PIN_A0, false); // Buttons RS485
                OutPorts[(int)PINS.led_B] = new OutputPort(Pins.GPIO_PIN_A1, false); // WatchDog
                OutPorts[(int)PINS.led_C] = new OutputPort(Pins.GPIO_PIN_A2, false); // Ethernet
                OutPorts[(int)PINS.led_D] = new OutputPort(Pins.GPIO_PIN_A3, false); // Reader
                OutPorts[(int)PINS.Out_D9] = new OutputPort(Pins.GPIO_PIN_D9, true); //
                OutPorts[(int)PINS.RxTx] = new OutputPort(Pins.GPIO_PIN_D4, false); //

                DebugPrint("PINS SETTINGS ...... inicialized");

                // RTC
                //try
                //{
                //    rtc = new DS1307();
                //    rtc.Synchronize();
                //    DebugPrint("RTC ................ inicialized, date and time: " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss"));
                //}
                //catch
                //{
                //    DebugPrint("RTC ................ failed");
                //}

                // WatchDog
                wdt = new WatchDog();

                // Reader
                ALLINIT = Reader.Init();
                ReaderFw = Reader.GetFirmware();
                DebugPrint("RFID ............... " + ReaderFw);

                // SD card
                SecureDigital.TreeCheck();
                DebugPrint("SECURE DIGITAL ..... inicialized");

                // Read data from SD card
                new Settings().Read();
                new Blocking().Read();          

                // RS485
                bool buttons = ALLINIT = (!ALLINIT) ? false : Buttons.Init();
                if (buttons)
                {
                    Buttons.Write(ALL, Screen.main);
                    DebugPrint("RS485 .............. inicialized");
                }
                else
                {
                    DebugPrint("RS485 .............. failed");
                }

                if (IPAddress.GetDefaultLocalAddress() != IPAddress.Any) //&& entryIP.AddressList[0].ToString() != NetworkInterface.GetAllNetworkInterfaces()[0].GatewayAddress
                {
                    MacAddress = HexMacToSring((NetworkInterface.GetAllNetworkInterfaces()[0]).PhysicalAddress);
                    IpAddress = IPAddress.GetDefaultLocalAddress().ToString();
                    Thread.Sleep(100);
                    NETWORK = true;

                    DebugPrint("NETWORK ............ inicialized");
                    DebugPrint("IP ADDRESS ......... " + IpAddress);
                    DebugPrint("MAC ADDRESS ........ " + MacAddress);
                }
                else
                {
                    DebugPrint("NETWORK ............ failed");
                    NETWORK = false;
                    ALLINIT = false;
                }

                DebugPrint("AVAILABLE MEMORY ... " + Debug.GC(false).ToString());


                Thread.Sleep(1000);

                if (NETWORK)
                {
                    DebugPrint("LOADING SETTINGS ... waiting");

                    // Posílám dotaz nanastavení 5x
                    for (int i = 0; i < 5; i++)
                    {
                        if (!Ethernet.Request("sn=" + settings.sn.ToString() + "&event=100&init=1"))
                        {
                            Thread.Sleep(1000);
                            continue;
                        }
                        break;
                    }

                    if (READ_SETTINGS)
                    {
                        Ethernet.UniqueId();

                        DebugPrint("LOADING SETTINGS ... loaded");
                        // Check for files
                        for (int i = 1; i <= settings.positions; i++)
                        {
                            SecureDigital.FileExists(@"SD\bottles\", "btl_" + i.ToString());
                            SecureDigital.FileExists(@"SD\calibration\", "cal_" + i.ToString());
                        }

                        // Check buttons present
                        for (int i = 1; i <= settings.positions; i++)
                        {
                            string result = String.Empty;
                            bool res = (Buttons.Write(i));
                            allbuttons = (!allbuttons) ? false : res;
                            result = (res) ? " respond" : " not respond";
                            DebugPrint("Position " + i.ToString() + result);
                        }

                        DebugPrint("LOADING BOTTLES .... waiting");
                        // Posílám dotaz nanastavení 5x
                        for (int i = 0; i < 5; i++)
                        {
                            if (!Ethernet.Request("sn=" + settings.sn.ToString() + "&event=101&init=1"))
                            {
                                Thread.Sleep(1000);
                                continue;
                            }
                            break;
                        }

                        if (CH_BOTTLE_OK)
                        {
                            Ethernet.UniqueId();
                            ONLINE = true;
                            DebugPrint("LOADING BOTTLES .... loaded");

                            DebugPrint("LOADING DATETIME ... waiting");

                            Ethernet.Request("sn=" + settings.sn.ToString() + "&event=400&init=1");
                            if (DATETIME_OK)
                            {
                                Ethernet.UniqueId();

                            }
                        }
                        else
                        {
                            ALLINIT = false;
                            DebugPrint("\r\nCOMMUNICATION ERROR: READ BOTTLES -> NO ANSWARE\r\n");
                        }
                    }
                    else
                    {
                        ALLINIT = false;
                        DebugPrint("\r\nCOMMUNICATION ERROR: READ SETTINGS -> NO ANSWARE\r\n");
                    }

                }

                return true;
            }
            catch (Exception e)
            {
                DebugPrint(e.Message + " | " + e.StackTrace);
                NETWORK = false;
                return false;
            }
        }
        public static bool HW_Init()
        {
            // LEDS
            OutPorts = new OutputPort[6];

            OutPorts[(int)PINS.led_A] = new OutputPort(Pins.GPIO_PIN_A0, false); // Buttons RS485
            OutPorts[(int)PINS.led_B] = new OutputPort(Pins.GPIO_PIN_A1, false); // WatchDog
            OutPorts[(int)PINS.led_C] = new OutputPort(Pins.GPIO_PIN_A2, false); // Ethernet
            OutPorts[(int)PINS.led_D] = new OutputPort(Pins.GPIO_PIN_A3, false); // Reader
            OutPorts[(int)PINS.Out_D9] = new OutputPort(Pins.GPIO_PIN_D9, true); //
            OutPorts[(int)PINS.RxTx] = new OutputPort(Pins.GPIO_PIN_D4, false); //

            DebugPrint("PINS SETTINGS ...... inicialized");

            // RTC
            try
            {
                rtc = new DS1307();
                rtc.Synchronize();
                Program.start = DateTime.Now;
                DebugPrint("RTC ................ inicialized, date and time: " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss"));
            }
            catch
            {
                DebugPrint("RTC ................ failed");
            }

            // WatchDog
            wdt = new WatchDog();

            // Reader
            Reader.Init();
            ReaderFw = Reader.GetFirmware();
            DebugPrint("RFID ............... " + ReaderFw);

            // SD card
            SecureDigital.TreeCheck();
            DebugPrint("SECURE DIGITAL ..... inicialized");

            // RS485
            if (Buttons.Init())
            {
                Buttons.Write(ALL, Screen.main);
                DebugPrint("RS485 .............. inicialized");
            }
            else
            {
                DebugPrint("RS485 .............. failed");
            }

            DebugPrint("LOADING SETTINGS ... waiting");

            // Read data from SD card
            new Settings().Read();

            DebugPrint("LOADING SETTINGS ... loaded");

            // Check for files
            for (int i = 1; i <= settings.positions; i++)
            {
                SecureDigital.FileExists(@"SD\bottles\", "btl_" + i.ToString());
                SecureDigital.FileExists(@"SD\calibration\", "cal_" + i.ToString());
            }

            // Check buttons present
            for (int i = 1; i <= settings.positions; i++)
            {
                string result = String.Empty;
                bool res = (Buttons.Write(i));
                allbuttons = (!allbuttons) ? false : res;
                result = (res) ? " respond" : " not respond";
                DebugPrint("Position " + i.ToString() + result);
            }

            DebugPrint("LOADING BOTTLES .... waiting");
            // Posílám dotaz nanastavení 5x
            for (int i = 1; i <= settings.positions; i++)
            {
                bottleData.Clear();
                Bottle btl = new Bottle();
                btl.Read(i);
                bottleData.position = i;
                Buttons.SendSettings();
                bottleData.Clear();
            }
            DebugPrint("LOADING BOTTLES .... loaded");

            return true;

        }