Example #1
0
        public static string Init(string cardcom, string cashIncom, string coinIncom, string cashOutcom, string coin1Outcom, string coin5Outcom)
        {
            if (bInit)
            {
                return("");
            }

            var sb   = new StringBuilder();
            var msg  = "";
            var open = false;

            IsOpenCassetteAndRead = false;
            try
            {
                //读卡器初始化
                cardCom = new SerialComIC(cardcom);
                cardCom.OnReadCardNo += (s, c) =>
                {
                    if (OnReadCardNo != null)
                    {
                        OnReadCardNo(s, c);
                    }
                };

                //纸币入
                cashInCom = new CashReceiver(cashIncom);
                open      = cashInCom.Open(out msg);
                if (!open)
                {
                    sb.Append(msg);
                }
                cashInCom.OnAcceptMoney += cashInCom_OnAcceptMoney;

                //硬币入
                var con = new ConnectionRs232
                {
                    PortName   = coinIncom,
                    RemoveEcho = true
                };
                Dictionary <byte, CoinTypeInfo> coins;
                coins         = CoinAcceptor.DefaultConfig;
                coinAcceptor3 = new CoinAcceptor(02, con, coins, null);
                coinAcceptor3.CoinAccepted         += CoinAcceptorCoinAccepted;
                coinAcceptor3.ErrorMessageAccepted += CoinAcceptorErrorMessageAccepted;
                coinAcceptor3.Init();

                //纸币出
                cashOutCom = new SerialCom(cashOutcom);
                if (cashOutCom.Open(out msg) == false)
                {
                    sb.Append(msg);
                }
                StatusCode.Init();
                constrant = new Constrant(cashOutCom);

                //硬币找零
                coin1Com = new CoinCharge(coin1Outcom, ChargeMoneyType.M1, false);
                coin5Com = new CoinCharge(coin5Outcom, ChargeMoneyType.M5, false);

                if (coin1Com.Open(out msg) == false)
                {
                    sb.Append(COIN1_COM_OPEN_ERROR);
                }
                Log.Out("1 yuan OK");
                if (coin5Com.Open(out msg) == false)
                {
                    sb.Append(COIN5_COM_OPEN_ERROR);
                }
                Log.Out("5 yuan OK");
                bInit = true;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            return(msg);
        }