Exemplo n.º 1
0
        //发卡
        public static bool destribute_card_M1(string company_code, string cardCode)
        {
            if (!connect_card_machine("M1"))
            {
                return(false);
            }

            ulong snr  = 0;
            char  mode = '1';

            ICRF.rf_card(icdev, mode, ref snr);

            //string skey = "FFFFFFFFFFFF";
            string skey = "6a3530303033";

            if (verify_pwd_M1(skey))
            {
                write_str_M1(company_code, cardCode);
            }
            else
            {
                MessageBox.Show("验证密码失败");
                ICRF.rf_exit(icdev);
                return(false);
            }

            ICRF.rf_exit(icdev);
            return(true);
        }
Exemplo n.º 2
0
        //连接读卡机
        private static bool connect_card_machine(string cardType)
        {
            if (icdev > 0)
            {
                if (cardType == "SLE4442")
                {
                    IC.ic_exit(icdev);
                }
                else if (cardType == "M1")
                {
                    ICRF.rf_exit(icdev);
                }
            }

            string card_port = IOUtil.get_config_by_key(ConfigKeys.KEY_CARD_PORT);
            string card_baud = IOUtil.get_config_by_key(ConfigKeys.KEY_CARD_BAUD);
            string no_hint   = IOUtil.get_config_by_key(ConfigKeys.KEY_CARD_NOHINT);

            if ((card_port == "" || card_baud == "") && (no_hint == "" || no_hint == "false"))
            {
                CardPortBaudForm cardPortBaudForm = new CardPortBaudForm();
                if (cardPortBaudForm.ShowDialog() != DialogResult.OK)
                {
                    return(false);
                }

                card_port = cardPortBaudForm.card_port.ToString();
                card_baud = cardPortBaudForm.card_baud.ToString();
            }

            if (card_port == "" || card_baud == "")
            {
                return(false);
            }

            Int16 port = Convert.ToInt16(card_port);
            int   baud = Convert.ToInt32(card_baud);

            if (cardType == "SLE4442")
            {
                icdev = IC.ic_init(port, baud);
            }
            else if (cardType == "M1")
            {
                icdev = ICRF.rf_init(port, baud);
            }
            if (icdev <= 0)
            {
                BathClass.printErrorMsg("连接读卡器失败,请重试!");
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        private static bool write_str_M1(string company_code, string card_code)
        {
            string str = company_code + card_code;

            byte[] data = Encoding.ASCII.GetBytes(str);
            int    st   = ICRF.rf_write(icdev, 9, data);

            if (st != 0)
            {
                BathClass.printErrorMsg("写卡失败!");
                return(false);
            }
            st = ICRF.rf_beep(icdev, 20);
            st = ICRF.rf_exit(icdev);

            return(true);
        }
Exemplo n.º 4
0
        private static bool verify_pwd_M1(string skey)
        {
            byte[] key1 = new byte[20];
            byte[] key2 = new byte[20];

            key1 = Encoding.ASCII.GetBytes(skey);
            ICRF.a_hex(key1, key2, 12);
            int st = ICRF.rf_load_key(icdev, 1, 2, key2);

            if (st != 0)
            {
                return(false);
            }

            st = ICRF.rf_authentication(icdev, 1, 2);
            if (st != 0)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
        public static bool read_data_M1(string compnay_code, ref string card_str)
        {
            if (!connect_card_machine("M1"))
            {
                return(false);
            }

            ulong snr  = 0;
            char  mode = '1';

            ICRF.rf_card(icdev, mode, ref snr);

            byte[] key1 = new byte[20];
            byte[] key2 = new byte[20];

            string skey      = "6a3530303033";
            string skey_init = "FFFFFFFFFFFF";

            if (verify_pwd_M1(skey_init) || verify_pwd_M1(skey))
            {
                byte[] data   = new byte[16];
                byte[] p_dest = new byte[16];
                for (int i = 0; i < 16; i++)
                {
                    data[i] = 0;
                }
                for (int i = 0; i < 16; i++)
                {
                    p_dest[i] = 0;
                }

                int st = ICRF.rf_read(icdev, 9, data);
                if (st == 0)
                {
                    card_str = System.Text.Encoding.ASCII.GetString(data);
                    if (!card_str.Contains(compnay_code))
                    {
                        return(false);
                    }

                    card_str = card_str.Substring(compnay_code.Length);
                    string tmpStr = "";
                    foreach (char c in card_str)
                    {
                        if (char.IsDigit(c))
                        {
                            tmpStr += c;
                        }
                    }
                    card_str = tmpStr;
                }
                else
                {
                    MessageBox.Show("读取数据失败");
                    ICRF.rf_exit(icdev);
                    return(false);
                }
            }
            else
            {
                MessageBox.Show("装载密码失败");
                ICRF.rf_exit(icdev);
                return(false);
            }



            ICRF.rf_exit(icdev);

            return(true);
        }