C#读取RFID卡号源码

  //读卡器介绍:https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-17663462238.23.16795b43onC5S2&id=600862990715https://item.taobao.com/item.htm?spm=a1z10.5-c.w4002-17663462238.23.16795b43onC5S2&id=600862990715

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;  //调用动态库一定要加入这个引用


namespace idcardreader
{
    public partial class Form1 : Form
    {
        //------------------------------------------------------------------------------------------------------------------------------------------------------
        //外部函数声明:让设备发出声响
        [DllImport("OUR_IDR_x64.dll", EntryPoint = "idr_beep", CallingConvention = CallingConvention.StdCall)]
        static extern byte idr_beep(UInt32 xms);//xms单位为毫秒 

	//------------------------------------------------------------------------------------------------------------------------------------------------------    
        //读取设备编号,可做为软件加密狗用,也可以根据此编号在公司网站上查询保修期限
        [DllImport("OUR_IDR_x64.dll", EntryPoint = "pcdgetdevicenumber", CallingConvention = CallingConvention.StdCall)]
        static extern byte pcdgetdevicenumber(byte[] devicenumber);//devicenumber用于返回编号 


        //------------------------------------------------------------------------------------------------------------------------------------------------------    
        //只读卡号
        [DllImport("OUR_IDR_x64.dll", EntryPoint = "idr_read", CallingConvention = CallingConvention.StdCall)]
        public static extern byte idr_read(byte[] serial);//serial返回卡号


	//------------------------------------------------------------------------------------------------------------------------------------------------------    
        //只读卡号,只读一次,必须拿开卡才能再读到
        [DllImport("OUR_IDR_x64.dll", EntryPoint = "idr_read_once", CallingConvention = CallingConvention.StdCall)]
        public static extern byte idr_read_once(byte[] serial);//serial返回卡号



        //------------------------------------------------------------------------------------------------------------------------------------------------------
        //发送显示内容到读卡器
        //[DllImport("OUR_IDR.dll", EntryPoint = "lcddispfull", CallingConvention = CallingConvention.StdCall)]
        //static extern byte lcddispfull(string lcdstr);
        //参数:说明

        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            byte status;//存放返回值
            byte[] myserial = new byte[5];//卡序列号
            status = idr_read(myserial);

            switch (status)
            {
                case 0:
                    idr_beep(50);

                    MessageBox.Show("读卡成功,卡号为" + System.Convert.ToString(myserial[1] * 256 * 256 * 256 + myserial[2] * 256 * 256 + myserial[3] * 256 + myserial[4]));
                    //MessageBox.Show("操作成功,卡号已在myserial中,卡号一般为myserial[0]卡厂商标识,myserial[1]到myserial[4]为卡号,用户可以组合为各种卡号编码。");
                    
                    break;
                //......
                case 8:
                    MessageBox.Show("请将卡放在感应区");
                    break;

                default:
                    MessageBox.Show("返回码(对应的说明请看例子中的注释):" + status);
                    break;

            }

        }

        private void button7_Click(object sender, EventArgs e)
        {//嘀一声
            idr_beep(50);
        }

        private void button6_Click(object sender, EventArgs e)
        {//读取设备编号,可做为软件加密狗用
            byte[] devno = new byte[4];
            if (pcdgetdevicenumber(devno) == 0)
            {
                MessageBox.Show(System.Convert.ToString(devno[0]) + "-" + System.Convert.ToString(devno[1]) + "-" + System.Convert.ToString(devno[2]) + "-" + System.Convert.ToString(devno[3]));
                //ShowMessage(IntToStr(devno[0]) + "-" + IntToStr(devno[1]) + "-" + IntToStr(devno[2]) + "-" + IntToStr(devno[3]));
            }
        }


        private void button4_Click(object sender, EventArgs e)
        {
            byte status;//存放返回值
            byte[] myserial = new byte[5];//卡序列号
            status = idr_read_once(myserial);

            switch (status)
            {
                case 0:
                    idr_beep(50);
                    MessageBox.Show("读卡成功,卡号为" + System.Convert.ToString(myserial[1] * 256 * 256 * 256 + myserial[2] * 256 * 256 + myserial[3] * 256 + myserial[4]));
                    //MessageBox.Show("操作成功,卡号已在myserial中,卡号一般为myserial[0]卡厂商标识,myserial[1]到myserial[4]为卡号,用户可以组合为各种卡号编码。");

                    break;
                //......
                case 8:
                    MessageBox.Show("请将卡放在感应区");
                    break;

                default:
                    MessageBox.Show("返回码(对应的说明请看例子中的注释):" + status);
                    break;

            }
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

vx_13822155058

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值