Exemplo n.º 1
0
        private DataModel dataModel = new DataModel();//读卡信息
        private void Read_Card()
        {
            Task task = new Task(() =>
            {
                CHCUsbSDK.USB_SDK_CERTIFICATE_INFO struCertificateInfo = new CHCUsbSDK.USB_SDK_CERTIFICATE_INFO();
                struCertificateInfo.dwSize = (uint)Marshal.SizeOf(struCertificateInfo);

                CHCUsbSDK.USB_CONFIG_OUTPUT_INFO struConfigOutputInfo = new CHCUsbSDK.USB_CONFIG_OUTPUT_INFO();
                struConfigOutputInfo.dwOutBufferSize = struCertificateInfo.dwSize;
                IntPtr ptrstruCertificateInfo        = Marshal.AllocHGlobal((int)struCertificateInfo.dwSize);
                Marshal.StructureToPtr(struCertificateInfo, ptrstruCertificateInfo, false);
                struConfigOutputInfo.lpOutBuffer = ptrstruCertificateInfo;

                CHCUsbSDK.USB_CONFIG_INPUT_INFO strConfigInputConfig = new CHCUsbSDK.USB_CONFIG_INPUT_INFO();
                if (CHCUsbSDK.USB_SDK_GetDeviceConfig(CHCUsbSDK.UserID, CHCUsbSDK.USB_SDK_GET_CERTIFICATE_INFO, ref strConfigInputConfig, ref struConfigOutputInfo))
                {
                    struCertificateInfo = (CHCUsbSDK.USB_SDK_CERTIFICATE_INFO)Marshal.PtrToStructure(struConfigOutputInfo.lpOutBuffer, typeof(CHCUsbSDK.USB_SDK_CERTIFICATE_INFO));
                    CertificateInfo     = struCertificateInfo;
                    ReadCertificateInfo();
                    Marshal.FreeHGlobal(ptrstruCertificateInfo);
                }
                else
                {
                    Marshal.FreeHGlobal(ptrstruCertificateInfo);
                    Console.WriteLine(CHCUsbSDK.ERR_LEVEL + "Fail to Read CardInfo");
                }
            });

            task.Start();
        }
Exemplo n.º 2
0
        private void login_device()
        {
            if (!JudgeValidOfLoginInfo())
            {
                return;
            }
            StruCurUsbLoginInfo.dwSize         = (uint)Marshal.SizeOf(StruCurUsbLoginInfo);
            StruCurUsbLoginInfo.dwTimeout      = 5000;//登录超时时间是5秒
            StruCurUsbLoginInfo.dwVID          = m_aHidDevInfo[SelectedItemsIndex].dwVID;
            StruCurUsbLoginInfo.dwPID          = m_aHidDevInfo[SelectedItemsIndex].dwPID;
            StruCurUsbLoginInfo.szSerialNumber = m_aHidDevInfo[SelectedItemsIndex].szSerialNumber;
            StruCurUsbLoginInfo.szUserName     = "******";
            StruCurUsbLoginInfo.szPassword     = "******";
            deviceSerialNumber = StruCurUsbLoginInfo.szSerialNumber;
            CHCUsbSDK.USB_SDK_DEVICE_REG_RES StruDeviceRegRes = new CHCUsbSDK.USB_SDK_DEVICE_REG_RES();
            StruDeviceRegRes.dwSize = (uint)Marshal.SizeOf(StruDeviceRegRes);
            int UserIDTemp = CHCUsbSDK.UserID;

            CHCUsbSDK.UserID = CHCUsbSDK.USB_SDK_Login(ref StruCurUsbLoginInfo, ref StruDeviceRegRes);
            if (CHCUsbSDK.UserID == CHCUsbSDK.INVALID_USER_ID)
            {
                CHCUsbSDK.UserID = UserIDTemp;
                changeConn(CHCUsbSDK.UserID != -1);
                Console.WriteLine(CHCUsbSDK.UserID);
                //为了解决重复登录时的问题,但是这次只考虑了只能登录一个设备,两个设备同时能登录的话,ID会覆盖得继续解决ID的问题
            }
            else
            {
                changeConn(true);
                string SuccesfulLoginInfo = "The device whose serial number is " + StruCurUsbLoginInfo.szSerialNumber + "login in successfully";
                Console.WriteLine(SuccesfulLoginInfo);
            }
        }
        private string deviceSerialNumber       = "";                             //设备编号
        #endregion

        #region 读卡初始化
        private void ReadInit()
        {
            bool res = CHCUsbSDK.USB_SDK_Init();//USB initialize

            m_VersionNum = CHCUsbSDK.USB_SDK_GetSDKVersion();
            TraverseDevice(); //遍历设备
            Login_device();   //登录设备
            autoRead_Timer.Tick    += AutoRead_Timer_Tick;
            autoRead_Timer.Interval = TimeSpan.FromMilliseconds(1000);
        }
