MainPage.xaml.cpp 2.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
//
// MainPage.xaml.cpp
// Implementation of the MainPage class.
//

#include "pch.h"
#include "MainPage.xaml.h"

using namespace AppTestUFRlib;

using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

#include <string.h>

// cstr2str
String^ StringFromAscIIChars(const char* chars)
{
	size_t newsize = strlen(chars) + 1;
	wchar_t * wcstring = new wchar_t[newsize];
	size_t convertedChars = 0;
	mbstowcs_s(&convertedChars, wcstring, newsize, chars, _TRUNCATE);
	String^ str = ref new Platform::String(wcstring);
	delete[] wcstring;
	return str;
}
MainPage::MainPage()
{
	InitializeComponent();

	c_string uFR_ver = GetDllVersionStr();
	txtOut->Text += "uFR DLL version " + StringFromAscIIChars(uFR_ver) + "\n";
}

void MainPage::wr_stat(const char * msg)
{
	c_string stat = UFR_Status2String(status);
	sprintf_s(this->msg, sizeof(this->msg) - 1, "%s : %s\n", msg, stat);
	txtOut->Text += StringFromAscIIChars(this->msg);
}

void MainPage::bRdOpen_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
	status = ReaderOpenEx(1, 0, 1, 0);
	wr_stat("ReaderOpenEx(1, 0, 1, 0)");
}

void MainPage::bRdClose_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
	status = ReaderClose();
	wr_stat("ReaderClose()");
}

void MainPage::bRdInfo_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
	c_string reader_dsc = GetReaderDescription();
	txtOut->Text += StringFromAscIIChars(reader_dsc);
}

void MainPage::bRdSignal_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
	status = ReaderUISignal(3, 3);
	wr_stat("ReaderUISignal(3, 3)");
}

void MainPage::bRdCardID_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
	uint8_t Sak;
	uint8_t Uid[10];
	uint8_t UidSize;
	status = GetCardIdEx(&Sak, Uid, &UidSize);
	wr_stat("GetCardIdEx()");

	if (status == UFR_OK)
	{
		sprintf_s(msg, sizeof(msg) - 1, "CARD: SAK= 0x%02X | UidSize= %d | Uid= ", Sak, UidSize);
		// todo serial
		for (size_t i = 0; i < UidSize; i++)
		{
			char t[10];
			sprintf_s(t, 9, "%02X:", Uid[i]);
			strcat_s(msg, sizeof(msg) - 1, t);
		}
		strcat_s(msg, sizeof(msg) - 1, "\n");

		txtOut->Text += StringFromAscIIChars(msg);
	}
}