Example #1
0
        public int WriteNewCard(short com, int baud, ref string kmm, short kzt, string kh, string dqdm, string yhh, string tm, int ql, int csql, int ccsql, short cs, int ljgql, short bkcs, int ljyql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj)
        {
            //清卡,新卡,卡上有内容
            MingHua.ClearCard(com, baud);
            //用户卡清卡
            StaticNewCard(com, baud);

            //卡号
            byte[] cardno = System.Text.Encoding.GetEncoding(1252).GetBytes(kh);

            int result;

            //发卡
            if (kzt == 0)
            {
                //调用发卡
                result = StaticInitCard(com, baud,
                                        cardno, ql, 0, cs,
                                        1, //初始化卡类型(1:发卡;3:补购气卡;0:补用户卡)
                                        2, //表型(1:一体表;2 ; 分体表 ,3:工业表)
                                        null);
            }
            else
            {
                //调用补卡
                result = StaticInitCard(com, baud,
                                        cardno, ql, 0, cs,
                                        2, //初始化卡类型(1:发卡;2:补购气卡;0:补用户卡)
                                        2, //表型(1:一体表;2 ; 分体表 ,3:工业表)
                                        null);
                Log.Debug("补卡结果:" + result);
            }
            Log.Debug("write new card end ret=" + result);
            return(result);
        }
Example #2
0
        public int WriteNewCard(short com, int baud, ref string kmm, short kzt, string kh, string dqdm, string yhh, string tm, int ql, int csql, int ccsql, short cs, int ljgql, short bkcs, int ljyql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj)
        {
            //清卡,新卡,卡上有内容
            MingHua.ClearCard(com, baud);

            HtDll.HTDL card = new HtDll.HTDL();
            //用户卡清卡
            card.ClearCard(com, baud);

            int result;

            //发卡
            if (kzt == 0)
            {
                //调用发卡
                result = card.NewCard(com, baud, 1, ql, kh, bjql);
            }
            else
            {
                //调用补卡
                result = card.CardInit(com, baud, 1, ql, kh, bjql, 5, "20131008", 0, cs);
            }
            Log.Debug("write card end ret=" + result);
            return(result);
        }
Example #3
0
        public int CheckGasCard(short com, int baud)
        {
            int ret = StaticCheckGasCard(com, baud);

            if (ret != 0)
            {
                return(ret);
            }
            //通过读卡看是否4442卡
            ret = MingHua.Is4442(com, baud);
            return(ret);
        }
Example #4
0
        //格式化卡函数
        public unsafe int FormatGasCard(short com, int baud, string kmm, string kh, string dqdm)
        {
            int rs = -1;

            try
            {
                PLtCardReader pcr1 = new PLtCardReader()
                {
                    dwDevType = 2,
                    dwPort    = com,
                    dwBaud    = baud,
                    dv_beep   = 0
                };

                PUserCard puc1 = new PUserCard();
                int       pti  = 0;
                //string kh1 = new string((sbyte*)puc1.CardNO);
                //string dqdm1 = new string((sbyte*)puc1.UserNO);

                Log.Debug("LanBaoShi FormatGasCard start;端口号:" + pcr1.dwPort + "波特率:" + pcr1.dwBaud);

                String buf;
                String buf1;
                Log.Debug("擦卡前读卡格式:");
                MingHua.GetSnapShot(com, baud, out buf);
                rs = RecycleUserCard(ref pcr1, ref puc1, pti);
                Log.Debug("擦卡后读卡格式:");
                MingHua.GetSnapShot(com, baud, out buf1);
                Log.Debug(buf);
                Log.Debug(buf1);

                //kh1 = new string((sbyte*)puc1.CardNO);
                //dqdm1 = new string((sbyte*)puc1.UserNO);
                Log.Debug("LanBaoShi FormatGasCard end,返回值return:" + rs);
                if (rs == 0)
                {
                    Log.Debug("蓝宝石擦卡成功!");
                    return(0);
                }
                else
                {
                    Log.Debug("蓝宝石擦卡失败!");
                    return(-1);
                }
            }
            catch (Exception e)
            {
                Log.Debug("蓝宝石擦卡异常:" + e.Message + "--" + e.StackTrace);
            }
            return(rs);
        }
