#include "TPT.h"


BOOL                OpenStuff(UBYTE * sername, UBYTE serunit, ULONG serflags, UBYTE * controlname)
{
	BadFlag = TRUE;
	SERGOOD = TRUE;

	tptflags = T_CRLF | T_BREAK | T_DO_TIMEOUT | T_PAUSE;
	time_delay = 24;
	num_kills = 0;

	ctrl_port = CreateMsgPort();

	if (ctrl_port)
	{
		ctrl_port->mp_Node.ln_Name = controlname;
		AddPort(ctrl_port);
		controlsig = CONTROL_SIG;

		if (OpenLibs())
		{
			if(!OpenSer(sername,serunit,serflags)) SERGOOD = FALSE;

			if (localflag || SERGOOD)
			{
				if (OpenTimer())
				{
					if (!localflag || SERGOOD)
					{
						set_read();
					}

					tptflags |= T_SER_TIMEOUT;
					return (TRUE);
				}
			}

			CloseSer();
		}

		CloseLibs();
	}

	ClosePorts();
	return (FALSE);
}

void                ClosePorts(void)
{
	if (ctrl_port)
	{
		RemPort(ctrl_port);
		DeleteMsgPort(ctrl_port);
	}

	ctrl_port = NULL;
}


