/// <summary>
        /// Initialize the communication port.
        /// </summary>
        /// <param name="communicationsSetting">The communication settings.</param>
        /// <exception cref="CommunicationException">Thrown if the error code returned from the call to the PTUDLL32.InitCommunication() method is
        /// not CommunicationError.Success.</exception>
        public virtual void InitCommunication(CommunicationSetting_t communicationsSetting)
        {
            Int32 error = -1;

            CommunicationError errorCode = CommunicationError.UnknownError;
            try
            {
                String args = "";

                if (communicationsSetting.Protocol == Protocol.RS232)
                {
                    m_CommDevice = new Serial();

                    args = "COM" + communicationsSetting.PortIdentifier + "," +
                            ((Int32)communicationsSetting.SerialCommunicationParameters.BaudRate).ToString() + "," + 
                            communicationsSetting.SerialCommunicationParameters.Parity.ToString() + "," + 
                            ((Int32)communicationsSetting.SerialCommunicationParameters.BitsPerCharacter).ToString() + "," +
                            ((Int32)communicationsSetting.SerialCommunicationParameters.StopBits).ToString();


                }
                else if (communicationsSetting.Protocol == Protocol.TCPIP)
                {
                    m_CommDevice = new TCP();
                    args = communicationsSetting.PortIdentifier;
                }

                if (m_CommDevice != null)
                {
                    error = m_CommDevice.Open(args);
                }
            }
            catch (Exception)
            {
                errorCode = CommunicationError.SystemException;
                throw new CommunicationException(Resources.EMPortInitializationFailed, errorCode);
            }

            if (DebugMode.Enabled == true)
            {
                DebugMode.InitCommunication_t initCommunication =
                    new DebugMode.InitCommunication_t(communicationsSetting.Protocol,
                                                      communicationsSetting.PortIdentifier,
                                                      communicationsSetting.SerialCommunicationParameters.BaudRate,
                                                      communicationsSetting.SerialCommunicationParameters.BitsPerCharacter,
                                                      communicationsSetting.SerialCommunicationParameters.Parity,
                                                      communicationsSetting.SerialCommunicationParameters.StopBits,
                                                      errorCode);
                DebugMode.Write(initCommunication.ToXML());
            }

            if (error >= 0)
            {
                errorCode = CommunicationError.Success;
                m_WatchClockMarshal = new WatchClockMarshal(m_CommDevice);
            }

            if (errorCode != CommunicationError.Success)
            {
                throw new CommunicationException(Resources.EMPortInitializationFailed, errorCode);
            }
        }
 /// <summary>
 /// Initialize a new instance of the class and set the function delegates, properties and member variables.
 /// </summary>
 /// <param name="communicationInterface">Reference to the communication interface containing the properties and member variables that are to
 /// be used to initialize the class.</param>
 public CommunicationParent(ICommunicationParent communicationInterface)
     : this()
 {
     m_CommunicationSetting = communicationInterface.CommunicationSetting;
     m_CommDevice = communicationInterface.CommDevice;
     m_WatchClockMarshal = communicationInterface.WatchClockMarshall;
 }