//	M510 : VA|[gāAeLXgf[^̑M

define	port 	= 0;
define	$InpTxt = "";

function main()
{
	//	{^\
	_BtnOpen(0, "|[gݒ");
	_BtnOpen(1, "M");
	_BtnOpen(2, "I");

	_BtnEnable(1, _FALSE);

	_Cls();

	_Stop();

	/*	\[Xj					*/
	_BtnClose(0); _BtnClose(1); _BtnClose(2);
	if (port != 0) {
		_ComClose (port);
		_ComDelete(port);
	}
}

//	{^ECxg
function _OnButton(BtnNo)
{
	define	$txt;

	if		(BtnNo == 0) {				//	u|[gݒv{^
		if (port = _ComCreateByDialog(port)) {
			_ComSetOnRxText(port, "OnRxText");
			_ComSetOnRxCtrl(port, "OnRxCtrl");
			if (!_ComIsOpened(port) && _ComIsOpenPossible(port)) {
				_ComOpen(port);
				_BtnEnable(1, _TRUE);
			}
		}
	}
	else if (BtnNo == 1) {				//	uMv{^
		if ($InpTxt = $_Input("MeLXg͂Ă", $InpTxt)) {
			_ComSendText(port, $_StrCat($InpTxt, "\n"));
			_PrintF("--> '%s'\n", $InpTxt);
		}
	}
	else if (BtnNo == 2) _Restart();	//	uIv{^
}

//	eLXgMCxg
function  OnRxText($Text)
{
	_PrintF("<-- '%s'", $Text);
}

//	R[hMCxg
function  OnRxCtrl(ctrl)
{
	_PrintF("%c", ctrl);
}
