Ejemplo n.º 1
0
        /// <summary>
        /// 卡机内是否有卡
        /// </summary>
        /// <returns></returns>
        public static bool CardUsable()
        {
            bool iss    = false;
            int  handle = 0;

            try
            {
                string        port = SysConfigHelper.readerNode("CRT310Port");
                StringBuilder info = new StringBuilder(1024);
                handle = CRT310.CommOpen("COM" + port);
                //读卡器状态
                Byte atPosition   = new byte();
                Byte frontSetting = new byte();
                Byte rearSetting  = new byte();
                //读取状态
                int hasCard = CRT310.CRT310_GetStatus(handle, ref atPosition, ref frontSetting, ref rearSetting);
                if ((atPosition == 0x4b) || (atPosition == 0x4a))
                {
                    iss = true;
                }
            }
            catch (Exception e)
            {
                throw new Exception("系统异常");
            }
            finally
            {
                CRT310.CommClose(handle);
            }
            return(iss);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 电动读卡器吞卡
        /// </summary>
        public static void swallowCard()
        {
            int handle = 0;

            try
            {
                string        port = SysConfigHelper.readerNode("CRT310Port");
                StringBuilder info = new StringBuilder(260);
                handle = CRT310.CommOpen("COM" + port);
                //读卡器状态
                Byte atPosition   = new byte();
                Byte frontSetting = new byte();
                Byte rearSetting  = new byte();

                //读取状态
                int hasCard = CRT310.CRT310_GetStatus(handle, ref atPosition, ref frontSetting, ref rearSetting);
                if ((atPosition == 0x4b) || (atPosition == 0x4a))
                {
                    //进卡控制,不进卡
                    CRT310.CRT310_CardSetting(handle, 0x1, 0x1);
                    //弹卡
                    CRT310.CRT310_Reset(handle, 2);
                    SysBLL.isSwallowCard = "9999";
                }
            }
            catch (Exception e)
            {
                throw new Exception("系统异常");
            }
            finally
            {
                CRT310.CommClose(handle);
            }
        }
Ejemplo n.º 3
0
        //public override Card getCardInfo(string cardNo)
        //{
        //    //TODO 调用万通卡查询余额的方法,返回卡片信息

        //    return null;
        //}

        //public override bool Recharge(string cardNo, int gasValue)
        //{
        //    throw new NotImplementedException();
        //}

        //public override bool Recharge(string cardNo, double moneyCount)
        //{
        //    //TODO 调用拉卡拉消费的方法
        //    //TODO 调用拉卡拉消费的方法,如果失败,提示错误,跳出方法

        //    //TODO 调用拉卡拉消费的方法,如果成功,调用万通卡的充值方法
        //    return false;

        //}

        /// <summary>
        /// 调用读卡器,拿到万通卡卡号
        /// </summary>
        /// <returns></returns>
        public string GetCardNo()
        {
            string        port   = SysConfigHelper.readerNode("CRT310Port");
            StringBuilder info   = new StringBuilder(260);
            int           handle = CRT310.CommOpen("COM" + port);

            try
            {
                //进卡控制
                CRT310.CRT310_CardSetting(handle, 0x3, 0x1);
                //停卡位置
                CRT310.CRT310_CardPosition(handle, 0x4);

                Byte atPosition   = new byte();
                Byte frontSetting = new byte();
                Byte rearSetting  = new byte();

                //读取状态
                int hasCard = CRT310.CRT310_GetStatus(handle, ref atPosition, ref frontSetting, ref rearSetting);//卡没插好,怎么办

                Byte   cpuType   = new byte();
                Byte[] exdata    = new byte[1024];
                int    exdataLen = 0;
                //CPU卡复位
                CRT310.CPU_ColdReset(handle, 0x0, ref cpuType, exdata, ref exdataLen);

                executeAPDU(handle, "00A40000023F00");

                executeAPDU(handle, "00A40000023F20");

                string cardNoSource = executeAPDU(handle, "00B0950000");
                //进卡控制
                CRT310.CRT310_CardSetting(handle, 0x1, 0x1);

                string result = DecryptCardNo(cardNoSource);
                return(result);
            }
            catch (Exception e)
            {
                throw new WtException(WtExceptionCode.Card.WT_READ_CARD, e.Message);
            }
            finally
            {
                //关闭端口
                CRT310.CommClose(handle);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 电动读卡器退卡
        /// </summary>
        public static void backCard()
        {
            int handle = 0;

            try
            {
                string        port = SysConfigHelper.readerNode("CRT310Port");
                StringBuilder info = new StringBuilder(1024);
                handle = CRT310.CommOpen("COM" + port);
                //进卡控制,不进卡
                CRT310.CRT310_CardSetting(handle, 0x1, 0x1);

                //读卡器状态
                Byte atPosition   = new byte();
                Byte frontSetting = new byte();
                Byte rearSetting  = new byte();

                //读取状态
                int hasCard = CRT310.CRT310_GetStatus(handle, ref atPosition, ref frontSetting, ref rearSetting);
                if ((atPosition == 0x4a) || (atPosition == 0x4b) || (atPosition == 0x4c) || (atPosition == 0x4d) || (atPosition == 0x46) || (atPosition == 0x47) || (atPosition == 0x48))
                {
                    //弹卡
                    CRT310.CRT310_Reset(handle, 1);
                    SysBLL.Player("请保管好您的卡片.wav");
                }
                //进卡控制,不进卡
                CRT310.CRT310_CardSetting(handle, 0x1, 0x1);
                CRT310.TT_EjectCard(0, new StringBuilder());
            }
            catch (ThreadAbortException ex) { log.Write("error:电动读卡器退卡:" + ex.Message); }
            catch (Exception e)
            {
                throw new Exception("系统异常");
            }
            finally
            {
                CRT310.CommClose(handle);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 等待插卡
        /// </summary>
        public static void waitCard()
        {
            int handle = 0;

            try
            {
                string        port = SysConfigHelper.readerNode("CRT310Port");
                StringBuilder info = new StringBuilder(260);
                handle = CRT310.CommOpen("COM" + port);
                //进卡控制
                CRT310.CRT310_CardSetting(handle, 0x3, 0x1);
                //停卡位置
                CRT310.CRT310_CardPosition(handle, 0x4);
            }
            catch (ThreadAbortException ae) { log.Write("error:等待插卡方法异常:" + ae.Message); }
            catch (Exception e)
            {
                throw new Exception("系统异常");
            }
            finally
            {
                CRT310.CommClose(handle);
            }
        }
Ejemplo n.º 6
0
        public static string MonitorCom()
        {
            //终端号
            string ClientNo = SysConfigHelper.readerNode("ClientNo");

            string strCom = "";
            //电动读卡器
            string        port   = SysConfigHelper.readerNode("CRT310Port");
            StringBuilder info   = new StringBuilder(2048);
            int           handle = CRT310.CommOpen("COM" + port);

            if (handle > 0)
            {
                strCom = strCom + "1";
            }
            else
            {
                strCom = strCom + "0";
            }
            CRT310.CommClose(handle);
            //燃气
            port         = SysConfigHelper.readerNode("CJ201");
            CJ201.handle = CJ201.Open_Com(Int32.Parse(port), 9600, 8, 0, 0);
            if (CJ201.handle > 0)
            {
                strCom = strCom + "1";
            }
            else
            {
                strCom = strCom + "0";
            }
            CJ201.Close_Com(CJ201.handle);
            ////公交读卡器
            //port = SysConfigHelper.readerNode("CRT603Port");
            //int openRet = CRT603.CRT603Vx_OpenConnection(Int32.Parse(port), 19200);
            //if (openRet == 0) strCom = strCom + "1";
            //else strCom = strCom + "0";
            //CRT603.CRT603Vx_CloseConnection();
            //打印机
            handle = Print.TT_OpenDevice(new StringBuilder("COM" + SysConfigHelper.readerNode("PrintPort")), new StringBuilder("38400"), info);
            if (handle == 0)
            {
                strCom = strCom + "1";
            }
            else
            {
                strCom = strCom + "0";
            }
            Print.TT_CloseDevice(info);
            //密码键盘
            PasswordBLL pwdBLL = new PasswordBLL();
            bool        ret    = pwdBLL.OpenDevice(SysConfigHelper.readerNode("ZT598Port"), "9600");

            if (ret)
            {
                strCom = strCom + "1";
            }
            else
            {
                strCom = strCom + "0";
            }

            return(strCom);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 读卡IC卡
        /// </summary>
        /// <returns></returns>
        public static Dictionary <string, string> ReadIC()
        {
            StringBuilder info   = new StringBuilder(260);
            int           handle = 0;

            try
            {
                string port = SysConfigHelper.readerNode("CRT310Port");
                handle = CRT310.TT_OpenDevice(new StringBuilder("COM" + port), new StringBuilder("9600"), new StringBuilder());

                Dictionary <string, string> icParams = new Dictionary <string, string>();
                StringBuilder info4           = new StringBuilder(1000);
                byte[]        sb              = new byte[10240];
                int           TT_GetTrackData = CRT310.TT_GetTrackData(sb, 2, null);
                //byte[] data = Encoding.ASCII.GetBytes(sb.ToString());

                string str = System.Text.Encoding.GetEncoding("gb2312").GetString(sb);
                icParams["cidao2"] = str.Replace("=", "D");

                icParams["cardNo"] = icParams["cidao2"].Substring(0, icParams["cidao2"].IndexOf("D"));

                byte[] data1 = new byte[1024];
                CRT310.TT_GetTrackData(data1, 3, info4);
                str = System.Text.Encoding.GetEncoding("gb2312").GetString(data1).TrimEnd('\0');
                icParams["cidao3"] = str.Replace("=", "D");


                StringBuilder info1 = new StringBuilder(260);

                StringBuilder info2 = new StringBuilder(260);

                byte[]        data  = null;
                StringBuilder info3 = new StringBuilder(260);

                StringBuilder szMsg = new StringBuilder();


                byte[] result = new byte[2048];
                CRT310.TT_CPUPowerOnOrDown(1, info);
                CRT310.TT_CPUGetICCardInfo(result, info);
                CRT310.TT_CPUPowerOnOrDown(0, info);
                System.Text.ASCIIEncoding ASCII = new System.Text.ASCIIEncoding();
                str = ASCII.GetString(result).TrimEnd('\0');
                string[] sArray = str.Split('|');
                //退卡
                icParams["period"]   = sArray[0];
                icParams["serialNo"] = sArray[1];


                if (sArray[3].IndexOf("\0") != -1)
                {
                    sArray[3].Replace("\0", "");
                }
                icParams["area55"] = sArray[3];


                //status = CRT310.TT_GetTrackData(data, 3, info4);
                //M1essageBox.Show("3磁道数据:" + data.ToString());
                CRT310.CommClose(handle);
                CRT310.TT_CloseDevice(info);
                return(icParams);
            }
            catch (Exception ex)
            {
                throw new Exception("系统异常");
            }
            finally
            {
                CRT310.CommClose(handle);
                CRT310.TT_CloseDevice(info);
            }
        }
Ejemplo n.º 8
0
        public static Dictionary <string, string> ReadBankCard1()
        {
            StringBuilder info   = new StringBuilder(260);
            int           handle = 0;

            try
            {
                string port = SysConfigHelper.readerNode("CRT310Port");
                handle = CRT310.TT_OpenDevice(new StringBuilder("COM" + port), new StringBuilder("9600"), new StringBuilder());

                Dictionary <string, string> icParams = new Dictionary <string, string>();
                StringBuilder info4 = new StringBuilder(1000);

                //读磁道信息

                //二磁道
                byte[] cidao2          = new byte[1024 * 4];
                int    TT_GetTrackData = CRT310.TT_GetTrackData(cidao2, 2, null);
                string str             = System.Text.Encoding.GetEncoding("gb2312").GetString(cidao2).TrimEnd('\0');
                icParams["cidao2"] = str.Replace("=", "D");

                ///三磁道
                byte[] cidao3 = new byte[1024 * 4];
                CRT310.TT_GetTrackData(cidao3, 3, info4);
                str = System.Text.Encoding.GetEncoding("gb2312").GetString(cidao3).TrimEnd('\0');
                icParams["cidao3"] = str.Replace("=", "D");

                //读卡号
                icParams["cardNo"] = icParams["cidao2"].Substring(0, icParams["cidao2"].IndexOf("D"));

                //读IC卡信息
                byte[] icInfo = new byte[2048];
                CRT310.TT_CPUPowerOnOrDown(1, info);
                CRT310.TT_CPUGetICCardInfo(icInfo, info);
                CRT310.TT_CPUPowerOnOrDown(0, info);
                str = System.Text.Encoding.GetEncoding("gb2312").GetString(icInfo).TrimEnd('\0');

                if (str != null && !"".Equals(str.Trim()))
                {
                    string[] sArray = str.Split('|');
                    //退卡
                    if (sArray != null && sArray.Length >= 4)
                    {
                        icParams["period"]   = sArray[0];
                        icParams["serialNo"] = sArray[1];

                        if (sArray[3].IndexOf("\0") != -1)
                        {
                            sArray[3].Replace("\0", "");
                        }
                        icParams["area55"] = sArray[3];
                    }
                }
                CRT310.CommClose(handle);
                CRT310.TT_CloseDevice(info);
                return(icParams);
            }
            catch (Exception ex)
            {
                throw new Exception("系统异常");
            }
            finally
            {
                CRT310.CommClose(handle);
                CRT310.TT_CloseDevice(info);
            }
        }