コード例 #1
0
        private async void btnDisconnect_Copy_Click(object sender, RoutedEventArgs e)
        {
            textBlock1.Text = "";

            fgGetCount cmd = new fgGetCount( );

            CommonResult ret = await FingerprintDevice.Execute(cmd);

            textBlock1.Text = "Result: " + FingerprintDevice.LastExecuteResult.Message + "\r\nUsers: " + cmd.Count.ToString( );

            //try
            //{
            //	_dataWriter.WriteBytes( BuildCommandData( new byte[ ] { 0x09, 0x00, 0x00, 0x00, 0x00 } ) );
            //	await _dataWriter.StoreAsync( );

            //	await _dataReader.LoadAsync( this._readBufferLength );
            //	if ( _dataReader.UnconsumedBufferLength > 0 )
            //	{
            //		byte[ ] data = new byte[_dataReader.UnconsumedBufferLength];
            //		_dataReader.ReadBytes( data );

            //		textBlock1.Text = "";
            //		for ( int i = 0; i < data.Length; i++ )
            //		{
            //			textBlock1.Text += Convert.ToString( data[i], 16 ) + " ";
            //		}
            //	}

            //}
            //catch ( Exception ex )
            //{
            //}



            // =-----------------------------------------------------------------------

            //string ret = await SendByte( BuildCommandData( new byte[ ] { 0x09, 0x00, 0x00, 0x00, 0x00 } ) );

            //if ( ret != string.Empty )
            //{
            //	textBlock1.Text = ret;
            //	return;
            //}

            //byte[ ] red;
            //ret = ReadByte( out red );
            //if ( ret != string.Empty )
            //{
            //	textBlock1.Text = ret;
            //	return;
            //}
            //else
            //{
            //	textBlock1.Text = "";
            //	for ( int i = 0; i < red.Length; i++ )
            //	{
            //		textBlock1.Text = textBlock1.Text + Convert.ToString( red[i], 2 );
            //	}
            //}


            // =-----------------------------------------------------------------------

            //	if ( _sports.Count <= 0 ) return;


            //	SerialDevice _derialPort = _sports[0];
            //	try
            //	{
            //		_derialPort.ReadTimeout = TimeSpan.FromMilliseconds( 1000 );//超时
            //		_derialPort.BaudRate = 9600;//波特率
            //		_derialPort.Parity = SerialParity.None;//校验检查
            //		_derialPort.StopBits = SerialStopBitCount.One;//停止位
            //		_derialPort.DataBits = 8;//数据位
            //		_derialPort.Handshake = SerialHandshake.None;//握手方式

            //		_dataWriter = new DataWriter( _derialPort.OutputStream );

            //		//设置读取输入流
            //		_dataReader = new DataReader( _derialPort.InputStream );
            //		_dataReader.InputStreamOptions = InputStreamOptions.Partial;

            //		_dataWriter.WriteBytes( new byte[ ] { 0xAA, 0xBB, 0xCC, 0xDD } );
            //		await _dataWriter.StoreAsync( );

            //		await _dataReader.LoadAsync( 100 );

            //		if ( _dataReader.UnconsumedBufferLength > 0 )
            //		{
            //			StringBuilder str_builder = new StringBuilder( );
            //			while ( _dataReader.UnconsumedBufferLength > 0 )
            //			{
            //				str_builder.Append( _dataReader.ReadByte( ).ToString( "x2" ) );
            //			}

            //			txbPort.Text = txbPort.Text + "\r\n Read: " + str_builder.ToString( ).ToUpper( );
            //		}
            //	}
            //	finally
            //	{
            //		if ( _dataReader != null )
            //			_dataReader.DetachStream( );

            //		if ( _dataWriter != null )
            //			_dataWriter.DetachStream( );

            //		if ( _derialPort != null )
            //			_derialPort.Dispose( );
            //	}

            //	Task<UInt32> loadAsyncTask;
            //	//读取数据
            //	loadAsyncTask = _dataReader.LoadAsync( _readBufferLength ).AsTask( );
            //	uint bytesRead = await loadAsyncTask;
            //	//判断获取数据长度
            //	if ( bytesRead > 0 )
            //	{
            //		//转换十六进制数据
            //		string res = LoadData( bytesRead );
            //	}

            //}
            //private string LoadData( uint bytesRead )
            //{
            //	StringBuilder str_builder = new StringBuilder( );

            //	//转换缓冲区数据为16进制
            //	while ( _dataReader.UnconsumedBufferLength > 0 )
            //	{
            //		str_builder.Append( _dataReader.ReadByte( ).ToString( "x2" ) );
            //	}
            //	return str_builder.ToString( ).ToUpper( );
            //}
        }
コード例 #2
0
        private async void btnDisconnect_Copy5_Click(object sender, RoutedEventArgs e)
        {
            //TimeSpan _orgTimeout = CommonRes.SerialPort.ReadTimeout;
            //try
            //{
            textBlock1.Text = "";

            // Get current count
            fgGetCount   cmd1 = new fgGetCount( );
            CommonResult ret1 = await FingerprintDevice.Execute(cmd1);

            if (ret1.Code != ResultCode.GN_SUCCESS)
            {
                textBlock1.Text = "Result: " + FingerprintDevice.LastExecuteResult.Message + "\r\nGet fingerprint count error.";
                return;
            }
            else
            {
                textBlock1.Text = "Now collect fingerprint first ....";
            }

            ushort newID = ( ushort )(cmd1.Count + 1);

            //CommonRes.SerialPort.ReadTimeout = TimeSpan.FromMilliseconds( 10000 );

            // First collect
            fgCollectFingerprint cmd2 = new fgCollectFingerprint(1, newID, 1);
            CommonResult         ret2 = await FingerprintDevice.Execute(cmd2);

            if (ret2.Code != ResultCode.GN_SUCCESS)
            {
                textBlock1.Text = "Result: " + FingerprintDevice.LastExecuteResult.Message + "\r\nCollect times 1 fail.";
                return;
            }
            else
            {
                textBlock1.Text = "Now collect fingerprint second ....";
            }

            // Second collect
            fgCollectFingerprint cmd3 = new fgCollectFingerprint(2, newID, 1);
            CommonResult         ret3 = await FingerprintDevice.Execute(cmd3);

            if (ret3.Code != ResultCode.GN_SUCCESS)
            {
                textBlock1.Text = "Result: " + FingerprintDevice.LastExecuteResult.Message + "\r\nCollect times 2 fail.";
                return;
            }
            else
            {
                textBlock1.Text = "Now collect fingerprint last ....";
            }

            // Last collect
            fgCollectFingerprint cmd4 = new fgCollectFingerprint(3, newID, 1);
            CommonResult         ret4 = await FingerprintDevice.Execute(cmd4);

            if (ret4.Code != ResultCode.GN_SUCCESS)
            {
                textBlock1.Text = "Result: " + FingerprintDevice.LastExecuteResult.Message + "\r\nCollect times 2 fail.";
                return;
            }
            else
            {
                textBlock1.Text = "Collect fingerprint finished !!!";
            }

            //}
            //finally
            //{
            //	CommonRes.SerialPort.ReadTimeout = _orgTimeout;
            //}
        }