Exemplo n.º 4
0
 private void TraverseDevice()
 {
     m_aHidDevInfo   = new CHCUsbSDK.USB_SDK_DEVICE_INFO[CHCUsbSDK.MAX_USB_DEV_LEN];
     g_nEnumDevIndex = 1;
     deviceModels.Clear();                                                  //不把列表头都清空了,得用item.clear
     m_OnEnumDeviceCallBack = new CHCUsbSDK.EnumDeviceCallBack(OnEnumDeviceCallBack);
     if (CHCUsbSDK.USB_SDK_EnumDevice(m_OnEnumDeviceCallBack, IntPtr.Zero)) //枚举设备
     {
         Console.WriteLine(CHCUsbSDK.INF_LEVEL + "SUCCESS USB_SDK_EnumDevice()");
     }
     else
     {
         Console.WriteLine(CHCUsbSDK.ERR_LEVEL + "FAILED USB _SDK_EnumDevice()");
     }
 }
Exemplo n.º 5
0
        private string deviceSerialNumber       = "";                             //设备编号
        public ReadCard()
        {
            InitializeComponent();
            Items2 = new List <DataModel>();
            bool res = CHCUsbSDK.USB_SDK_Init();//USB initialize

            //IntPtr ptrLogPath = Marshal.StringToHGlobalAnsi(szLogPath);//写日志
            //CHCUsbSDK.USB_SDK_SetLogToFile(3, ptrLogPath, false);//这里用枚举参数不匹配,直接写了3,
            //Marshal.FreeHGlobal(ptrLogPath);
            m_VersionNum = CHCUsbSDK.USB_SDK_GetSDKVersion();
            TraverseDevice(); //遍历设备
            login_device();   //登录设备
            autoRead_Timer.Tick    += AutoRead_Timer_Tick;
            autoRead_Timer.Interval = TimeSpan.FromMilliseconds(1000);
            autoScan_Timer.Tick    += AutoScan_Timer_Tick;
            autoScan_Timer.Interval = TimeSpan.FromMilliseconds(10);
        }
Exemplo n.º 6
0
        DispatcherTimer autoRead_Timer          = new DispatcherTimer();          //自动读卡
        public MainWindow()
        {
            InitializeComponent();
            bool res = CHCUsbSDK.USB_SDK_Init();//USB initialize

            m_VersionNum = CHCUsbSDK.USB_SDK_GetSDKVersion();
            TraverseDevice(); //遍历设备
            login_device();   //登录设备
            autoRead_Timer.Tick    += AutoRead_Timer_Tick;
            autoRead_Timer.Interval = TimeSpan.FromMilliseconds(1000);
            SettingModel settingModel1 = SettingJsonConfig.readJson();

            settingModel                = settingModel1 == null ? new SettingModel() : settingModel1;
            userNameBox.Text            = settingModel.userName == null ? "" : settingModel.userName;
            passWordBox.Password        = settingModel.passWord == null ? "" : settingModel.passWord;
            CheckBox_isRember.IsChecked = settingModel.isRember;
        }