Example #1
0
        /// <summary>
        /// Initialize connection
        /// </summary>
        /// <param name="PortConfguration">Configuration of serial port</param>
        public void Initialize(SerialPortConfigurationMaster PortConfguration)
        {
            // Save parameters
            m_TimeoutSync           = PortConfguration.TimeoutForSyncReceive;
            m_TimeoutSyncStream     = PortConfguration.TimeoutForSyncStreamReceive;
            m_RetransmitsOnErrCount = (PortConfguration.RetransmitsCountOnError > 0)
                                          ? PortConfguration.RetransmitsCountOnError
                                          : 0;
            m_RetransmitsOnErrCountForArrays = (PortConfguration.UseRetransmitsForArrays)
                                                   ? m_RetransmitsOnErrCount
                                                   : 0;
            m_CatchTimeouts = PortConfguration.RetransmitOnTimeout;

            // Open port
            OpenConnection(PortConfguration);
        }
Example #2
0
        private void OpenConnection(SerialPortConfigurationMaster PortConfguration)
        {
            m_Port = new SerialPort(@"COM" + PortConfguration.PortNumber, PortConfguration.BaudRate,
                                    PortConfguration.ParityMode, PortConfguration.DataBits,
                                    PortConfguration.StopBits)
            {
                ReceivedBytesThreshold = 1
            };

            m_Port.DataReceived += PortDataReceived;

            try
            {
                m_Port.Open();
            }
            catch (Exception e)
            {
                throw new SerialConnectionException(string.Format(Resources.SCCIMasterAdapter_Communication_exception, e.Message), e);
            }
        }