• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

dll中含有unsignedchar数组,被C#调用-

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

  public class OPVcDll
    {
        #region 对USB接口的使用(PHILIPH卡)
        [DllImport("dcrf32.dll")]
        public static extern int dc_init(Int16 port, long baud);  //初试化
        [DllImport("dcrf32.dll")]
        public static extern short dc_exit(int icdev);
        [DllImport("dcrf32.dll")]
        public static extern short dc_reset(int icdev, uint sec);
        [DllImport("dcrf32.dll")]
        public static extern short dc_request(int icdev, char _Mode, ref uint TagType);
        [DllImport("dcrf32.dll")]
        public static extern short dc_card(int icdev, char _Mode, ref ulong Snr);
        [DllImport("dcrf32.dll")]
        public static extern short dc_halt(int icdev);
        [DllImport("dcrf32.dll")]
        public static extern short dc_anticoll(int icdev, char _Bcnt, ref ulong IcCardNo);
        [DllImport("dcrf32.dll")]
        public static extern short dc_beep(int icdev, uint _Msec);////蜂鸣
        [DllImport("dcrf32.dll")]
        public static extern short dc_authentication(int icdev, int _Mode, int _SecNr);

        [DllImport("dcrf32.dll")]
        public static extern short dc_load_key(int icdev, int mode, int secnr, [In] byte[] nkey);  //密码装载到读写模块中
        [DllImport("dcrf32.dll")]
        public static extern short dc_load_key_hex(int icdev, int mode, int secnr, string nkey);  //密码装载到读写模块中

        [DllImport("dcrf32.dll")]
        public static extern short dc_write(int icdev, int adr, [In] byte[] sdata);  //向卡中写入数据
        [DllImport("dcrf32.dll")]
        public static extern short dc_write(int icdev, int adr, [In] string sdata);  //向卡中写入数据
        [DllImport("dcrf32.dll")]
        public static extern short dc_write_hex(int icdev, int adr, [In] string sdata);  //向卡中写入数据(转换为16进制)

        [DllImport("dcrf32.dll")]
        public static extern short dc_read(int icdev, int adr, [Out] byte[] sdata);

        [DllImport("dcrf32.dll")]
        public static extern short dc_read(int icdev, int adr, [MarshalAs(UnmanagedType.LPStr)] StringBuilder sdata);  //从卡中读数据
        [DllImport("dcrf32.dll")]
        public static extern short dc_read_hex(int icdev, int adr, [MarshalAs(UnmanagedType.LPStr)] StringBuilder sdata);  //从卡中读数据(转换为16进制)
        [DllImport("dcrf32.dll")]
        public static extern int a_hex(string oldValue, ref string newValue, Int16 len);  //普通字符转换成十六进制字符
        [DllImport("dcrf32.dll")]
        public static extern void hex_a(ref string oldValue, ref string newValue, int len);  //十六进制字符转换成普通字符
        /// <summary>
        /// 读取卡信息  (unsigned char * )
        /// </summary>
        /// <param name="icdev"></param>
        /// <param name="_Snrlen"></param>
        /// <returns></returns>
        [DllImport("PdocMACDll.dll")]
        public static extern int mif_CPU_Card(int icdev, [MarshalAs(UnmanagedType.LPArray)]byte[] _Snrlen);
        public static  int mif_CPU_Card(int icdev, ref byte[] _Snrlen)
        {
            return mif_CPU_Card(icdev, _Snrlen);
        }
        #endregion

        /// <summary>
        /// 初始化设备
        /// </summary>
        public static int Icdev
        {
            get
            {
                int dc_init = OPVcDll.dc_init(100, 115200);
                if (dc_init > 0)
                {
                    return dc_init;
                }
                else
                {
                    throw new Exception("初始化失败!");
                }

            }

        }

        /// <summary>
        /// 获取卡信息 
        /// </summary>
        /// <returns></returns>
        public static string ReadIc()
        {
            string cardId = "";
            int st;
            byte[] icCardNo = new byte[16];
            char tt = (char)1;
            uint ss = 0;
            int dc_init = Icdev;
            dc_beep((Int16)dc_init, 50);
            st =dc_request(dc_init, tt, ref ss); //检测卡
            if (st!=0)
            {
                 dc_exit(dc_init); //退出
                throw new Exception("获取卡信息出错!");
            }
            //是否为CPU卡
            if (ss != 8)
            {
                dc_exit(dc_init); //退出
                throw new Exception("该卡为非CPU卡不可以在本功能中发行!");
            }
                 
            mif_CPU_Card(dc_init, ref icCardNo);
            string str = Encoding.Default.GetString(icCardNo);
            if (str != null)
            {
                cardId = str;
            }
            else
            {
                dc_exit(dc_init); //退出
                throw new Exception("寻卡失败!");
            }
           
            return cardId;
        }


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C、C++混合调用发布时间:2022-07-13
下一篇:
C语言数据结构之一元多项式的求导发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap