       {:reply, {:error, :eagain}, state}
     else
       log_path = Path.expand(Keyword.get(opts, :log_path, @default_log_path))
-      sample_rate = Keyword.get(opts, :sample_rate, @default_sample_rate)
-
-      case set_up(port, log_path, sample_rate) do
+      period = Keyword.get(opts, :period, @default_period)
+
+      case set_up(port, log_path, period) do
         {:ok, settings} ->
           new_state = Map.put(state, port, settings)
           {:reply, :ok, new_state}

    end
  end

  defp calculate_upper_limit(sample_rate) when sample_rate < @period do
    {:error, :sample_rate_less_than_period}
  end

  defp calculate_upper_limit(sample_rate) when rem(sample_rate, @period) != 0 do
    {:error, :sample_rate_not_multiple_of_period}
  end

  defp calculate_upper_limit(sample_rate) do
    upper_limit = div(sample_rate, @period)
    {:ok, upper_limit}
  end


    Logger.remove_backend({LoggerFileBackend, path})
  end

  defp generate_settings(log_path, period) do
    case calculate_upper_limit(period) do
      {:ok, upper_limit} ->
        settings = %{
          log_path: log_path,
          period: period,
          lower_limit: 0,
          upper_limit: upper_limit,
          count: 0,
