Ejemplo n.º 1
0
        /// <summary>
        /// Socket opening and start polling
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConnectButton(object sender, EventArgs e)
        {
            // Get IP address and Ip port from form front panel
            m_IPAddress = textBox_IPAddress.Text;
            int.TryParse(textBox_IPPort.Text, out m_IPPort);

            m_PositionerName = TextBox_Group.Text;
            int index = m_PositionerName.LastIndexOf('.');

            if (index != -1)
            {
                m_IsPositioner          = true;
                m_GroupName             = m_PositionerName.Substring(0, index);
                label_ErrorMessage.Text = string.Empty;
            }
            else
            {
                m_IsPositioner = false;
                m_GroupName    = m_PositionerName;
                ErrorMessageHandlerChanged("Must be a positioner name not a group name");
            }

            label_GroupStatusDescription.Text = string.Empty;
            m_XPSControllerVersion            = string.Empty;
            m_errorDescription = string.Empty;

            try
            {
                // Open socket #1 to order
                if (m_xpsInterface == null)
                {
                    m_xpsInterface = new CommandInterfaceXPS.XPS();
                }
                if (m_xpsInterface != null)
                {
                    // Open socket
                    int returnValue = m_xpsInterface.OpenInstrument(m_IPAddress, m_IPPort, DEFAULT_TIMEOUT);
                    if (returnValue == 0)
                    {
                        string errorString = string.Empty;
                        int    result      = m_xpsInterface.FirmwareVersionGet(out m_XPSControllerVersion, out errorString);
                        if (result == CommandInterfaceXPS.XPS.FAILURE) // Communication failure with XPS
                        {
                            if (errorString.Length > 0)
                            {
                                int errorCode = 0;
                                int.TryParse(errorString, out errorCode);
                                m_xpsInterface.ErrorStringGet(errorCode, out m_errorDescription, out errorString);
                                m_XPSControllerVersion = string.Format("FirmwareVersionGet ERROR {0}: {1}", result, m_errorDescription);
                            }
                            else
                            {
                                m_XPSControllerVersion = string.Format("Communication failure with XPS after FirmwareVersionGet ");
                            }
                        }
                        else
                        {
                            label_MessageCommunication.ForeColor = Color.Green;
                            label_MessageCommunication.Text      = string.Format("Connected to XPS");
                            m_CommunicationOK = true;
                        }
                    }
                }
                else
                {
                    m_XPSControllerVersion = "XPS instance is NULL";
                }

                // Open socket #2 for polling
                if (m_xpsInterfaceForPolling == null)
                {
                    m_xpsInterfaceForPolling = new CommandInterfaceXPS.XPS();
                }
                if (m_xpsInterfaceForPolling != null)
                {
                    // Open socket
                    int returnValue = m_xpsInterfaceForPolling.OpenInstrument(m_IPAddress, m_IPPort, DEFAULT_TIMEOUT);
                    if (returnValue == 0)
                    {
                        string errorString = string.Empty;
                        int    result      = m_xpsInterfaceForPolling.FirmwareVersionGet(out m_XPSControllerVersion, out errorString);
                        if (result != CommandInterfaceXPS.XPS.FAILURE) // Communication failure with XPS
                        {
                            StartPolling();
                        }
                    }
                }

                if (m_XPSControllerVersion.Length <= 0)
                {
                    m_XPSControllerVersion = "No detected XPS";
                }

                this.Text = string.Format("Axel Track v1.3 - {0}", m_XPSControllerVersion);
            }
            catch (Exception ex)
            {
                ErrorMessageHandlerChanged("Exception in ConnectButton: " + ex.Message);
            }
        }