Example #5
0
        /// <summary>
        /// 售气写卡
        /// </summary>
        /// <param name="com">串口号,0代表串口1</param>
        /// <param name="baut">波特率</param>
        /// <param name="kmm">卡密码</param>
        /// <param name="kh">卡号</param>
        /// <param name="dqdm">地区代码</param>
        /// <param name="ql">气量,小于或等于0,表示退气,大于0表示购气。</param>
        /// <param name="csql">上次气量</param>
        /// <param name="ccsql">上上次气量</param>
        /// <param name="cs">次数</param>
        /// <param name="ljgql">累购气量</param>
        /// <param name="bjql">报警气量</param>
        /// <param name="czsx">充值上限</param>
        /// <param name="tzed">透支额度</param>
        /// <param name="sqrq">售气日期</param>
        /// <param name="cssqrq">上次售气日期</param>
        /// <param name="oldprice">老价格</param>
        /// <param name="newprice">新价格</param>
        /// <param name="sxrq">售气日期</param>
        /// <param name="sxbj">生效标记</param>
        /// <returns>成功:0,失败:非0</returns>
        public int WriteGasCard(short com, int baud, ref string kmm, string kh, string dqdm, int ql, int csql, int ccsql, short cs, int ljgql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj)
        {
            String buf;

            Log.Debug("买气前读卡格式:");
            MingHua.GetSnapShot(com, baud, out buf);

            byte[] cardNo = System.Text.Encoding.GetEncoding(1252).GetBytes(kh);

            Int32 syql        = 0; //当前表剩余气量
            Int32 klx         = 0; //卡类型
            Int32 orderamount = 0;
            Int32 orderNum    = 0;

            byte[] cardid    = new byte[20];
            byte[] customeid = new byte[20];
            Log.Debug("WriteGasCard(short com, int baud, ref string kmm, string kh, string dqdm, int ql, int csql, int ccsql, short cs, int ljgql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj)=("
                      + com + "," + baud + "," + kmm + "," + kh
                      + dqdm + "," + ql + "," + csql + "," + ccsql
                      + cs + "," + ljgql + "," + bjql + "," + czsx
                      + tzed + "," + sqrq + "," + cssqrq + "," + oldprice
                      + newprice + "," + sxrq + "," + sxbj
                      + ")");
            int readresult = ReadGasCard(com, cardid, customeid, ref orderamount, ref orderNum, ref ljgql, ref syql, ref klx);

            Log.Debug("WriteGasCard(short com, int baud, ref string kmm, string kh, string dqdm, int ql, int csql, int ccsql, short cs, int ljgql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj)=("
                      + com + "," + baud + "," + kmm + "," + kh
                      + dqdm + "," + ql + "," + csql + "," + ccsql
                      + cs + "," + ljgql + "," + bjql + "," + czsx
                      + tzed + "," + sqrq + "," + cssqrq + "," + oldprice
                      + newprice + "," + sxrq + "," + sxbj
                      + ")=" + readresult);
            byte[] customeNo = customeid;
            string khq       = Encoding.ASCII.GetString(cardNo, 0, 8);
            string yhhq      = Encoding.ASCII.GetString(customeNo, 0, 10);

            Log.Debug("sell gas start:" + "kh:" + khq + "--yhh:" + yhhq + "--cs:" + cs + "--ql:" + ql);
            int result = StaticWriteGasCard(com, cardNo, customeNo, cs, ql);

            Log.Debug("write gas card result=" + result);
            Log.Debug("买气后读卡格式:");
            String buf2;

            MingHua.GetSnapShot(com, baud, out buf2);
            Log.Debug(buf);
            Log.Debug(buf2);
            return(result);
        }
Example #6
0
 public int CheckGasCard(short com, int baud)
 {
     try
     {
         int ret = StaticCheckGasCard(com, baud);
         if (ret != 0)
         {
             return(ret);
         }
         //通过读卡看是否4442卡
         ret = MingHua.Is4442(com, baud);
         return(ret);
     }catch (Exception e)
     {
         Log.Debug(e.Message);
     }
     return(-1);
 }
Example #7
0
        public int CheckGasCard(short com, int baud)
        {
            byte[] data_buffer = new byte[300];
            //for (int i = 0; i < 200;i++ )
            // {
            //    data_buffer[i] = byte.Parse(i.ToString(), NumberStyles.HexNumber);
            // }
            //srdCard_ver(256, data_buffer);
            MingHua.ic_init(com, baud);
            srd_4442(9600, 0, 256, data_buffer);
            string s = ToHexString(data_buffer);

            Log.Debug("我是data_buffer:" + data_buffer[0] + "" + data_buffer[1] + "" + data_buffer[2]);
            writeFile(s);
            //打日志
            Log.Debug("------------------------------------------------" + s + "+++++++++++++++++++++++++++++");
            return(0);
        }
