Chinaunix首页 | 论坛 | 博客
  • 博客访问: 588500
  • 博文数量: 208
  • 博客积分: 3286
  • 博客等级: 中校
  • 技术积分: 1780
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-24 20:38
文章分类

全部博文(208)

文章存档

2012年(7)

2011年(28)

2010年(21)

2009年(76)

2008年(65)

2007年(11)

我的朋友

分类: C/C++

2007-09-24 20:48:58

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Runtime.InteropServices;  // 为了使用DllImport
using System.Text;
namespace WindowsApplication2
{
    static class Program
    {
        ///
        /// 应用程序的主入口点。
        ///

        ///
        [STAThread]
        [DllImport("BM32.dll")]
        internal static extern IntPtr bm_init(int comPortNumber, int baudrate);
        [DllImport("BM32.dll")]
        internal static extern Int16 bm_type_set(IntPtr dev, int cardtype);
        [DllImport("BM32.dll")]
        internal static extern Int16 bm_page(IntPtr dev, int pageno);
        static void Main()
        {
            IntPtr dev;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
           
            dev = bm_init(1, 4800);
            if (dev != null)
            {
                MessageBox.Show("dd"); //连上读卡器后可以弹出这个对话框。这个函数在这个应该是成功了吧。
            }
            else
            {
                MessageBox.Show("ee");
            }
            short ret;
            ret = bm_type_set(dev, 6);
            if (ret == 0)
            {
                MessageBox.Show("type set ok!");//连上读卡器后可以弹出这个对话框。这个函数在这个应该是成功了吧。
            }
            else
            {
                MessageBox.Show("type set nook!");
            }
            unsafe
            {
                Int16 tt;
                //fixed char name[30];
                byte[] cc = new byte[1024];
                int i;
                for (i = 0; i < 1024; i++)
                    cc[i] = 0;
                //  string d = "";
                //MessageBox.Show(cc[0].ToString());
                fixed (Byte * p = cc)
                {
                    tt = bm_page(dev, 0);
                    tt = UnmanagedWrapper.bm_read(dev, 0, 16, p);
                    if (tt == 0)
                    {
                        MessageBox.Show(cc[0].ToString());//连上读卡器后可以弹出这个对话框。但读到的字符不正确。
                    }
                    else
                    {
                        MessageBox.Show("read faild!");
                    }
                   
                    //byte[] ByteArray2 =   { 0x30, 0xe8, 108, 108, 111, 32, 87, 111, 114, 108, 100 };
                    string dte = System.Text.Encoding.Default.GetString(cc);
                    MessageBox.Show(dte);
                    /*
                    ASCIIEncoding AE2 = new ASCIIEncoding();
                    char[] CharArray = AE2.GetChars(cc);
                    String str = "";
                    for (int x = 0; x <= 16; x++)
                    {
                        //Console.Write(CharArray[x]);
                        str += (char)(cc[x]);
                    }
                    MessageBox.Show(str);*/
                }
            }
        }
        unsafe internal static class UnmanagedWrapper
        {
            [DllImport("BM32.dll", CharSet = CharSet.Unicode)]
            internal static extern Int16 bm_read(IntPtr dev_id, int add, int bytes, byte* p);
            [DllImport("BM32.dll", CharSet = CharSet.Unicode)]
            internal static extern Int16 bm_read_hex(IntPtr dev_id, int add, int bytes, byte* p);
        }
    }
}
阅读(823) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:emacs window下编译

给主人留下些什么吧!~~