fix service
This commit is contained in:
parent
678b8cf928
commit
d9d8e6b53c
@ -77,12 +77,8 @@ start_link(AST = #ast{}) ->
|
||||
%% @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
|
||||
%% process to initialize.
|
||||
init([AST = #ast{modbus = Modbus = #modbus{transport = Transport}, devices = Devices}]) ->
|
||||
init([AST = #ast{modbus = Modbus = #modbus{error_log = ErrorLog, access_log = AccessLog}, devices = Devices}]) ->
|
||||
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),
|
||||
@ -96,10 +92,8 @@ init([AST = #ast{modbus = Modbus = #modbus{transport = Transport}, devices = Dev
|
||||
|
||||
lager:debug("device pid: ~p", [DevicesMap]),
|
||||
|
||||
%{ok, AccessLogPid} = modbus_logger:start_link(AccessLog),
|
||||
%{ok, ErrorLogPid} = modbus_logger:start_link(ErrorLog),
|
||||
|
||||
{ok, ?DISCONNECTED, #state{ast = AST, queue = queue:new(), packet_id = 1, devices_map = DevicesMap}}.
|
||||
{ok, ?DISCONNECTED, #state{ast = AST, access_log_pid = create_log_file(AccessLog), error_log_pid = create_log_file(ErrorLog),
|
||||
queue = queue:new(), packet_id = 1, devices_map = DevicesMap}}.
|
||||
|
||||
%% @private
|
||||
%% @doc This function is called by a gen_statem when it needs to find out
|
||||
@ -242,4 +236,10 @@ frame_delay(BaudRate, DataBits, Parity, StopBits) when is_integer(BaudRate), is_
|
||||
erlang:ceil((3500 * CharBits) / BaudRate * 1.2).
|
||||
|
||||
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) ->
|
||||
{ok, FilePid} = modbus_logger:start_link(FileName),
|
||||
FilePid.
|
||||
Loading…
x
Reference in New Issue
Block a user