using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

using Windows.UI.Popups;
using Windows.ApplicationModel.Core;
using Windows.ApplicationModel.Activation;
using Windows.Storage;
using Windows.Storage.Pickers;


using BxlWinUniversalSDK;


// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace BxlUniversalTestAPP.Content
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class PrintingTest : Page
    {
        BxlUniversalSDK _BxlUniversalSDK;

        public PrintingTest()
        {
            this.InitializeComponent();

            if (true == MainPage._ConnectedPrinter)
            {
                _BxlUniversalSDK = MainPage._BxlUniversalSDK;
            }
            else
            {
                var Dialog = new MessageDialog("First connect to the printer.");
                Dialog.ShowAsync();
            }
        }

        private void Feed_Click(object sender, RoutedEventArgs e)
        {
            _BxlUniversalSDK.LineFeed(6);
        }

        private void Text_Click(object sender, RoutedEventArgs e)
        {
            _BxlUniversalSDK.SetCharacterSet(MainPage.BXL_CS_WPC1252);

            _BxlUniversalSDK.PrintText("Left Default\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText("Center, FontB\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_FONTB, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText("Right, FontC\n", MainPage.BXL_ALIGNMENT_RIGHT, MainPage.BXL_FT_FONTC, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);

            _BxlUniversalSDK.PrintText("Center, Bold, Default\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_BOLD | MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText("Center, Bold, FontB\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_FONTB | MainPage.BXL_FT_BOLD, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText("Center, Bold, FontC\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_BOLD | MainPage.BXL_FT_FONTC, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);

            _BxlUniversalSDK.PrintText("Left, Underline\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_UNDERLINE | MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText("Right, Reverse\n", MainPage.BXL_ALIGNMENT_RIGHT, MainPage.BXL_FT_REVERSE | MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);

            _BxlUniversalSDK.PrintText("Left, Default, 0W 0H\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText("Left, Default, 1W 0H\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_1WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText("Left, Default, 0W 1H\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_1HEIGHT);
            _BxlUniversalSDK.PrintText("Left, Default, 1W 1H\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_1WIDTH | MainPage.BXL_TS_1HEIGHT);

            _BxlUniversalSDK.LineFeed(5);
        }

        private void Barcode_Click(object sender, RoutedEventArgs e)
        {
            byte[] bytes = new byte[12] { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32 };

            _BxlUniversalSDK.PrintText("UPCA\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_UPCA, 50, 2, MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_BC_TEXT_BELOW);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_UPCA, 70, 3, MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_BC_TEXT_BELOW);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_UPCA, 30, 2, MainPage.BXL_ALIGNMENT_RIGHT, MainPage.BXL_BC_TEXT_BELOW);

            _BxlUniversalSDK.PrintText("UPCE\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_UPCE, 50, 2, MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_BC_TEXT_BELOW);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_UPCE, 30, 3, MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_BC_TEXT_NONE);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_UPCE, 70, 2, MainPage.BXL_ALIGNMENT_RIGHT, MainPage.BXL_BC_TEXT_NONE);

            _BxlUniversalSDK.PrintText("EAN13\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_EAN13, 50, 2, MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_BC_TEXT_ABOVE);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_EAN13, 70, 2, MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_BC_TEXT_ABOVE);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_EAN13, 50, 3, MainPage.BXL_ALIGNMENT_RIGHT, MainPage.BXL_BC_TEXT_ABOVE);

            _BxlUniversalSDK.PrintText("JAN13\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_JAN13, 50, 2, MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_BC_TEXT_BELOW);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_JAN13, 70, 4, MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_BC_TEXT_BELOW);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_JAN13, 30, 2, MainPage.BXL_ALIGNMENT_RIGHT, MainPage.BXL_BC_TEXT_BELOW);

            byte[] bytes1 = new byte[8] { 0x31, 0x32, 0x33, 0x34, 0x34, 0x35, 0x36, 0x38 };
            _BxlUniversalSDK.PrintText("EAN8\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes1, MainPage.BXL_BCS_EAN8, 50, 2, MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_BC_TEXT_NONE);
            _BxlUniversalSDK.PrintBarcode(bytes1, MainPage.BXL_BCS_EAN8, 70, 2, MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_BC_TEXT_NONE);
            _BxlUniversalSDK.PrintBarcode(bytes1, MainPage.BXL_BCS_EAN8, 60, 3, MainPage.BXL_ALIGNMENT_RIGHT, MainPage.BXL_BC_TEXT_NONE);

            _BxlUniversalSDK.PrintText("JAN8\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes1, MainPage.BXL_BCS_JAN8, 50, 2, MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_BC_TEXT_BELOW);
            _BxlUniversalSDK.PrintBarcode(bytes1, MainPage.BXL_BCS_JAN8, 50, 4, MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_BC_TEXT_BELOW);
            _BxlUniversalSDK.PrintBarcode(bytes1, MainPage.BXL_BCS_JAN8, 50, 3, MainPage.BXL_ALIGNMENT_RIGHT, MainPage.BXL_BC_TEXT_BELOW);

            byte[] bytes2 = new byte[12] { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32 };

            _BxlUniversalSDK.PrintText("Code 39\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes2, MainPage.BXL_BCS_CODE39, 50, 2, MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_BC_TEXT_ABOVE);
            _BxlUniversalSDK.PrintBarcode(bytes2, MainPage.BXL_BCS_CODE39, 70, 3, MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_BC_TEXT_ABOVE);
            _BxlUniversalSDK.PrintBarcode(bytes2, MainPage.BXL_BCS_CODE39, 50, 4, MainPage.BXL_ALIGNMENT_RIGHT, MainPage.BXL_BC_TEXT_ABOVE);

            _BxlUniversalSDK.PrintText("ITF\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes2, MainPage.BXL_BCS_ITF, 50, 2, MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_BC_TEXT_NONE);
            _BxlUniversalSDK.PrintBarcode(bytes2, MainPage.BXL_BCS_ITF, 30, 3, MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_BC_TEXT_NONE);
            _BxlUniversalSDK.PrintBarcode(bytes2, MainPage.BXL_BCS_ITF, 70, 4, MainPage.BXL_ALIGNMENT_RIGHT, MainPage.BXL_BC_TEXT_NONE);

            _BxlUniversalSDK.PrintText("Codebar\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes2, MainPage.BXL_BCS_CODABAR, 50, 2, MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_BC_TEXT_BELOW);
            _BxlUniversalSDK.PrintBarcode(bytes2, MainPage.BXL_BCS_CODABAR, 40, 3, MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_BC_TEXT_BELOW);
            _BxlUniversalSDK.PrintBarcode(bytes2, MainPage.BXL_BCS_CODABAR, 70, 2, MainPage.BXL_ALIGNMENT_RIGHT, MainPage.BXL_BC_TEXT_BELOW);

            _BxlUniversalSDK.PrintText("Code 93\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes2, MainPage.BXL_BCS_CODE93, 50, 2, MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_BC_TEXT_ABOVE);
            _BxlUniversalSDK.PrintBarcode(bytes2, MainPage.BXL_BCS_CODE93, 60, 2, MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_BC_TEXT_ABOVE);
            _BxlUniversalSDK.PrintBarcode(bytes2, MainPage.BXL_BCS_CODE93, 70, 2, MainPage.BXL_ALIGNMENT_RIGHT, MainPage.BXL_BC_TEXT_ABOVE);

            _BxlUniversalSDK.PrintText("Code 128\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes2, MainPage.BXL_BCS_CODE128, 50, 2, MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_BC_TEXT_NONE);
            _BxlUniversalSDK.PrintBarcode(bytes2, MainPage.BXL_BCS_CODE128, 50, 2, MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_BC_TEXT_NONE);
            _BxlUniversalSDK.PrintBarcode(bytes2, MainPage.BXL_BCS_CODE128, 50, 2, MainPage.BXL_ALIGNMENT_RIGHT, MainPage.BXL_BC_TEXT_NONE);

            _BxlUniversalSDK.LineFeed(5);
        }

        private void Barcode2_Click(object sender, RoutedEventArgs e)
        {
            byte[] bytes = new byte[12] { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32 };

            _BxlUniversalSDK.PrintText("PDF417\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_PDF417, 0, 2, MainPage.BXL_ALIGNMENT_LEFT, 0);

            _BxlUniversalSDK.PrintText("QRCODE\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_QRCODE_MODEL1, 0, 2, MainPage.BXL_ALIGNMENT_LEFT, 0);

            _BxlUniversalSDK.PrintText("QRCODE\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_QRCODE_MODEL2, 0, 2, MainPage.BXL_ALIGNMENT_LEFT, 0);

            _BxlUniversalSDK.PrintText("DATAMATRIX\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_DATAMATRIX, 0, 2, MainPage.BXL_ALIGNMENT_LEFT, 0);

            _BxlUniversalSDK.PrintText("MAXICODE\n", MainPage.BXL_ALIGNMENT_LEFT, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintBarcode(bytes, MainPage.BXL_BCS_MAXICODE_MODE4, 0, 2, MainPage.BXL_ALIGNMENT_LEFT, 0);


            _BxlUniversalSDK.LineFeed(5);
        }

        private void Sample_Click(object sender, RoutedEventArgs e)
        {
            _BxlUniversalSDK.SetCharacterSet(MainPage.BXL_CS_WPC1251);
            _BxlUniversalSDK.SetInterCharSet(MainPage.BXL_ICS_USA);

            _BxlUniversalSDK.PrintText("Receipt\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_BOLD | MainPage.BXL_FT_UNDERLINE, MainPage.BXL_TS_1WIDTH | MainPage.BXL_TS_1HEIGHT);
            _BxlUniversalSDK.PrintText("\n\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_BOLD | MainPage.BXL_FT_UNDERLINE, MainPage.BXL_TS_1WIDTH | MainPage.BXL_TS_1HEIGHT);

            _BxlUniversalSDK.PrintText("------------------------------\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText(" Apple      3             $3.0\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText(" Cola       1             $1.2\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText(" Milk       2             $1.8\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText(" Juice      1             $2.0\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText("------------------------------\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText(" Total                    $8.0\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_BOLD, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText(" Cash                     $8.0\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_BOLD, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText("                          $0.0\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_BOLD, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);

            //////////////////////////////////////////////////////////////////////////
            //Set multi attribute in one line.
            _BxlUniversalSDK.PrintText("Test", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_BOLD, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText("BBB", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_FONTB | MainPage.BXL_FT_BOLD, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText("CCC", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_FONTB | MainPage.BXL_FT_REVERSE, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText("DDD", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_BOLD | MainPage.BXL_FT_UNDERLINE, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText("\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_BOLD | MainPage.BXL_FT_UNDERLINE, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);

            _BxlUniversalSDK.PrintText("ABCDEFabcdef\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_DEFAULT, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText("ABCDEFabcdef\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_FONTB, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);
            _BxlUniversalSDK.PrintText("ABCDEFabcdef\n", MainPage.BXL_ALIGNMENT_CENTER, MainPage.BXL_FT_FONTC, MainPage.BXL_TS_0WIDTH | MainPage.BXL_TS_0HEIGHT);


            _BxlUniversalSDK.LineFeed(5);
        }

        private async void Direct_Click(object sender, RoutedEventArgs e)
        {
            byte[] bytes = new byte[3] { 0x1d, 0x49, 67 };  // GS I
            byte[] ReadBuf = new byte[20];


            ReadBuf = await _BxlUniversalSDK.DirectIOAsync(bytes, 20);

            if (null != ReadBuf)
            {
                var Dialog = new MessageDialog(System.Text.Encoding.UTF8.GetString(ReadBuf, 1, ReadBuf.Length - 2));
                Dialog.ShowAsync();
            }
        }

        private async void Status_Click(object sender, RoutedEventArgs e)
        {
            Int32 status = await _BxlUniversalSDK.CheckPrinterStatusAsync();
            string strStatus;

            if ((status & MainPage.BXL_STS_COVEROPEN) != 0)
            {
                strStatus = "Cover : Open";
            }
            else
            {
                strStatus = "Cover : Close";
            }

            if ((status & MainPage.BXL_STS_PAPEREMPTY) != 0)
            {
                strStatus += "  Paper : Empty";
            }
            else
            {
                strStatus += "  Paper : OK";
            }

            var Dialog = new MessageDialog(strStatus);
            Dialog.ShowAsync();

            Int32 power = await _BxlUniversalSDK.CheckPowerAsync();
            string strPower;

            if (power == MainPage.BXL_PWR_FULL)
                strPower = "Battery : Full. 75~100%";
            else if (power == MainPage.BXL_PWR_HIGH)
                strPower = "Battery : High. 50~75%";
            else if (power == MainPage.BXL_PWR_MIDDLE)
                strPower = "Battery : Middle. 10~50%";
            else if (power == MainPage.BXL_PWR_LOW)
                strPower = "Battery : Low. under 10%";
            else
                strPower = "Failed to check battery.";

            Dialog = new MessageDialog(strPower);
            Dialog.ShowAsync();
        }

        CoreApplicationView view = CoreApplication.GetCurrentView();

        private async void Image_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker imgPicker = new FileOpenPicker();
            MessageDialog Dialog;

            imgPicker.ViewMode = PickerViewMode.Thumbnail;
            imgPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            imgPicker.FileTypeFilter.Add(".bmp");
            imgPicker.FileTypeFilter.Add(".jpeg");
            imgPicker.FileTypeFilter.Add(".jpg");
            imgPicker.FileTypeFilter.Add(".gif");

            StorageFile file = await imgPicker.PickSingleFileAsync();

            if (null != file)
            {
                try
                {
                    Int32 ret;

                    ret = await _BxlUniversalSDK.PrintImage(file.Path, 300, MainPage.BXL_ALIGNMENT_CENTER, 50);

                    if (MainPage.BXL_SUCCESS != ret)
                    {
                        Dialog = new MessageDialog("Failed to print image.");
                        Dialog.ShowAsync();
                    }
                }
                catch (Exception ex)
                {
                    Dialog = new MessageDialog(ex.Message);
                    Dialog.ShowAsync();
                }
            }
            else
            {
                Dialog = new MessageDialog("Failed to open the image.");
                Dialog.ShowAsync();
            }

            //view.Activated += PrintImage;
        }

        private async void PrintImage(CoreApplicationView sender, IActivatedEventArgs args1)
        {
            FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs;
            MessageDialog Dialog;

            var d1 = new MessageDialog("11111");
            d1.ShowAsync();

            if (args != null)
            {
                if (args.Files.Count == 0) return;

                view.Activated -= PrintImage;

                var d = new MessageDialog(args.Files[0].Path);
                d.ShowAsync();

                try
                {
                    Int32 ret;

                    ret = await _BxlUniversalSDK.PrintImage(args.Files[0].Path, 300, MainPage.BXL_ALIGNMENT_CENTER, 50);

                    if (MainPage.BXL_SUCCESS != ret)
                    {
                        Dialog = new MessageDialog("Failed to print image.");
                        Dialog.ShowAsync();
                    }
                }
                catch (Exception ex)
                {
                    Dialog = new MessageDialog(ex.Message);
                    Dialog.ShowAsync();
                }
            }
        }

    }
}
