干吗要多线程读?哪个读卡器这么牛B一次能读N张卡?

解决方案 »

  1.   

    因为要连续不断的读,还要和数据库中的字段比较
      

  2.   

    没有人知道吗?有没有好心人呀,急
      

  3.   

    楼主,我也正在学习这个,能否把你的代码发一份学习一下啊,谢谢!
      

  4.   

    实现有多种方法了,为什么一定要多线程操作,比较麻烦的。
      

  5.   

    要连续不断的读卡,建议你不要用多线程读,可以用个Timer控制,然后再连接串口,执行读卡的方法。
    给你个思路,可以试试。。
     //c++函数强制声明
            [DllImport("mi.dll", EntryPoint = "API_OpenComm")]
            public static extern IntPtr API_OpenComm(int nCom, int nBaudrate);        [DllImport("mi.dll", EntryPoint = "API_ControlBuzzer")]
            public static extern int API_ControlBuzzer(IntPtr commHandle, int DeviceAddress, byte freq, byte duration, ref byte buffer);        [DllImport("mi.dll", EntryPoint = "API_MF_Read")]
            public static extern int API_MF_Read(IntPtr commHandle, int DeviceAddress, byte mode, byte blk_add, byte num_blk, ref byte snr, ref byte buffer);
     private void Form1_Load(object sender, EventArgs e)
            {
                //启动时间轴
                timer1.Interval = 1000;
                timer1.Start();        }
     private void timer1_Tick(object sender, EventArgs e)
            {            byte[] hex = new byte[16];
                long ret = long.Parse("281474976710655");
                hex = BitConverter.GetBytes(ret);            byte[] hex1 = new byte[16];
                byte[] hex2 = new byte[16];
                //Array.Clear(hex1, 0, 16);
                byte[] data = new byte[16];
                byte prBuf = new byte();
                int idata = API_MF_Read(Program.Port, 0, 0, 10, 1, ref hex[0], ref data[0]);
                //无卡接触时,循环等待
                if (idata != 0)
                {
                    return;
                }
                //取卡号
                s = BitConverter.ToInt64(data, 0).ToString();            member mem = new member();
                timer1.Stop();            //卡有效性验证
                if (mem.Existsnew(Convert.ToInt32(s)))
                {
                    Program.Num_id = Convert.ToInt32(s);
                    DialogResult result;
                    result = MessageBoxEx.Show("此卡有效,是否现在进行考核", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.No)
                    {
                        timer1.Start();
                        return;
                    }
                    if(memscore.ifexist(Convert.ToInt32(s)))
                    {
                        timer1.Start();
                        return;
                    }
                }
                else
                {
                    MessageBoxEx.Show("此卡无效,请换卡重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    timer1.Start();
                    return;
                }