Exemple #1
0
        /// <summary>
        /// Initializes the communication port.
        /// </summary>
        /// Revision History
        /// MM/DD/YY who Version Issue# Description
        /// -------- --- ------- ------ ---------------------------------------
        /// 08/01/05 bdm 7.13.00 N/A	Created
        private void Init()
        {
            // create a system event for synchronizing Closing
            m_ptrCloseEvent = PortAPI.CreateEvent(true,
                                                  false,
                                                  m_strCloseEventName);

            // create the transmit and receive buffers
            m_abytRxBuf = new byte[m_uintRxBufSz];
            m_abytTxBuf = new byte[m_uintTxBufSz];

            //Default using detailed port settings;
            m_portSettings = new DetailedPortSettings();
        }
Exemple #2
0
        /// <summary>
        /// Opens the port passed in as a parameter.
        /// </summary>
        /// <param name="portName">
        /// The communication port to open.
        /// </param>
        /// <exception cref="CommPortException">
        /// Thrown when a port failure occurs.
        /// </exception>
        /// <example>
        /// <code>
        /// Communication comm = new Communication();
        /// comm.OpenPort("COM4:");
        /// </code>
        /// </example>
        /// Revision History
        /// MM/DD/YY who Version Issue# Description
        /// -------- --- ------- ------ ---------------------------------------
        /// 08/01/05 bdm 7.13.00 N/A	Created
        public void OpenPort(string portName)
        {
            byte[] abytReadBuf  = new Byte[m_uintRxBufSz];
            int    intBytesRead = 0;
            string strDesc;

            try
            {
                //Only support one port at a time.
                if (IsOpen)
                {
                    strDesc = string.Format(m_rmStrings.GetString("PORT_ALREADY_OPEN"));
                    throw (new Exception(strDesc));
                }

                m_strPortName = portName;

                Init();

                //This must be performed after the Init() and before the Open();
                m_portSettings = new HandshakeNone();

                Open();

                //Allow the open port response to be received by the buffer and
                //then ReadFile to remove any of the open port bytes received
                System.Threading.Thread.Sleep(100);

                PortAPI.ReadFile(m_hPort, abytReadBuf,
                                 m_uintRxBufSz, ref intBytesRead);

                m_abytRxBuf.Initialize();
                m_uintRxBufIx = 0;
            }
            catch (Exception e)
            {
                strDesc = string.Format(m_rmStrings.GetString("OPEN_PORT_FAILED"),
                                        e.Message);
                throw (new CommPortException(strDesc, e));
            }
        }