private static DocInterfaceControl Console_InitializeDocInterfaceControl()
        {
            Console.WriteLine("== Select initialize parameters ==");
            //Get PortType
            int    portType = Console_InitializePortType();
            string portName = "";

            switch (portType)
            {
            case 0:
            case 2:
                //For Serial & bluetooth, PortName needed.
                portName = Console_InitializePortName();
                break;
            }
            //Initialize InterfaceCommunicationSettings class
            var readerPortSettings = InterfaceCommunicationSettings.GetForSerialDevice(portType, portName);
            //InterfaceType = 13.56MHz for TELID®200
            int interfaceType = 1356;

            //Parameters selected --> Initialize class instance
            Console.WriteLine("");
            DocInterfaceControl result = new DocInterfaceControl(readerPortSettings, interfaceType);

            Console.WriteLine(string.Format("Selected parameters: PortType: {0} | PortName: {1} | IntType: {2}", portType, portName, interfaceType));

            //Call initialize to open the communication port
            result.InitializeCompleted += DocInterfaceControl_InitializeCompleted;
            result.StartInitialize();
            Console.Write("Initializing...");
            //For demo purposes, just wait blocking execution until "Initialize" process is completed (notified using "InitializeCompleted" event)
            while (!initializeCompleted) //Alternative, call "IsInitializing"
            {
                Thread.Sleep(100);
                Console.Write(".");
            }
            Console.WriteLine("");
            if (result.IsInitialized)
            {
                Console.WriteLine("\tInitialized");
                result.DocResultChanged += DocInterfaceControl_DocResultChanged;
                return(result);
            }
            else
            {
                //Initialization failed: Terminate class instance & try again
                Console.WriteLine("\tInitialize failed");
                result.Terminate();
                return(Console_InitializeDocInterfaceControl());
            }
        }
        private void ButtonInitialize_Click(object sender, RoutedEventArgs e)
        {
            if (m_DocInterface != null)
            {
                //First dispose previous instance
                m_DocInterface.Terminate();
                m_DocInterface = null;
            }
            //Get Interface parameters and initialize class
            try
            {
                //Port type --> Get from UI
                //  0 = Serial
                //  2 = Bluetooth
                //  4 = USB
                byte portType = 4; //Default USB
                if (radioButtonInitialize_PortSerial.IsChecked.Value)
                {
                    portType = 0;
                }
                if (radioButtonInitialize_PortBt.IsChecked.Value)
                {
                    portType = 2;
                }

                var readerPortSettings = InterfaceCommunicationSettings.GetForSerialDevice(portType, textBoxInitialize_PortName.Text);
                //Interface Type --> 1356 = 13.56MHz (HF)

                //Initialize class. Then call "initialize"
                m_DocInterface = new DocInterfaceControl(readerPortSettings, 1356);

                //Initialize
                textBlockInitialize_ParamInterfaceType.Text = "InterfaceType: 1356";
                textBlockInitialize_ParamPortType.Text      = "PortType: " + portType;
                textBlockInitialize_ParamPortName.Text      = "PortName: " + textBoxInitialize_PortName.Text;

                m_DocInterface.InitializeCompleted += DocInterface_InitializeCompleted;
                m_DocInterface.DocResultChanged    += DocInterface_DocResultChanged;
                textBlock_ReaderInfo.Text           = "Calling Initialize";
                m_DocInterface.StartInitialize();
            }
            catch
            {
                //TODO catch exception & notify
            }
        }