예제 #1
0
        private static string Console_InitializePortName()
        {
            int cursorTop = Console.CursorTop;

            string[] portNames = InterfaceCommunicationSettings.GetAvailablePortNames();
            Console.WriteLine("Port Name:");
            for (int i = 0; i < portNames.Length; i++)
            {
                Console.WriteLine(string.Format("{0} - {1}", i, portNames[i]));
            }
            Console.Write("Selection (confirm with ENTER): ");
            string portNameIndexTxt = Console.ReadLine();

            if (int.TryParse(portNameIndexTxt, out int portNameIndex))
            {
                if (portNameIndex < portNames.Length)
                {
                    Console.WriteLine(string.Format("\t{0} selected", portNames[portNameIndex]));
                    return(portNames[portNameIndex]);
                }
            }

            //Selection failed
            Console.SetCursorPosition(0, cursorTop);
            return(Console_InitializePortName());
        }
        private void Button_OpenPort_Click(object sender, RoutedEventArgs e)
        {
            textBox_Logging.Text = "";

            if (comboBox_PortSelect.SelectedIndex == -1)
            {
                //No device selected --> Do nothing
                MessageBox.Show("Please select a Device to connect to");
                return;
            }

            try
            {
                //Initialize InterfaceCommunicationSettings
                //  PortType = 2 --> Bluteooth
                //  PortName = selected device in ComboBox
                var readerPortSettings = InterfaceCommunicationSettings.GetForSerialDevice(2, comboBox_PortSelect.SelectedItem.ToString());
                m_SpcInterface = new SpcInterfaceControl(readerPortSettings, "", "\r\n");

                //Open communication port
                m_SpcInterface.InitializeCompleted += SpcInterface_InitializeCompleted;
                m_SpcInterface.StartInitialize();
            }
            catch
            {
                AddLoggingText(string.Format("{0} - can not open", comboBox_PortSelect.SelectedItem.ToString()));
            }
        }
        private void ButtonInitialize_Click(object sender, RoutedEventArgs e)
        {
            if (radioButtonInitialize_PortUsb.IsChecked.Value)
            {
                //For USB communication, no parameters needed
                m_TelidControl = new TelidControl();
            }
            else
            {
                //For serial/bluetooth, get needed parameters
                byte portType = 0;
                if (radioButtonInitialize_PortBt.IsChecked.Value)
                {
                    portType = 2;
                }
                var readerPortSetings = InterfaceCommunicationSettings.GetForSerialDevice(portType, textBoxInitialize_PortName.Text);
                m_TelidControl = new TelidControl(readerPortSetings);
            }
            //On this event the read-progress is notified
            m_TelidControl.ReadLogProtocol_ProgressPercentageUpdated += TelidControl_ReadLogProtocol_ProgressPercentageUpdated;
            //On this event the result of the "StartInitialize" process is notified
            m_TelidControl.InitializeCompleted += TelidControl_InitializeCompleted;
            //On this event the result of the Start
            m_TelidControl.ReadCompleted += TelidControl_ReadCompleted;

            //Start Initialize
            m_TelidControl.StartInitialize();
        }
        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
            }
        }
        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 Window_Loaded(object sender, RoutedEventArgs e)
 {
     //Get port names and populate ComboBox
     string[] portNames = InterfaceCommunicationSettings.GetAvailablePortNames();
     if (portNames != null)
     {
         if (portNames.Length > 0)
         {
             foreach (string device in portNames)
             {
                 comboBox_PortSelect.Items.Add(device);
             }
             comboBox_PortSelect.IsEnabled = true;
             button_OpenPort.IsEnabled     = true;
         }
     }
 }
예제 #7
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);
        }
        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
            }
        }
        private async void Button_OpenPort_ClickAsync(object sender, RoutedEventArgs e)
        {
            textBox_Logging.Text = "";

            if (comboBox_PortSelect.SelectedIndex == -1)
            {
                //No device selected --> Do nothing
                MessageBox.Show("Please select a Device to connect to");
                return;
            }

            try
            {
                //Initialize InterfaceCommunicationSettings
                //  PortType = 2 --> Bluteooth
                //  PortName = selected device in ComboBox
                var readerPortSettings = InterfaceCommunicationSettings.GetForSerialDevice(2, comboBox_PortSelect.SelectedItem.ToString());
                m_SpcInterface = new SpcInterfaceControl(readerPortSettings, "", "\r\n");

                //Open communication port
                if (await m_SpcInterface.InitializeAsync())
                {
                    AddLoggingText(string.Format("Port {0} open", comboBox_PortSelect.SelectedItem.ToString()));
                    button_GetHeartbeatAsync.IsEnabled = true;
                    button_GetLastHeartbeat.IsEnabled  = true;
                    button_GetLastRawData.IsEnabled    = true;
                    button_GetRawDataAsync.IsEnabled   = true;
                    button_Read.IsEnabled     = true;
                    button_Write.IsEnabled    = true;
                    button_OpenPort.IsEnabled = false;
                }
                else
                {
                    //False --> Communication port could not be opened
                    AddLoggingText(string.Format("{0} - can not open", comboBox_PortSelect.SelectedItem.ToString()));
                }
            }
            catch
            {
                AddLoggingText(string.Format("{0} - can not open", comboBox_PortSelect.SelectedItem.ToString()));
            }
        }
예제 #10
0
        private static SpcInterfaceControl Console_InitializeSpcInterfaceControl()
        {
            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);

            //Parameters selected --> Initialize class instance
            Console.WriteLine("");
            SpcInterfaceControl result = new SpcInterfaceControl(readerPortSettings, "", "\r\n");

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

            //Call initialize to open the communication port

            Console.Write("Initializing...");
            Console.WriteLine("");
            if (result.Initialize())
            {
                Console.WriteLine("\tInitialized");
                return(result);
            }
            else
            {
                //Initialization failed: Terminate class instance & try again
                Console.WriteLine("\tInitialize failed");
                result.Terminate();
                return(Console_InitializeSpcInterfaceControl());
            }
        }
예제 #11
0
        private async void ButtonInitialize_ClickAsync(object sender, RoutedEventArgs e)
        {
            if (radioButtonInitialize_PortUsb.IsChecked.Value)
            {
                //For USB communication, no parameters needed
                m_TelidControl = new TelidControl();
            }
            else
            {
                //For serial/bluetooth, get needed parameters
                byte portType = 0;
                if (radioButtonInitialize_PortBt.IsChecked.Value)
                {
                    portType = 2;
                }
                var readerPortSetings = InterfaceCommunicationSettings.GetForSerialDevice(portType, textBoxInitialize_PortName.Text);
                m_TelidControl = new TelidControl(readerPortSetings);
            }
            //On this event the read-progress is notified
            m_TelidControl.ReadLogProtocol_ProgressPercentageUpdated += TelidControl_ReadLogProtocol_ProgressPercentageUpdated;

            //Initialize
            if (await m_TelidControl.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
                textBlock_ReaderInfo.Text = "Initialize Result: False";
                SetUiEnabled(false, 0);
            }
        }