示例#1
0
        void readCardWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            ReadCardParam param = (ReadCardParam)e.Argument;
            string        card  = string.Empty;

            while (true)
            {
                card = readCardValueFromFile(param.cardFile);
                string msg = " {0}. Retry in {1} seconds...";
                if (string.IsNullOrEmpty(card))
                {
                    msg = "Cannot read value from card" + msg;
                }
                else if (card == "NC")
                {
                    msg = "No card detected for" + msg;
                }
                else
                {
                    break;
                }
                print(string.Format(msg, param.cardName, conf.dCardRead / 1000));
                System.Threading.Thread.Sleep(conf.dCardRead);
            }
            param.cardValue = card;
            e.Result        = param;
        }
示例#2
0
        void readCard(string cardName, string cardFile, AsyncCallDelegate callback)
        {
            ReadCardParam param = new ReadCardParam();

            param.cardName = cardName;
            param.cardFile = cardFile;
            param.callback = callback;
            readCardWorker.RunWorkerAsync(param);
        }
示例#3
0
        void readCardWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            ReadCardParam param = (ReadCardParam)e.Result;

            switch (param.cardName)
            {
            case "P1":
                print("Player card 1: " + param.cardValue);
                lblP1.Text            = cardP1 = param.cardValue;
                picP1.BackgroundImage = Image.FromFile(conf.imgP1);
                _iPCard1 = getCardValue(param.cardValue.Substring(1));
                _iPTotal = (_iPTotal + _iPCard1) % 10;
                break;

            case "P2":
                print("Player card 2: " + param.cardValue);
                lblP2.Text            = cardP2 = param.cardValue;
                picP2.BackgroundImage = Image.FromFile(conf.imgP2);
                _iPCard2 = getCardValue(param.cardValue.Substring(1));
                _iPTotal = (_iPTotal + _iPCard2) % 10;
                break;

            case "P3":
                print("Player card 3: " + param.cardValue);
                lblP3.Text            = cardP3 = param.cardValue;
                picP3.BackgroundImage = Image.FromFile(conf.imgP3);
                _iPCard3 = getCardValue(param.cardValue.Substring(1));
                _iPTotal = (_iPTotal + _iPCard3) % 10;
                break;

            case "B1":
                print("Banker card 1: " + param.cardValue);
                lblB1.Text            = cardB1 = param.cardValue;
                picB1.BackgroundImage = Image.FromFile(conf.imgB1);
                _iBCard1 = getCardValue(param.cardValue.Substring(1));
                _iBTotal = (_iBTotal + _iBCard1) % 10;
                break;

            case "B2":
                print("Banker card 2: " + param.cardValue);
                lblB2.Text            = cardB2 = param.cardValue;
                picB2.BackgroundImage = Image.FromFile(conf.imgB2);
                _iBCard2 = getCardValue(param.cardValue.Substring(1));
                _iBTotal = (_iBTotal + _iBCard2) % 10;
                break;

            case "B3":
                print("Banker card 3: " + param.cardValue);
                lblB3.Text            = cardB3 = param.cardValue;
                picB3.BackgroundImage = Image.FromFile(conf.imgB3);
                _iBCard3 = getCardValue(param.cardValue.Substring(1));
                _iBTotal = (_iBTotal + _iBCard3) % 10;
                break;

            default: break;
            }
            if (param.callback != null)
            {
                param.callback(param);
            }
        }