Example #8
0
        public int WriteGasCard(short com, int baud, ref string kmm, string kh, string dqdm, int ql, int csql, int ccsql, short cs, int ljgql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj, string result)
        {
            //byte[] data_buffer = new byte[256];
            //data_buffer[0] = 20;
            //srdCard_ver(256, data_buffer);
            //Log.Debug("result: " + result);
            //swr_4442(9600, 95, 1, data_buffer);

            String buf;

            Log.Debug("买气前读卡格式:");
            MingHua.GetSnapShot(com, baud, out buf);

            byte[] cardNo = System.Text.Encoding.GetEncoding(1252).GetBytes(kh);

            Int32 syql        = 0; //当前表剩余气量
            Int32 klx         = 0; //卡类型
            Int32 orderamount = 0;
            Int32 orderNum    = 0;

            byte[] cardid    = new byte[20];
            byte[] customeid = new byte[20];
            Log.Debug("read keluomu card start!");
            int readresult = ReadGasCard(com, cardid, customeid, ref orderamount, ref orderNum, ref ljgql, ref syql, ref klx);

            Log.Debug("read keluomu card end!" + readresult);
            byte[] customeNo = customeid;
            string khq       = Encoding.ASCII.GetString(cardNo, 0, 8);
            string yhhq      = Encoding.ASCII.GetString(customeNo, 0, 10);

            Log.Debug("sell gas start:" + "kh:" + khq + "--yhh:" + yhhq + "--cs:" + cs + "--ql:" + ql);
            int results = StaticWriteGasCard(com, cardNo, customeNo, cs, ql);

            Log.Debug("write gas card result=" + results);
            Log.Debug("买气后读卡格式:");
            String buf2;

            MingHua.GetSnapShot(com, baud, out buf2);
            Log.Debug(buf);
            Log.Debug(buf2);
            results = ChangeResult(results);
            return(results);
            //   return 0;
        }
Example #9
0
        public int WriteNewCard(short com, int baud, ref string kmm, short kzt, string kh, string dqdm, string yhh, string tm, int ql, int csql, int ccsql, short cs, int ljgql, short bkcs, int ljyql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj, string result1)
        {
            byte[] cardNo      = System.Text.Encoding.GetEncoding(1252).GetBytes(kh);
            byte[] yh          = System.Text.Encoding.GetEncoding(1252).GetBytes(yhh);
            byte[] cardid      = new byte[20];
            byte[] customeid   = new byte[20];
            Int32  syql        = 0; //当前表剩余气量
            Int32  klx         = 0; //卡类型
            Int32  orderamount = 0;
            Int32  orderNum    = 0;
            int    result      = -1;

            Log.Debug("clear keluomu card start, is:!" + yhh);
////
            int readresult = ReadGasCard(com, cardid, customeid, ref orderamount, ref orderNum, ref ljgql, ref syql, ref klx);

            Log.Debug("read keluomu card end!" + readresult);

            int clearresult = StaticFormatGasCard(com, yh);

            Log.Debug("clead keluomu card end!" + clearresult);
            if (0 == kzt)
            {
                Log.Debug("make new card start:com:" + com + "--cardno:" + kh + "--yhh:" + yhh + "--ql:" + ql);
                result = MakeGasCard(com, cardNo, yh, 1, ql);
                Log.Debug("make new keluomu card end!" + result);
            }
            else if (1 == kzt)
            {
                Log.Debug("repair new card start:com:" + com + "--cardno:" + kh + "--yhh:" + yhh + "--cs" + cs + "--ql:" + ql);
                result = MakeGasCard(com, cardNo, yh, cs, ql);
                Log.Debug("repair keluomu card end!" + result);
            }

            String buf;

            Log.Debug("发卡后读卡格式:");
            MingHua.GetSnapShot(com, baud, out buf);
            Log.Debug(buf);
            result = ChangeResult(result);
            return(result);
        }
Example #10
0
        public unsafe int WriteNewCard(short com, int baud, ref string kmm, short kzt, string kh, string dqdm, string yhh, string tm, int ql, int csql, int ccsql, short cs, int ljgql, short bkcs, int ljyql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj)
        {
            int rs = -1;

            try
            {
                PLtCardReader pcr1 = new PLtCardReader()
                {
                    dwDevType = 2,
                    dwPort    = com,
                    dwBaud    = baud,
                    dv_beep   = 0
                };
                PLtMeterStruct pms1 = new PLtMeterStruct()
                {
                    cbSize                   = 0,
                    WriteBack                = 0,
                    TotalAmount              = 0,
                    TotalMoney               = 0,
                    RemainAmount             = 0,
                    RemainMoney              = 0,
                    RechargeTimes            = 0,
                    OverflowTimes            = 0,
                    MagnetismInterferedTimes = 0,
                    Valve   = 0,
                    Battery = 0
                };

                PAdvancedSettingsStruct past = new PAdvancedSettingsStruct()
                {
                    cbSize                 = 0,
                    WarnAmount             = 10,
                    WarnMoney              = 0,
                    AllowedOverdraftAmount = 0,
                    AllowedOverdraftMoney  = 0,
                    ValveOffOnIdle         = 0,
                    ValveOffOnLowPower     = 0,
                    ValveOffOnWarning      = 0
                };

                PUserCard puc1 = new PUserCard()
                {
                    cbSize         = 0,
                    RechargeTimes  = cs,
                    RechargeAmount = ql * 10000,
                    RechargeMoney  = 0,
                    MecMeterType   = 1
                };
                FillBytes(puc1.CardNO, kh);
                FillBytes(puc1.UserNO, dqdm);
                //写卡之前先格式化卡
                Log.Debug("write card ql=" + ql + ",kagas=" + puc1.RechargeAmount);
                int pti = 0;
                rs = RecycleUserCard(ref pcr1, ref puc1, pti);
                Log.Debug("clear card rs=" + rs);
                Log.Debug("LanBaiShiGY WriteNewCard start"); String buf;
                String buf1;
                Log.Debug("发卡前读卡格式:");
                MingHua.GetSnapShot(com, baud, out buf);
                rs = IssueUserCard(ref pcr1, ref puc1, pti);
                Log.Debug("发卡后读卡格式:");
                MingHua.GetSnapShot(com, baud, out buf1);
                Log.Debug(buf);
                Log.Debug(buf1);
                Log.Debug("LanBaiShiGY WriteNewCard end, return:" + rs);
                if (rs == 0)
                {
                    Log.Debug("蓝宝石工业卡写新卡成功!");
                    return(0);
                }
                else
                {
                    Log.Debug("蓝宝石工业卡写新卡失败!");
                    return(-1);
                }
            }
            catch (Exception e)
            {
                Log.Debug("蓝宝石工业写新卡异常:" + e.Message + "--" + e.StackTrace);
            }
            return(rs);
        }
