Esempio n. 1
0
        public static LCD43 lcd = new LCD43();              // Displej

        // MAIN
        public static void Main()
        {
            Thread.Sleep(1000);

            CommonFunc.BLOCKING = false;
            HttpSettings.ONLINE = false;
            HttpSettings.NETWORK = false;

            if (TEST)
            {
                CommonFunc.DebugPrint("===========================================");
                CommonFunc.DebugPrint("===========================================");
                CommonFunc.DebugPrint("=========RUNING ONT TEST SERVER============");
                CommonFunc.DebugPrint("===========================================");
                CommonFunc.DebugPrint("===========================================");
            }

            // Lcd
            if (lcd.Init())
            {
                lcd.Screen = (int)SCREEN.black;
                lcd.PrintPrompt("LCD display Init .. OK ");

                Thread.Sleep(500);
                Utility.SetLocalTime(lcd.ReadDateTime());                   // nastavim datetime dle rttc v displeji

                lcd.PrintPrompt("RTTC Init ......... OK ");
                lcd.PrintPrompt(DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss"));
            }
            else
            {
                ArrayList lsl = new ArrayList();
                Utility.SetLocalTime(new DateTime(2015, 1, 1));

                CommonFunc.DebugPrint("LCD display Init ...... Error ");
            }

            Thread.Sleep(500);

            // RFID ctecka
            SL030.Open();
            Thread.Sleep(500);
            lcd.PrintPrompt("RFID Card Reader " + SL030.ReaderName);
            Thread.Sleep(500);

            // SD Create directory
            lcd.PrintPrompt(new SD_Init().CreateDirectory());
            Thread.Sleep(500);
            Settings.Read();                               // nactu nastaveni  s SD            
            lcd.PrintPrompt("Read settings from SD .. OK");
            Thread.Sleep(500);

            // Clear DataCard
            DataCard.Clear();
            Thread.Sleep(500);

            // Tlacitka
            ButtonRS485.Open();
            Thread.Sleep(500);
            for (int addr = 1; addr <= Settings.buttonNumber; addr++)
            {
                if (ButtonRS485.ReadButton(addr) >= 0)
                {
                    lcd.PrintPrompt("Push Button " + addr + " .......... OK ");
                }
                else
                {
                    lcd.PrintPrompt("Push Button " + addr + " ......... Error ");
                }
                Thread.Sleep(100);
            }

            Thread.Sleep(500);

            NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;

            HttpSettings.NetworkSettings();

            //=============================================================
            //================== MAIN CYCLE BEGINS HERE ===================
            //=============================================================

            while (true)
            {

                /// vzestupna hrana
                bool tagdetectnew = !SL030.TagDetectSignal.Read();
                if ((tagdetectnew != tagdetectold) && tagdetectnew)     // vzestupna hrana
                {
                    lcd.Beep();
                    DataCard.Clear();
                    tagdetectold = tagdetectnew;
                    if (!CommonFunc.BLOCKING)
                    {
                        lcd.Print(0, 0, 2, 1, CommonFunc.StringFill(40, " Verifying card, wait please"));               // 40 znaku
                        Thread.Sleep(100);
                        if (!SL030.TagDetectSignal.Read())                  // je stale karta ?
                        {
                            DataCard.Id = SL030.SelectCard();               // nactu cislo karty
                            if (HttpSettings.ONLINE)
                            {
                                Hardware.Led_C.On();
                                HttpData.query = "sn=" + Settings.sn.ToString() + "&event=200" + "&card=" + DataCard.Id;
                                new Thread(HttpSettings.Connect).Start();
                                int loop = 0;
                                do
                                {
                                    Thread.Sleep(100);
                                    loop++;
                                } while (!HttpData.RESPONSE_OK && loop < HttpSettings.RequestTimeout);   // cekam max 3sec

                                CardList cd = new CardList();

                                if (DataCard.CARD_OK)
                                {
                                    if (HttpData.uniqueid != string.Empty)  // potvrdim uniquedid
                                    {
                                        HttpSettings.Acknowledgement();
                                    }
                                }
                                else
                                {
                                    if (cd.Contains(DataCard.Id))
                                    {
                                        DataCard.Role = CardRole.OfflineMode;
                                    }
                                }
                            }
                            // dale jen podle role
                            if (!SL030.TagDetectSignal.Read())                  // je stale karta ?
                            {
                                switch (DataCard.Role)
                                {
                                    case CardRole.None:
                                        if (HttpData.exception != String.Empty)
                                        {
                                            lcd.Print(0, 0, 2, 1, CommonFunc.StringFill(40, HttpData.exception));               // 40 znaku
                                            counter_1sec = 3; // nechm to tam viset 3sec
                                        }
                                        else
                                        {
                                            lcd.Print(0, 0, 2, 1, CommonFunc.StringFill(40, "Verification failed"));               // 40 znaku
                                            lcd.Print(0, 104, 2, 4, CommonFunc.StringFill(40, "          --------------------"));
                                            lcd.Print(0, 128, 2, 4, CommonFunc.StringFill(40, "         | VERIFICATION FAILED |"));
                                            lcd.Print(0, 152, 2, 4, CommonFunc.StringFill(40, "          --------------------"));
                                            counter_1sec = 5; // nechm to tam viset 5sec
                                        }
                                        lcd.Beep();
                                        flag = true;
                                        break;
                                    case CardRole.Credit:
                                    case CardRole.Debet:
                                        Bill.InvoiceNo = Bill.GetInvoiceNo();               // nactu cislo posledniho uctu
                                        Bill.Clear();                                       // novy listek
                                        Bill.BillHeaderAdd(DateTime.Now.ToString("dd/MM/yyyy   HH:mm:ss"));
                                        Bill.BillHeaderAdd("Bill no:      " + Bill.NoToString(Bill.InvoiceNo));
                                        Bill.BillHeaderAdd("Card ID      " + DataCard.Id);
                                        Bill.BillHeaderAdd("Credit   " + CommonFunc.StringPad(8, (Int32)DataCard.Credit, true) + " " + Settings.currency);
                                        Bill.BillLineAdd("---------------------");
                                        lcd.Screen = SCREEN.cardUser;
                                        // cislo uctu
                                        lcd.Print(305, 16, 1, 7, " Bill no:   " + Bill.NoToString(Bill.InvoiceNo));
                                        lcd.Print(285, 224, 1, 7, "-----------------------");
                                        LcdUpdateClient();                                  // jmeno a stav uctu
                                        break;
                                    case CardRole.ServiceBottle:
                                    case CardRole.Service:
                                    case CardRole.Cleaning:
                                    case CardRole.Master:
                                        lcd.Screen = SCREEN.mainMenu;
                                        break;
                                    case CardRole.OfflineMode:
                                        lcd.Screen = SCREEN.black;
                                        lcd.Print(154, 20, 3, 1, "OFFLINE MODE");
                                        lcd.Print(20, 74, 2, 1, "push left button on selected position");
                                        lcd.Print(20, 98, 2, 1, "           for dispensing");
                                        lcd.Print(12, 146, 2, 1, "push right button on selected position");
                                        lcd.Print(12, 178, 2, 1, "        for stop dispensing");
                                        break;
                                    default:
                                        DataCard.Role = CardRole.None;
                                        lcd.Screen = SCREEN.noCard;
                                        break;
                                }
                            }
                        }
                    }
                }
                /// sestupna hrana
                if ((tagdetectnew != tagdetectold) && !tagdetectnew)
                {
                    tagdetectold = tagdetectnew;
                    if ((DataCard.Role == CardRole.Credit || DataCard.Role == CardRole.Debet) && dispensed)
                    {
                        Bill.SaveBill(Bill.InvoiceNo, (CommonFunc.StringPad(8, Bill.Purchase, true) + " " + Settings.currency));
                        Bill.SaveInvoiceNo(Bill.InvoiceNo);
                    }

                    lcd.ClearBill();                                    // vymazu listek
                    DataCard.Clear();                                   // vymazu data karty !!!

                    dispensed = false;
                    StopAllVent();                                 // vypnu ventily :-) sichr
                    OFFLINEBOTTLE = 0;

                    poolTime = DateTime.Now.AddSeconds(5);              // po vytazeni karty az za 5 sec
                    VolumeInfo.GetVolumes()[0].FlushAll();              // ulozim vse na SD !!! nutne !!!

                    if (lcd.Screen != SCREEN.noCard) lcd.Screen = SCREEN.noCard;
                    lcd.PictureCut(1, 0, 0, 480, 48);
                    lcd.Beep();
                }
                // jako ze nic nedela
                //
                if (DataCard.Role == CardRole.Credit || DataCard.Role == CardRole.Debet)    // toto je vydej
                {
                    if ((FromButton.bottle > 0) && (FromButton.choice > Choice.none))
                    {
                        Dispensing(FromButton.bottle, FromButton.choice);
                    }
                }
                else if ((DataCard.Role == CardRole.OfflineMode))         // sanitace
                {
                    // spusteni 
                    if ((FromButton.bottle > 0) && (FromButton.choice > Choice.none))
                    {
                        if (FromButton.choice == Choice.small && OFFLINEBOTTLE == 0)             // zapnu
                        {
                            int b = FromButton.bottle;
                            OFFLINEBOTTLE = FromButton.bottle;
                            Thread.Sleep(10);
                            ButtonRS485.VentilsOnOff(b, true);
                        }
                        else if ((FromButton.choice == Choice.large) && (FromButton.bottle == OFFLINEBOTTLE))       // vypnu vzdy vse
                        {
                            int b = FromButton.bottle;
                            Thread.Sleep(10);
                            OFFLINEBOTTLE = 0;
                            ButtonRS485.VentilsOnOff(b, false);
                        }
                        Thread.Sleep(10);
                        FromButton.Clear();
                    }
                }
                else if (DataCard.Role == CardRole.None)
                {
                    if (DateTime.Now > startTime)    // 1sec
                    {
                        startTime = DateTime.Now.AddSeconds(1);
                        if (counter_1sec > 0) counter_1sec--;
                        if (!flag)
                        {
                            //if (!HttpSettings.ONLINE) lcd.Print(0, 0, 2, 1, " Loss of HttpSettings.Connection, device is blocked  ");
                            //else lcd.PictureCut(1, 0, 0, 480, 48);

                            if (CommonFunc.BLOCKING == true) lcd.Print(100, 190, 4, 41, " ! blocked !");
                            else lcd.PictureCut(1, 100, 190, 370, 240);
                            string statusNet = (HttpSettings.ONLINE) ? "On line  " : "Off line ";
                            string statusLine = (" " + DateTime.Now.ToString(" dd.MM.yyyy HH:mm:ss") + "  sn: " + Settings.sn + "  fw: v" + Settings.ver);
                            PrintStatusLine(statusLine, statusNet);
                        }
                    }
                    else if ((FromButton.bottle > 0) && (FromButton.choice > Choice.none))
                    {
                        counter_1sec = 5;
                        flag = true;
                        PrintPrice(FromButton.bottle, FromButton.choice);           // vypise cenu
                        lcd.Beep();
                        Thread.Sleep(100);
                        FromButton.Clear();
                    }
                    else
                    {
                        if ((counter_1sec < 1) && (flag))
                        {
                            flag = false;
                            lcd.Screen = SCREEN.noCard;
                            string statusNet = (HttpSettings.ONLINE) ? "On line  " : "Off line ";
                            string statusLine = (" " + DateTime.Now.ToString(" dd.MM.yyyy HH:mm:ss") + "  sn: " + Settings.sn + "  fw: v" + Settings.ver);
                            PrintStatusLine(statusLine, statusNet);
                        }
                    }
                    // Cyklický dotaz na změny
                    if (DateTime.Now > poolTime)    // dotaz na zmneny po 1 min
                    {
                        HttpSettings.HeartBeat();

                        poolTime = DateTime.Now.AddSeconds(Settings.POOL);
                    }
                }
                else if ((DataCard.Role >= CardRole.ServiceBottle) && (lcd.Screen == SCREEN.mainMenu))    // odcvrknuti
                {
                    if ((FromButton.bottle > 0) && (FromButton.choice == Choice.small))
                    {
                        int time = 40;                                      // asi 0,002
                        DateTime wait = DateTime.Now.AddMilliseconds((time * 10) + 200);
                        ButtonRS485.VentilsOnTime(FromButton.bottle, time);
                        while (DateTime.Now < wait) ;                     // a cekam :-)
                        FromButton.Clear();
                    }

                }
                else if ((DataCard.Role >= CardRole.ServiceBottle) && (lcd.Screen == SCREEN.set4Number))    // kalibrace
                {
                    // spusteni davky 10 sec
                    if ((FromButton.bottle > 0) && (FromButton.bottle == Menu.selectedBottle) && (FromButton.choice > Choice.none))
                    {
                        DateTime wait = DateTime.Now.AddMilliseconds(CommonFunc.calibrationTime + 200);
                        int time = CommonFunc.calibrationTime / 10;
                        ButtonRS485.VentilsOnTime(FromButton.bottle, time);
                        do
                        {
                            Thread.Sleep(100);
                        }
                        while (DateTime.Now < wait && !SL030.TagDetectSignal.Read());                    
                        FromButton.Clear();
                    }
                }
                else if ((DataCard.Role >= CardRole.ServiceBottle) && (lcd.Screen == SCREEN.clearing))         // sanitace
                {
                    // spusteni 
                    if ((FromButton.bottle > 0) && (FromButton.choice > Choice.none))
                    {
                        if (FromButton.choice == Choice.small)              // zapnu
                        {
                            int b = FromButton.bottle;
                            ButtonRS485.VentilsOnOff(b, true);
                        }
                        else if (FromButton.choice == Choice.large)         // vypnu vzdy vse
                        {
                            int b = FromButton.bottle;
                            ButtonRS485.VentilsOnOff(b, false);
                        }
                        FromButton.Clear();
                    }
                }

                // z touch panelu
                if (lcd.touchKey > 0)
                {
                    ProcesingKey((KEY)lcd.touchKey);
                    lcd.touchKey = 0;
                }
            }  // end While
        }
Esempio n. 2
0
        public static void ct_ConnectionSuccess(object sender, NetSuccessEventArgs e)
        {
            if (e.NetStatus == netStatus.Success)
            {
                CommonFunc.DebugPrint("<- " + e.Answers);
                string[] rowparam = e.Answers.Split('|');
                for (int i = 0; i < rowparam.Length; i++)
                {
                    Param[] param = DecryptParam.Decrypt(rowparam[i]);
                    try
                    {
                        while (!DecryptParam.Parse(param)) ;
                    }
                    catch (Exception ex)
                    {
                        CommonFunc.DebugPrint(ex.ToString());
                    }

                    if (INIT && HttpData.confirmed != String.Empty)
                    {
                        break;
                    }

                    switch (HttpData.events)
                    {
                        case 100:
                            READ_SETTINGS = false;
                            if (HttpData.result == "ok")
                            {
                                Settings.Write();
                                Settings.Read();
                                if (Settings.isClosed == 0) CommonFunc.BLOCKING = false;
                                else CommonFunc.BLOCKING = true;
                                READ_SETTINGS = true;
                            }
                            break;
                        case 101:
                            CHANGEBOTTLE_OK = false;
                            if (HttpData.result == "ok")
                            {
                                if (BottleData.position > 0 && BottleData.position <= Settings.buttonNumber)
                                {
                                    BottleData.Write(BottleData.position);      // a ulozim vzdy
                                    CHANGEBOTTLE_OK = true;
                                }
                                BottleData.position = 0;                    // musim vymazat
                            }
                            break;
                        case 200:
                            DataCard.CARD_OK = false;
                            if (HttpData.result == "ok")
                            {
                                if (HttpData.card == DataCard.Id)
                                {
                                    if (DataCard.Role >= CardRole.ServiceBottle)
                                    {
                                        CardList cd = new CardList();

                                        if (cd.Contains(DataCard.Id) && DataCard.Validity == 0)
                                        {
                                            cd.Remove(DataCard.Id);
                                        }
                                        else if (!cd.Contains(DataCard.Id) && DataCard.Validity == 1)
                                        {
                                            cd.Add(DataCard.Id);
                                        }
                                    }

                                    if (!SL030.TagDetectSignal.Read()) DataCard.CARD_OK = true;
                                    else DataCard.Clear();
                                }
                            }
                            break;
                        case 201:
                            ENABLE_DISPENSING = false;
                            if (DataCard.Role == CardRole.Credit || DataCard.Role == CardRole.Debet)
                            {
                                if (HttpData.result == "ok")
                                {
                                    if (HttpData.dosevolume > 5)
                                        ENABLE_DISPENSING = true;
                                }
                            }
                            break;
                        default: break;
                    }
                } // end for

                HttpData.RESPONSE_OK = true;
            }
            else if (e.NetStatus == netStatus.Timeout)
            {
                CommonFunc.DebugPrint("TIMEOUT : " + DateTime.Now.ToString("HH:mm:ss fff"));
            }
            else if (e.NetStatus == netStatus.Failure)
            {
                CommonFunc.DebugPrint("FAILED : " + DateTime.Now.ToString("HH:mm:ss fff"));
            }
            Hardware.Led_C.Off();
        }