anchor.diff:  	    {error, Reason}
       end.
   
  -loop(Parent, Port, Cmd) ->
  +loop(Parent, #state{port=Port}=S) ->
       _ = send_heart_beat(Port),
       receive
   	{From, set_cmd, NewCmd0} ->
  
positive.code: 	    exit(normal)
      end.
  
  do_cycle_port_program(Caller, Parent, Port, Cmd) ->
      unregister(?HEART_PORT_NAME),
      case catch start_portprogram() of
  	{ok, NewPort} ->
  	    _ = send_shutdown(Port),
  	    receive
  		{'EXIT', Port, _Reason} ->
  		    _ = send_heart_cmd(NewPort, Cmd),
  		    Caller ! {heart, ok},
  		    loop(Parent, NewPort, Cmd)
  	    after
  		?CYCLE_TIMEOUT ->
  		    %% Huh! Two heart port programs running...
  		    %% well, the old one has to be sick not to respond
  		    %% so we'll settle for the new one...
  		    _ = send_heart_cmd(NewPort, Cmd),
  		    Caller ! {heart, {error, stop_error}},
  		    loop(Parent, NewPort, Cmd)
  	    end;
  	no_heart ->
  	    Caller ! {heart, {error, no_heart}},
  	    loop(Parent, Port, Cmd);
  	error ->
  	    Caller ! {heart, {error, start_error}},
  	    loop(Parent, Port, Cmd)
      end.
      
  
  
negative.code: 		    _ = send_heart_cmd(Port, NewCmd),
  		    _ = wait_ack(Port),
  		    From ! {heart, ok},
  		    loop(Parent, S#state{cmd=NewCmd});
  		_ ->
  		    From ! {heart, {error, {bad_cmd, NewCmd0}}},
  		    loop(Parent, S)
  	    end;
  	{From, clear_cmd} ->
  	    From ! {heart, ok},
  	    _ = send_heart_cmd(Port, []),
  	    _ = wait_ack(Port),
  	    loop(Parent, S#state{cmd = []});
  	{From, get_cmd} ->
  	    From ! {heart, get_heart_cmd(Port)},
              loop(Parent, S);
  	{From, cycle} ->
  	    %% Calls back to loop
  	    do_cycle_port_program(From, Parent, S);
  	{'EXIT', Parent, shutdown} ->
  	    no_reboot_shutdown(Port);
  	{'EXIT', Parent, Reason} ->
  	    exit(Port, Reason),
  	    exit(Reason);
  	{'EXIT', Port, badsig} ->  % we can ignore badsig-messages!
  	    loop(Parent, S);
  	{'EXIT', Port, _Reason} ->
  	    exit({port_terminated, {heart, loop, [Parent, S]}});
  	_ -> 
  	    loop(Parent, S)
      after
  	?TIMEOUT ->
  	    loop(Parent, S)
      end.
  
  -spec no_reboot_shutdown(port()) -> no_return().
  