Exemplo n.º 1
0
        //读卡
        public CardInfo ReadCard()
        {
            Log.Debug("ReadCard start");
            CardInfo ret = new CardInfo();

            try
            {
                //检查卡的初始状态
                int result = MingHua.CheckCard(Port, Baud);
                //有错误,显示错误内容,不是新卡不当做错误
                if (result != 0 && result != -15)
                {
                    //获取错误代码
                    ret.Err = Errors[-result - 1];
                    return(ret);
                }

                if (Cards == null)
                {
                    throw new Exception("Cards is null");
                }
                //循环调用所有厂家的
                foreach (CardConfig info in Cards)
                {
                    ICard card = info.Card;
                    //如果不是本厂家的,看下一个
                    int r = card.CheckGasCard(Port, Baud);
                    Log.Debug("check " + info.Name + " is " + r);
                    if (r != 0)
                    {
                        continue;
                    }
                    //读卡
                    string  kh    = "";
                    Int32   ql    = 0;
                    decimal money = 0;
                    Int16   cs    = 0;
                    Int16   bkcs  = 0;
                    r = card.ReadGasCard(Port, Baud, ref kh, ref ql, ref money, ref cs, ref bkcs);
                    if (r < 0)
                    {
                        //获取错误代码
                        ret.Err = Errors[-r - 1];
                    }
                    else
                    {
                        //返回读取结果
                        ret.Factory    = info.Name;
                        ret.CardID     = kh;
                        ret.Gas        = ql;
                        ret.Money      = money;
                        ret.Times      = cs;
                        ret.RenewTimes = bkcs;
                    }
                    return(ret);
                }
                //一个都没有找到
                ret.Err = "未知厂家";
                return(ret);
            }
            catch (Exception e)
            {
                Log.Debug("ReadCard exception");
                ret.Exception = e.Message;
                return(ret);
            }
        }
Exemplo n.º 2
0
        //读卡
        public CardInfo ReadCard()
        {
            Log.Debug("ReadGasCard()=()");
            CardInfo ret = new CardInfo();

            try
            {
                ////检查卡的初始状态
                //int result = MingHua.CheckCard(Port, Baud);
                ////有错误,显示错误内容,不是新卡不当做错误
                //if (result != 0 && result != -15)
                //{
                //    //获取错误代码
                //    if (result <= -20)
                //    {
                //        ret.Err = GetCardSpecificError(null, result);
                //    }
                //    else
                //    {
                //        ret.Err = Errors[-result - 1];
                //    }
                //    Log.Debug("ReadGasCard()=" + result);
                //    return ret;
                //}

                //循环调用所有厂家的
                foreach (CardConfig info in Cards)
                {
                    ICard card = info.Card;
                    //如果不是本厂家的,看下一个
                    int r = card.CheckGasCard(Port, Baud);
                    Log.Debug("check " + info.Name + " is " + r);
                    if (r != 0)
                    {
                        continue;
                    }
                    //读卡
                    string  kh    = "";
                    string  yhh   = "";
                    Int32   ql    = 0;
                    decimal money = 0;
                    Int16   cs    = 0;
                    Int16   bkcs  = 0;
                    r = card.ReadGasCard(Port, Baud, ref kh, ref ql, ref money, ref cs, ref bkcs, ref yhh);
                    Log.Debug("用户号:" + yhh);
                    if (r < 0)
                    {
                        if (r <= -19)
                        {
                            ret.Err = GetCardSpecificError(card, r);
                        }
                        else
                        {
                            ret.Err = Errors[-r - 1];
                        }
                    }
                    else
                    {
                        //返回读取结果
                        ret.Factory    = info.Name;
                        ret.CardID     = kh;
                        ret.Gas        = ql;
                        ret.Money      = money;
                        ret.Times      = cs;
                        ret.RenewTimes = bkcs;
                        ret.Yhh        = yhh;
                    }
                    Log.Debug("ReadGasCard()=" + r);
                    return(ret);
                }
                Log.Debug("ReadGasCard()=未知厂家");
                //一个都没有找到
                ret.Err = "未知厂家";
                return(ret);
            }
            catch (Exception e)
            {
                Log.Debug("ReadGasCard()=" + e.Message);
                ret.Exception = e.Message;
                return(ret);
            }
        }