Ejemplo n.º 1
0
 public CardInfo ReadCard()
 {
     String args = "ReadCard";
     Log.Debug(args + " started.");
     String result = null;
     CardInfo ci = new CardInfo();
     try
     {
         if (this.Spawn(args, out result))
         {
             ci = JsonConvert.DeserializeObject<CardInfo>(result);
             Log.Debug(args + "=" + result);
         }
         else
         {
             ci.Err = "调用未返回。";
             Log.Debug(args + "=" + ci.Err);
         }
     }
     catch(Exception e)
     {
         ci.Exception = e.Message;
         ci.Err = "调用错误。";
     }
     return ci;
 }
        //读卡
        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;
            }
        }
Ejemplo n.º 3
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);
            }
        }