Compare commits
No commits in common. "18723bdb0d01cca09b1010c94d78226419d0c60f" and "678b8cf9280761af922624adacf273bade1e1298" have entirely different histories.
18723bdb0d
...
678b8cf928
@ -48,13 +48,9 @@ start_link(FileName) when is_list(FileName) ->
|
|||||||
{stop, Reason :: term()} | ignore).
|
{stop, Reason :: term()} | ignore).
|
||||||
init([FileName]) ->
|
init([FileName]) ->
|
||||||
ensure_dir(filename:dirname(FileName)),
|
ensure_dir(filename:dirname(FileName)),
|
||||||
case file:open(FileName, [append, binary]) of
|
{ok, IoDevice} = file:open(FileName, [append, binary]),
|
||||||
{ok, IoDevice} ->
|
|
||||||
{ok, #state{file = IoDevice, file_name = FileName}};
|
{ok, #state{file = IoDevice, file_name = FileName}}.
|
||||||
{error, Reason} ->
|
|
||||||
lager:warning("[modbus_logger] create log file: ~p, error: ~p", [FileName, Reason]),
|
|
||||||
ignore
|
|
||||||
end.
|
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
%% @doc Handling call messages
|
%% @doc Handling call messages
|
||||||
|
|||||||
@ -77,8 +77,12 @@ start_link(AST = #ast{}) ->
|
|||||||
%% @doc Whenever a gen_statem is started using gen_statem:start/[3,4] or
|
%% @doc Whenever a gen_statem is started using gen_statem:start/[3,4] or
|
||||||
%% gen_statem:start_link/[3,4], this function is called by the new
|
%% gen_statem:start_link/[3,4], this function is called by the new
|
||||||
%% process to initialize.
|
%% process to initialize.
|
||||||
init([AST = #ast{modbus = Modbus = #modbus{error_log = ErrorLog, access_log = AccessLog}, devices = Devices}]) ->
|
init([AST = #ast{modbus = Modbus = #modbus{transport = Transport}, devices = Devices}]) ->
|
||||||
lager:debug("modbus is: ~p", [Modbus]),
|
lager:debug("modbus is: ~p", [Modbus]),
|
||||||
|
Device = hd(Devices),
|
||||||
|
lager:debug("devices is: ~p", [Device#modbus_device.metrics]),
|
||||||
|
% Res = connect(Transport),
|
||||||
|
% lager:debug("connect res: ~p", [Res]),
|
||||||
|
|
||||||
%% 建立连接
|
%% 建立连接
|
||||||
erlang:start_timer(0, self(), modbus_connect),
|
erlang:start_timer(0, self(), modbus_connect),
|
||||||
@ -92,8 +96,10 @@ init([AST = #ast{modbus = Modbus = #modbus{error_log = ErrorLog, access_log = Ac
|
|||||||
|
|
||||||
lager:debug("device pid: ~p", [DevicesMap]),
|
lager:debug("device pid: ~p", [DevicesMap]),
|
||||||
|
|
||||||
{ok, ?DISCONNECTED, #state{ast = AST, access_log_pid = create_log_file(AccessLog), error_log_pid = create_log_file(ErrorLog),
|
%{ok, AccessLogPid} = modbus_logger:start_link(AccessLog),
|
||||||
queue = queue:new(), packet_id = 1, devices_map = DevicesMap}}.
|
%{ok, ErrorLogPid} = modbus_logger:start_link(ErrorLog),
|
||||||
|
|
||||||
|
{ok, ?DISCONNECTED, #state{ast = AST, queue = queue:new(), packet_id = 1, devices_map = DevicesMap}}.
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
%% @doc This function is called by a gen_statem when it needs to find out
|
%% @doc This function is called by a gen_statem when it needs to find out
|
||||||
@ -237,13 +243,3 @@ frame_delay(BaudRate, DataBits, Parity, StopBits) when is_integer(BaudRate), is_
|
|||||||
|
|
||||||
retry_connect() ->
|
retry_connect() ->
|
||||||
erlang:start_timer(5000, self(), modbus_connect).
|
erlang:start_timer(5000, self(), modbus_connect).
|
||||||
|
|
||||||
create_log_file(undefined) ->
|
|
||||||
undefined;
|
|
||||||
create_log_file(FileName) ->
|
|
||||||
case modbus_logger:start_link(FileName) of
|
|
||||||
{ok, FilePid} ->
|
|
||||||
FilePid;
|
|
||||||
_ ->
|
|
||||||
undefined
|
|
||||||
end.
|
|
||||||
Loading…
x
Reference in New Issue
Block a user