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()));
            }
        }
Exemplo n.º 2
0
        private static void SendReadRequest(SpcInterfaceControl _spcIntControl)
        {
            // Generate "SCAN" request and send to reader
            string command = "~T";          // SOH + Read-Identifier

            _spcIntControl.SendSpcRequest(command);
            Console.WriteLine(string.Format("\nSend READ Request: {0}", command));
        }
 private void Button_ClosePort_Click(object sender, RoutedEventArgs e)
 {
     if (m_SpcInterface != null)
     {
         m_SpcInterface.Dispose();
         m_SpcInterface = null;
     }
     button_OpenPort.IsEnabled = true;
     button_Read.IsEnabled     = false;
     button_Write.IsEnabled    = false;
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine(".NETCore Console");
            Console.WriteLine("SampleThreads_C#");
            Console.WriteLine("--------------------");
            Console.WriteLine("Library Version: " + iIDReaderLibrary.Version.LibraryVersion);

            //Get SpcInterfaceControl instance
            SpcInterfaceControl spcIntControl = Console_InitializeSpcInterfaceControl();

            if (spcIntControl != null)
            {
                //SpcInterfaceControl is initialized
                AddConsoleLines();

                //Check cyclically if key pressed
                bool exit = false;
                while (!exit)
                {
                    var key = Console.ReadKey();
                    switch (key.Key)
                    {
                    case ConsoleKey.R:
                        SendReadRequest(spcIntControl);
                        break;

                    case ConsoleKey.W:
                        SendWriteRequest(spcIntControl);
                        break;

                    case ConsoleKey.X:
                        exit = true;
                        break;
                    }
                    Thread.Sleep(500);
                }

                spcIntControl.Terminate();
                Console.WriteLine("");
                Console.Write("EXITING in 5");
                Thread.Sleep(1000);
                Console.Write(", 4");
                Thread.Sleep(1000);
                Console.Write(", 3");
                Thread.Sleep(1000);
                Console.Write(", 2");
                Thread.Sleep(1000);
                Console.Write(", 1");
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 5
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
            result.InitializeCompleted += SpcInterfaceControl_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.RawDataReceived         += SpcInterface_RawDataReceived;
                result.ReaderHeartbeatReceived += SpcInterface_ReaderHeartbeatReceived;
                return(result);
            }
            else
            {
                //Initialization failed: Terminate class instance & try again
                Console.WriteLine("\tInitialize failed");
                result.Terminate();
                return(Console_InitializeSpcInterfaceControl());
            }
        }
Exemplo n.º 6
0
        private static void SendWriteRequest(SpcInterfaceControl _spcIntControl)
        {
            if (string.IsNullOrEmpty(m_LastId))
            {
                return;
            }
            // Generate "WRITE" request and send to reader
            string command = "~W";                                                    // SOH + Write-Identifier

            command += m_LastId;                                                      // TID
            command += "ConsoleTest " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // Equipment-data to write
            _spcIntControl.SendSpcRequest(command);
            Console.WriteLine(string.Format("\nSend WRITE Request: {0}", command));
        }
Exemplo n.º 7
0
        static async void MainAsync()
        {
            Console.WriteLine(".NETCore Console");
            Console.WriteLine("SampleThreads_C#");
            Console.WriteLine("--------------------");
            Console.WriteLine("Library Version: " + iIDReaderLibrary.Version.LibraryVersion);

            //Get SpcInterfaceControl instance
            SpcInterfaceControl spcIntControl = Console_InitializeSpcInterfaceControl();

            if (spcIntControl != null)
            {
                //SpcInterfaceControl is initialized
                Console.WriteLine("");
                Console.Write("Waiting for Heartbeat...");
                var heartbeat = await spcIntControl.GetHeartbeatAsync();

                if (heartbeat != null)
                {
                    Console.WriteLine("");
                    Console.WriteLine("Detected Reader:");
                    ShowHeartbeat(heartbeat);
                }

                //Reader info obtained --> execute functions using menu
                Console.WriteLine("");
                while (await Console_ExecuteAndContinueAsync(spcIntControl))
                {
                    Thread.Sleep(500);
                }

                spcIntControl.Terminate();
                Console.WriteLine("");
                Console.Write("EXITING in 5");
                Thread.Sleep(1000);
                Console.Write(", 4");
                Thread.Sleep(1000);
                Console.Write(", 3");
                Thread.Sleep(1000);
                Console.Write(", 2");
                Thread.Sleep(1000);
                Console.Write(", 1");
                Thread.Sleep(1000);
            }
            m_Completed = true;
        }
        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()));
            }
        }
Exemplo n.º 9
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());
            }
        }
Exemplo n.º 10
0
        private static async System.Threading.Tasks.Task <bool> Console_ExecuteAndContinueAsync(SpcInterfaceControl _spcIntControl)
        {
            //Main Console MENU
            Console.WriteLine("");
            Console.WriteLine("--------------------");
            Console.WriteLine(" Console MENU");
            Console.WriteLine("--------------------");
            Console.WriteLine("0 - Get Last HEARTBEAT");
            Console.WriteLine("1 - Get HEARTBEAT asynchronously");
            Console.WriteLine("2 - Get Last RawData");
            Console.WriteLine("3 - Get RawData asynchronously");
            Console.WriteLine("4 - Send READ request");
            Console.WriteLine("5 - Send WRITE request");
            Console.WriteLine("X - EXIT");
            Console.Write("Selection (confirm with ENTER): ");
            string operationNumTxt = Console.ReadLine();

            switch (operationNumTxt)
            {
            case "0":
                Console.WriteLine("\tGet Last HEARTBEAT");
                var lastHb = _spcIntControl.Heartbeat;
                if (lastHb != null)
                {
                    ShowHeartbeat(lastHb);
                }
                break;

            case "1":
                Console.WriteLine("\tGet HEARTBEAT asynchronously");
                var hbAsync = await _spcIntControl.GetHeartbeatAsync();

                if (hbAsync != null)
                {
                    ShowHeartbeat(hbAsync);
                }
                break;

            case "2":
                Console.WriteLine("\tGet Last RawData");
                var lastRawData = _spcIntControl.DataReceived;
                if (lastRawData != null)
                {
                    DecodeReceivedText(lastRawData.Data);
                }
                break;

            case "3":
                Console.WriteLine("\tGet RawData asynchronously");
                var rawDataAsync = await _spcIntControl.GetDataReceivedAsync();

                if (rawDataAsync != null)
                {
                    DecodeReceivedText(rawDataAsync.Data);
                }
                break;

            case "4":
                Console.WriteLine("\tSend READ request");
                SendReadRequest(_spcIntControl);
                break;

            case "5":
                Console.WriteLine("\tSend WRITE request");
                SendWriteRequest(_spcIntControl);
                break;

            case "X":
            case "x":
                return(false);

            default:
                break;
            }
            Thread.Sleep(500);
            return(true);
        }