/// <summary>
        /// Method for removing modbus device - returns null if there is no device of given port and unitId
        /// </summary>
        /// <param name="port"></param>
        /// <param name="unitIdentifier"></param>
        /// <returns></returns>
        public static ModbusDevice RemoveDevice(Int32 port, byte unitIdentifier = 1)
        {
            var server = ModbusFactory.GetServer(port);

            if (server == null)
            {
                return(null);
            }

            var device = server.GetModbusDevice(unitIdentifier);

            if (device == null)
            {
                return(null);
            }

            server.RemoveModbusDevice(unitIdentifier);

            if (server.GetNumberOfModbusDevices() <= 0)
            {
                ModbusFactory.RemoveServer(port);
            }

            return(device);
        }
        /// <summary>
        /// Method for enabling device to communicate
        /// </summary>
        public void Enable()
        {
            if (!this.Enabled)
            {
                //Starting listening for server - method doesn't call listen if server is already listening
                ModbusFactory.StartListening(this.Port);

                this._enabled = true;
            }
        }
        /// <summary>
        /// Method for creating new device - returns existing one if device of given port and unitId exists
        /// </summary>
        /// <param name="port"></param>
        /// <param name="unitIdentifier"></param>
        /// <returns></returns>
        public static ModbusDevice CreateNewDevice(Int32 port, byte unitIdentifier = 1)
        {
            //Creating new modbus server - method for create returns exisitng one if server exists
            var server = ModbusFactory.CreateServer(port);

            //Creating new device - method for create returns exisitng one if device exists
            var device = server.CreateModbusDevice(unitIdentifier);

            return(device);
        }
        /// <summary>
        /// Method for disabling device to communicate
        /// </summary>
        public void Disable()
        {
            if (this.Enabled)
            {
                //Stopping server communication if this the device is the only one that listens
                if (ModbusFactory.GetNumberOfEnabledDevices(this.Port) <= 1)
                {
                    ModbusFactory.StopListening(this.Port);
                }

                this._enabled = false;
            }
        }
        /// <summary>
        /// Method for getting modbus device - returns null if there is no device of given port and unitId
        /// </summary>
        /// <param name="port"></param>
        /// <param name="unitIdentifier"></param>
        /// <returns></returns>
        public static ModbusDevice GetDevice(Int32 port, byte unitIdentifier = 1)
        {
            var server = ModbusFactory.GetServer(port);

            if (server == null)
            {
                return(null);
            }

            var device = server.GetModbusDevice(unitIdentifier);

            return(device);
        }