Example #11
0
        public unsafe int WriteGasCard(short com, int baud, ref string kmm, string kh, string dqdm, int ql, int csql, int ccsql, short cs, int ljgql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj)
        {
            int rs = -1;

            try
            {
                PLtCardReader pcr1 = new PLtCardReader()
                {
                    dwDevType = 2,
                    dwPort    = com,
                    dwBaud    = baud,
                    dv_beep   = 0
                };
                PLtMeterStruct pms1 = new PLtMeterStruct()
                {
                    cbSize                   = 0,
                    WriteBack                = 0,
                    TotalAmount              = 0,
                    TotalMoney               = 0,
                    RemainAmount             = 0,
                    RemainMoney              = 0,
                    RechargeTimes            = 0,
                    OverflowTimes            = 0,
                    MagnetismInterferedTimes = 0,
                    Valve   = 0,
                    Battery = 0
                };

                PAdvancedSettingsStruct past = new PAdvancedSettingsStruct()
                {
                    cbSize                 = 0,
                    WarnAmount             = 10,
                    WarnMoney              = 0,
                    AllowedOverdraftAmount = 0,
                    AllowedOverdraftMoney  = 0,
                    ValveOffOnIdle         = 0,
                    ValveOffOnLowPower     = 0,
                    ValveOffOnWarning      = 0
                };

                PUserCard puc1 = new PUserCard()
                {
                    cbSize        = 0,
                    RechargeTimes = cs,
                    RechargeMoney = 0,
                    MecMeterType  = 1
                };
                FillBytes(puc1.CardNO, kh);
                FillBytes(puc1.UserNO, dqdm);

                int pti = 0;
                if (ql != 0)
                {
                    puc1.RechargeAmount = ql * 10000;
                    String buf;
                    String buf1;
                    Log.Debug("购气前读卡格式:");
                    MingHua.GetSnapShot(com, baud, out buf);
                    rs = RechargeUserCard(ref pcr1, ref puc1, pti);
                    Log.Debug("购气后读卡格式:");
                    MingHua.GetSnapShot(com, baud, out buf1);
                    Log.Debug(buf);
                    Log.Debug(buf1);
                    if (rs == 0)
                    {
                        Log.Debug("蓝宝石工业购气成功!");
                        return(0);
                    }
                    else
                    {
                        Log.Debug("蓝宝石工业购气失败!");
                        return(-1);
                    }
                }
                else
                {
                    int rt  = ReadUserCard(ref pcr1, ref puc1, pti);
                    int gas = (int)puc1.RechargeAmount;
                    puc1.RechargeAmount = -gas;
                    String buf;
                    String buf1;
                    Log.Debug("退气前读卡格式:");
                    MingHua.GetSnapShot(com, baud, out buf);
                    rs = RechargeUserCard(ref pcr1, ref puc1, pti);
                    Log.Debug("退气后读卡格式:");
                    MingHua.GetSnapShot(com, baud, out buf1);
                    Log.Debug(buf);
                    Log.Debug(buf1);
                    if (rs == 0)
                    {
                        Log.Debug("蓝宝石工业冲正成功!");
                        return(0);
                    }
                    else
                    {
                        Log.Debug("蓝宝石工业冲正失败!");
                        return(-1);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Debug("蓝宝石工业购气卡异常:" + e.Message + "--" + e.StackTrace);
            }
            return(rs);
        }
Example #12
0
        /// <summary>
        /// 写新卡
        /// </summary>
        /// <param name="com">串口号,0代表串口1</param>
        /// <param name="baut">波特率</param>
        /// <param name="kmm">卡密码</param>
        /// <param name="kzt">卡状态</param>
        /// <param name="kh">卡号</param>
        /// <param name="dqdm">地区代码</param>
        /// <param name="yhh">用户号</param>
        /// <param name="tm">条码</param>
        /// <param name="ql">气量</param>
        /// <param name="csql">上次气量</param>
        /// <param name="ccsql">上上次气量</param>
        /// <param name="cs">次数</param>
        /// <param name="ljgql">累购气量</param>
        /// <param name="bkcs">补卡次数</param>
        /// <param name="ljyql">累计用气量</param>
        /// <param name="bjql">报警气量</param>
        /// <param name="czsx">充值上限</param>
        /// <param name="tzed">透支额度</param>
        /// <param name="sqrq">售气日期</param>
        /// <param name="cssqrq">上次售气日期</param>
        /// <param name="oldprice">老价格</param>
        /// <param name="newprice">新价格</param>
        /// <param name="sxrq">生效日期</param>
        /// <param name="sxbj">生效标记</param>
        /// <returns>成功:0,失败:非0</returns>
        public int WriteNewCard(short com, int baud, ref string kmm, short kzt, string kh, string dqdm, string yhh, string tm, int ql, int csql, int ccsql, short cs, int ljgql, short bkcs, int ljyql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj, int klx, string meterid)
        {
            Log.Debug("WriteNewCard(short com, int baud, ref string kmm, short kzt, string kh, string dqdm, string yhh, string tm, int ql, int csql, int ccsql, short cs, int ljgql, short bkcs, int ljyql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj)=("
                      + com + "," + baud + "," + kmm + "," + kzt
                      + kh + "," + dqdm + "," + yhh + "," + tm
                      + ql + "," + csql + "," + ccsql + "," + cs
                      + ljgql + "," + bkcs + "," + ljyql + "," + bjql
                      + czsx + "," + tzed + "," + sqrq + "," + cssqrq
                      + oldprice + "," + newprice + "," + sxrq + "," + sxbj
                      + ")");
            byte [] cardNo    = System.Text.Encoding.GetEncoding(1252).GetBytes(kh);
            byte[]  yh        = System.Text.Encoding.GetEncoding(1252).GetBytes(yhh);
            byte[]  cardid    = new byte[20];
            byte[]  customeid = new byte[20];
            int     result    = -1;

            //写新卡前先格式化卡
            //格式化卡之前先判断是否为新卡
            byte[] Istrue  = new byte[20];
            int    i       = StaticCheckGasCard(com, Istrue);
            int    istrue1 = int.Parse(Encoding.ASCII.GetString(Istrue, 0, 1));

            Log.Debug("CheckGasCardiSNew and i  is" + i + " and isTrue is " + istrue1);
            //判卡成功

            //是新卡,则不需清卡  if (Istrue == 0)

            //不是新卡,清卡  ,先读卡
            if (istrue1 == 1)
            {
                Log.Debug("克罗姆写新卡非新卡清卡");
                Log.Debug("WriteNewCard->StaticFormatGasCard(com, baud, mm, 2, cardNO, bdqdm)=(" + com + "," + baud + "," + kmm + "," + 2 + "," + cardNo + "," + dqdm + ")");
                Int32  syql        = 0; //当前表剩余气量
                Int32  klxs        = 0; //卡类型
                Int32  ljgql1      = 0;
                Int32  orderamount = 0;
                Int32  orderNum    = 0;
                byte[] cardid1     = new byte[20];
                byte[] customeid1  = new byte[20];
                //清卡前先读卡 确保传入卡中的卡号等参数正确
                Log.Debug("ReadGasCard(com, cardid, customeid, ref orderamount, ref orderNum, ref ljgql, ref syql, ref klx" + com + "," + cardid + "," +
                          customeid + "," + orderamount + "," + orderNum + "," + ljgql + "," + syql + "," + klx);
                int readresult = ReadGasCard(com, cardid1, customeid1, ref orderamount, ref orderNum, ref ljgql1, ref syql, ref klx);
                Log.Debug("ReadGasCard(com, cardid, customeid, ref orderamount, ref orderNum, ref ljgql, ref syql, ref klx)" + readresult);
                byte[] customeNo = customeid1;
                string yhhq      = Encoding.ASCII.GetString(customeNo, 0, 10);
                Log.Debug("FormatGasCard(short com, int baud, string kmm, string kh, string dqdm)=(" + com + "," + baud + "," + kmm + "," + kh + "," + dqdm + ")");
                //清卡需要传入端口号 用户号
                result = StaticFormatGasCard(com, customeNo);
                Log.Debug("FormatGasCard(short com, int baud, string kmm, string kh, string dqdm)=" + result);
                //清卡失败
                if (result != 0)
                {
                    Log.Debug("WriteNewCard(short com, int baud, ref string kmm, short kzt, string kh, string dqdm, string yhh, string tm, int ql, int csql, int ccsql, short cs, int ljgql, short bkcs, int ljyql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj)=" + result);
                    return(result);
                }
            }


            Log.Debug("WriteNewCard->StaticFormatGasCard(com, baud, mm, 2, cardNO, bdqdm)=(" + com + "," + baud + "," + kmm + "," + 2 + "," + cardNo + "," + dqdm + ")=" + result);
            //kzt==0  表示新开户 写卡
            if (0 == kzt)
            {
                result = MakeGasCard(com, cardNo, yh, 1, ql);
            }
            //kzt==1  表示补卡 写卡
            else if (1 == kzt)
            {
                result = MakeGasCard(com, cardNo, yh, cs, ql);
            }

            String buf;

            Log.Debug("发卡后读卡格式:");
            MingHua.GetSnapShot(com, baud, out buf);
            Log.Debug(buf);
            Log.Debug("WriteNewCard(short com, int baud, ref string kmm, short kzt, string kh, string dqdm, string yhh, string tm, int ql, int csql, int ccsql, short cs, int ljgql, short bkcs, int ljyql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj)=("
                      + com + "," + baud + "," + kmm + "," + kzt
                      + kh + "," + dqdm + "," + yhh + "," + tm
                      + ql + "," + csql + "," + ccsql + "," + cs
                      + ljgql + "," + bkcs + "," + ljyql + "," + bjql
                      + czsx + "," + tzed + "," + sqrq + "," + cssqrq
                      + oldprice + "," + newprice + "," + sxrq + "," + sxbj
                      + ")=" + result);
            //转换错误代码

            return(result);
        }
Example #13
0
        public unsafe int WriteGasCard(short com, int baud, ref string kmm, string kh, string dqdm, int ql, int csql, int ccsql, short cs, int ljgql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj)
        {
            int rs = -1;

            try
            {
                PLtCardReader pcr1 = new PLtCardReader()
                {
                    dwDevType = 2,
                    dwPort    = com,
                    dwBaud    = baud,
                    dv_beep   = 0
                };

                PLtMeterStruct pms1 = new PLtMeterStruct()
                {
                    cbSize                   = 0,
                    WriteBack                = 0,
                    TotalAmount              = 0,
                    TotalMoney               = 0,
                    RemainAmount             = 0,
                    RemainMoney              = 0,
                    RechargeTimes            = 0,
                    OverflowTimes            = 0,
                    MagnetismInterferedTimes = 0,
                    Valve   = 0,
                    Battery = 0
                };

                PAdvancedSettingsStruct past = new PAdvancedSettingsStruct()
                {
                    cbSize                 = 0,
                    WarnAmount             = 10,
                    WarnMoney              = 0,
                    AllowedOverdraftAmount = 0,
                    AllowedOverdraftMoney  = 0,
                    ValveOffOnIdle         = 0,
                    ValveOffOnLowPower     = 0,
                    ValveOffOnWarning      = 0
                };

                PUserCard puc1 = new PUserCard()
                {
                    cbSize        = 0,
                    RechargeTimes = cs,
                    RechargeMoney = 0,
                    MecMeterType  = 0
                };

                //给卡号、用户号赋值
                FillBytes(puc1.CardNO, kh);
                FillBytes(puc1.UserNO, dqdm);

                int pti = 0;

                //正常购气
                if (ql != 0)
                {
                    //气量
                    puc1.RechargeAmount = ql * 10000;
                    string kh2   = new string((sbyte *)puc1.CardNO);
                    string dqdm2 = new string((sbyte *)puc1.UserNO);

                    Log.Debug("LanBaoShi WriteGasCard start:卡号:" + kh2 + "区域号:" + dqdm2 + "气量:" + puc1.RechargeAmount + "购气次数:" + puc1.RechargeTimes + "卡类型" + puc1.MecMeterType);

                    String buf;
                    String buf1;
                    Log.Debug("购气前读卡格式:");
                    MingHua.GetSnapShot(com, baud, out buf);
                    rs = RechargeUserCard(ref pcr1, ref puc1, pti);
                    Log.Debug("购气后读卡格式:");
                    MingHua.GetSnapShot(com, baud, out buf1);
                    Log.Debug(buf);
                    Log.Debug(buf1);

                    //kh2 = new string((sbyte*)puc1.CardNO);
                    //dqdm2 = new string((sbyte*)puc1.UserNO);
                    Log.Debug("LanBaoShi WriteGasCard start:返回值return:" + rs + "卡号:" + kh2 + "区域号:" + dqdm2 + "气量:" + puc1.RechargeAmount + "购气次数:" + puc1.RechargeTimes + "卡类型" + puc1.MecMeterType);
                    if (rs == 0)
                    {
                        Log.Debug("蓝宝石购气成功!");
                        return(0);
                    }
                    else
                    {
                        Log.Debug("蓝宝石购气失败!");
                        return(-1);
                    }
                }
                //退气
                else
                {
                    //读取卡上气量
                    int    rt    = ReadUserCard(ref pcr1, ref puc1, pti);
                    string kh2   = new string((sbyte *)puc1.CardNO);
                    string dqdm2 = new string((sbyte *)puc1.UserNO);

                    Log.Debug("LanBaoShi 退气 ReadUserCard end:返回值:" + rt + "区域号:" + dqdm2 + "气量:" + puc1.RechargeAmount + "购气次数:" + puc1.RechargeTimes + "卡类型" + puc1.MecMeterType);

                    //退气时读卡失败
                    if (rt != 0)
                    {
                        return(-1);
                    }

                    int gas = (int)puc1.RechargeAmount;

                    puc1.RechargeAmount = -gas;

                    Log.Debug("LanBaoShi 退气 WriteGasCard start:卡号:" + kh2 + "区域号:" + dqdm2 + "气量:" + puc1.RechargeAmount + "购气次数:" + puc1.RechargeTimes + "卡类型" + puc1.MecMeterType);

                    String buf;
                    String buf1;
                    Log.Debug("退气前读卡格式:");
                    MingHua.GetSnapShot(com, baud, out buf);
                    rs = RechargeUserCard(ref pcr1, ref puc1, pti);
                    Log.Debug("退气后读卡格式:");
                    MingHua.GetSnapShot(com, baud, out buf1);
                    Log.Debug(buf);
                    Log.Debug(buf1);
                    //kh2 = new string((sbyte*)puc1.CardNO);
                    //dqdm2 = new string((sbyte*)puc1.UserNO);
                    Log.Debug("LanBaoShi 退气 WriteGasCard end:返回值return:" + rs + "卡号:" + kh2 + "区域号:" + dqdm2 + "气量:" + puc1.RechargeAmount + "购气次数:" + puc1.RechargeTimes + "卡类型" + puc1.MecMeterType);
                    if (rs == 0)
                    {
                        Log.Debug("蓝宝石冲正成功!");
                        return(0);
                    }
                    else
                    {
                        Log.Debug("蓝宝石冲正失败!");
                        return(-1);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Debug("蓝宝石写卡异常:" + e.Message + "--" + e.StackTrace);
            }
            return(rs);
        }
Example #14
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);
            }
        }
Example #15
0
        public int WriteNewCard(short com, int baud, ref string kmm, short kzt, string kh, string dqdm, string yhh, string tm, int ql, int csql, int ccsql, short cs, int ljgql, short bkcs, int ljyql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj)
        {
            String buf;

            MingHua.GetSnapShot(com, baud, out buf);

            int ret = -1;

            try
            {
                byte[] mm = new byte[16] {
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                };
                // byte[] omm = System.Text.Encoding.GetEncoding(1252).GetBytes(kmm);
                byte[] cardNO = System.Text.Encoding.GetEncoding(1252).GetBytes(kh);
                byte[] bdqdm  = System.Text.Encoding.GetEncoding(1252).GetBytes(dqdm);
                byte[] byhh1  = System.Text.Encoding.GetEncoding(1252).GetBytes(yhh);
                short  oklx   = 1;
                byte[] btm    = new byte[8];
                byte[] bsqrq  = new byte[8] {
                    0, 0, 0, 0, 0, 0, 0, 0
                };
                byte[] bsxrq = new byte[8] {
                    0, 0, 0, 0, 0, 0, 0, 0
                };
                byte[] bsxbj = new byte[8] {
                    0, 0, 0, 0, 0, 0, 0, 0
                };

                short  okzt      = 0;
                byte[] ocardNO   = new byte[100];
                byte[] odqdm     = new byte[100];
                byte[] osqrq     = new byte[100];
                byte[] osxrq     = new byte[100];
                byte[] osxbj     = new byte[100];
                byte[] otm       = new byte[100];
                int    oql       = 0;
                short  ocs       = 0;
                int    oljgql    = 0;
                int    oljyql    = 0;
                int    osyql     = 0;
                int    objql     = 0;
                int    oczsx     = 0;
                int    otzed     = 0;
                short  obkcs     = 0;
                int    ooldprice = 0;
                int    onewprice = 0;
                //读出卡中用户号
                byte[] yhh1 = new byte[100];
                Log.Debug("发卡或者补卡前读卡:");
                ret = ReadGasCard(com, baud, mm, ref oklx, ref okzt, ocardNO, odqdm, yhh1, otm,
                                  ref oql, ref ocs, ref oljgql, ref obkcs, ref oljyql, ref osyql, ref objql, ref oczsx,
                                  ref otzed, osqrq, ref ooldprice, ref onewprice, osxrq, osxbj);
                Log.Debug("读卡结果:" + ret);
                if (0 == ret)
                {
                    Log.Debug("读卡结果为0,则进行擦卡:");
                    kh  = Encoding.ASCII.GetString(ocardNO, 0, 8);
                    yhh = Encoding.ASCII.GetString(yhh1, 0, 10);

                    Log.Debug("擦卡开始parevalues is:" + "--kh" + kh + "--yhh" + yhh);
                    Int32 ret1 = StaticFormatGasCard(com, baud, mm, oklx, ocardNO, odqdm, yhh1);
                    Log.Debug("擦卡结束:" + ret1);
                }
                //int ret = 1;

                if (0 == kzt)
                {
                    Log.Debug("发卡开始,参数:卡号:" + kh + "--气量:" + ql + "--次数:" + cs + "--用户号:" + yhh);
                    ret = StaticWriteNewCard(com, baud, mm, 1, kzt, cardNO, bdqdm, byhh1, btm,
                                             ql, cs, ljgql, bkcs, ljyql, bjql, czsx, tzed, bsqrq, 0, 0, bsxrq, bsxbj);

                    Log.Debug("发卡结束:" + ret);
                }
                else
                {
                    Log.Debug("补卡开始,参数:卡号:" + kh + "--用户号:" + yhh + "--次数:" + cs);
                    ret = StaticWriteNewCard(com, baud, mm, 1, kzt, cardNO, bdqdm, byhh1, btm,
                                             ql, cs, ljgql, bkcs, ljyql, bjql, czsx, tzed, bsqrq, 0, 0, bsxrq, bsxbj);

                    //  Log.Debug("kmm is:"+kmm);
                    Log.Debug("补卡结束" + ret);
                }
            }catch (Exception e)
            {
                Log.Debug("操作新卡异常:" + e.Message + e.StackTrace);
            }

            String buf2;

            MingHua.GetSnapShot(com, baud, out buf2);
            Log.Debug(buf);
            Log.Debug(buf2);

            return(ret);
        }
Example #16
0
        public int WriteGasCard(short com, int baud, ref string kmm, string kh, string dqdm, int ql, int csql, int ccsql, short cs, int ljgql, int bjql, int czsx, int tzed, string sqrq, string cssqrq, int oldprice, int newprice, string sxrq, string sxbj)
        {
            String buf;

            MingHua.GetSnapShot(com, baud, out buf);

            int ret = -1;

            try
            {
                byte[] omm = new byte[16] {
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
                };
                short  oklx      = 0;
                short  okzt      = 0;
                byte[] ocardNO   = new byte[100];
                byte[] odqdm     = new byte[100];
                byte[] osqrq     = new byte[100];
                byte[] osxrq     = new byte[100];
                byte[] osxbj     = new byte[100];
                byte[] otm       = new byte[100];
                int    oql       = 0;
                short  ocs       = 0;
                int    oljgql    = 0;
                int    oljyql    = 0;
                int    osyql     = 0;
                int    objql     = 0;
                int    oczsx     = 0;
                int    otzed     = 0;
                short  obkcs     = 0;
                int    ooldprice = 0;
                int    onewprice = 0;
                //读出卡中用户号
                byte[] yhh = new byte[100];
                Log.Debug("read before sell gas:");
                ret = ReadGasCard(com, baud, omm, ref oklx, ref okzt, ocardNO, odqdm, yhh, otm,
                                  ref oql, ref ocs, ref oljgql, ref obkcs, ref oljyql, ref osyql, ref objql, ref oczsx,
                                  ref otzed, osqrq, ref ooldprice, ref onewprice, osxrq, osxbj);
                Log.Debug("read end before sell gas:" + ret);
                //用户号10位
                yhh[10] = 0;
                string yhhh = Encoding.ASCII.GetString(yhh, 0, 10);
                Log.Debug("yhh is:" + yhhh);
                byte[] cardNO = System.Text.Encoding.GetEncoding(1252).GetBytes(kh);
                byte[] bdqdm  = System.Text.Encoding.GetEncoding(1252).GetBytes(dqdm);
                byte[] btm    = new byte[8];
                byte[] bsqrq  = new byte[8] {
                    0, 0, 0, 0, 0, 0, 0, 0
                };
                byte[] bsxrq = new byte[8] {
                    0, 0, 0, 0, 0, 0, 0, 0
                };
                byte[] bsxbj = new byte[8] {
                    0, 0, 0, 0, 0, 0, 0, 0
                };
                Log.Debug("买气开始,卡号:" + kh + "--dqdm:" + dqdm + "--yhh:" + yhhh + "--cs" + cs);
                ret = StaticWriteGasCard(com, baud, omm, 1, cardNO, bdqdm, yhh, ql,
                                         cs, ljgql, bjql, czsx, tzed, bsqrq, oldprice, newprice, bsxrq, bsxbj);
                Log.Debug("sell gas end:" + ret);
                int pos = -1;
                for (int i = 0; i < omm.Length; i++)
                {
                    if (omm[i] == 0)
                    {
                        pos = i;
                        break;
                    }
                }
                kmm = Encoding.ASCII.GetString(omm, 0, pos);
            }
            catch (Exception e)
            {
                Log.Debug("购气异常:" + e.Message + "----" + e.StackTrace);
            }

            String buf2;

            MingHua.GetSnapShot(com, baud, out buf2);
            Log.Debug(buf);
            Log.Debug(buf2);

            return(ret);
        }