private async void ButtonInitialize_ClickAsync(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;

                textBlock_ReaderInfo.Text = "Calling Initialize";
                if (await m_DocInterface.InitializeAsync())
                {
                    //Initialize worked --> Enable UI & enable BackgroundWorker to check Reader-ID
                    textBlock_ReaderInfo.Text = "Initialize Result: True";
                    if (m_Worker.IsBusy != true)
                    {
                        // Start the asynchronous operation.
                        m_Worker.RunWorkerAsync();
                    }
                }
                else
                {
                    //Initialize didn't work --> disable UI
                    SetUiEnabled(false, 0);
                    textBlock_ReaderInfo.Text = "Initialize Result: False";
                }
            }
            catch
            {
                //TODO catch exception & notify
            }
        }
예제 #2
0
        private static async System.Threading.Tasks.Task <DocInterfaceControl> Console_InitializeDocInterfaceControlAsync()
        {
            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));
            Console.WriteLine("Initializing...");

            //Call initialize to open the communication port
            try
            {
                if (await result.InitializeAsync())
                {
                    Console.WriteLine("\tInitialized");
                    return(result);
                }
                else
                {
                    //Initialization failed: Terminate class instance & try again
                    Console.WriteLine("\tInitialize failed");
                    result.Terminate();
                    return(await Console_InitializeDocInterfaceControlAsync());
                }
            }
            catch { }
            return(null);
        }