示例#1
0
        /// <summary>
        /// Query the current port's capabilities without accessing it. You can only call the Close()
        /// method after reading the capabilities. This method does neither initialize nor Open() the
        /// port.
        /// </summary>
        ///
        /// <example>
        ///
        /// </example>
        public bool Query()
        {
            if (isOpen)
            {
                return(false);
            }

            hPort = m_CommAPI.QueryFile(portName);

            if (hPort == (IntPtr)CommAPI.INVALID_HANDLE_VALUE)
            {
                int e = Marshal.GetLastWin32Error();

                if (e == (int)APIErrors.ERROR_ACCESS_DENIED)
                {
                    // port is unavailable
                    return(false);
                }

                // ClearCommError failed!
                string error = String.Format("CreateFile Failed: {0}", e);
                throw new CommPortException(error);
            }


            // read the port's capabilities
            bool status = GetPortProperties();

            return(true);
        }
示例#2
0
        /// <summary>
        /// Query the current port's capabilities without accessing it. You can only call the Close()
        /// method after reading the capabilities. This method does neither initialize nor Open() the
        /// port.
        /// </summary>
        ///
        /// <example>
        ///
        /// </example>
        public bool Query()
        {
            if (isOpen)
            {
                return(false);
            }

            hPort = m_CommAPI.QueryFile(portName);

            if (hPort == (IntPtr)CommAPI.INVALID_HANDLE_VALUE)
            {
                int e = Marshal.GetLastWin32Error();

                if (e == (int)APIErrors.ERROR_ACCESS_DENIED)
                {
                    // port is unavailable
                    return(false);
                }

                string errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
                Console.WriteLine(errorMessage);
                string error = "CreateFile Failed: " + errorMessage;
                throw new CommPortException(error);
            }


            // read the port's capabilities
            bool status = GetPortProperties();

            return(true);
        }