ComPortInterfaceSetting.prototype._ReadData_ = function()
{
	var ComPortDevice = $(".Form").eq(0).find(".Row").eq(0).find(".Select").val();
	if(typeof(Global_ComPort[ComPortDevice]) != "object")
	{
		Global_ComPort[ComPortDevice] = new Object();
		Global_ComPort[ComPortDevice]["BaudRate"]    = 115200;
		Global_ComPort[ComPortDevice]["DataBits"]    = 8;
		Global_ComPort[ComPortDevice]["Parity"]      = "None";
		Global_ComPort[ComPortDevice]["StopBits"]    = 1;
		Global_ComPort[ComPortDevice]["PollingRate"] = 500;
	}
	$("#SerialSetting").find(".Row").eq(0).find(".Select").eq(0).val(Global_ComPort[ComPortDevice]["BaudRate"]);
	$("#SerialSetting").find(".Row").eq(1).find(".Select").eq(0).val(Global_ComPort[ComPortDevice]["DataBits"]);
	$("#SerialSetting").find(".Row").eq(2).find(".Select").eq(0).val(Global_ComPort[ComPortDevice]["Parity"]);
	$("#SerialSetting").find(".Row").eq(3).find(".Select").eq(0).val(Global_ComPort[ComPortDevice]["StopBits"]);
	$("#SerialSetting").find(".Row").eq(4).find(".Text").eq(0).val(Global_ComPort[ComPortDevice]["PollingRate"]);
};

ComPortInterfaceSetting.prototype._WriteData_ = function()
{
	ComPortInterfaceSetting.prototype._CheckPollingRate_()
	var ComPortDevice = $(".Form").eq(0).find(".Row").eq(0).find(".Select").val();
	var BaudRate    = $("#SerialSetting").find(".Row").eq(0).find(".Select").eq(0).val();
	var DataBits    = $("#SerialSetting").find(".Row").eq(1).find(".Select").eq(0).val();
	var Parity      = $("#SerialSetting").find(".Row").eq(2).find(".Select").eq(0).val();
	var StopBits    = $("#SerialSetting").find(".Row").eq(3).find(".Select").eq(0).val();
	var PollingRate = $("#SerialSetting").find(".Row").eq(4).find(".Text").eq(0).val();
	if(typeof(Global_ComPort[ComPortDevice]) != "object")
	{
		Global_ComPort[ComPortDevice] = new Object();
	}
	Global_ComPort[ComPortDevice]["BaudRate"]    = parseInt(BaudRate);
	Global_ComPort[ComPortDevice]["DataBits"]    = parseInt(DataBits);
	Global_ComPort[ComPortDevice]["Parity"]      = Parity;
	Global_ComPort[ComPortDevice]["StopBits"]    = parseInt(StopBits);
	Global_ComPort[ComPortDevice]["PollingRate"] = parseInt(PollingRate);
};

ComPortInterfaceSetting.prototype._TransmissionJson_ = function(ssocket, Command, JsonString, Callback)
{
	var Length=20000, index=0;  var array = new Array("Start","");
	ssocket.emit(Command, array);	
	ssocket.on(Command, function (Return) {
		if(Return == "Start" || Return == "Send")
		{
			if(JsonString.length > (index+Length)){
				array = new Array("Send", JsonString.substring(index, index+Length));
			}
			else if(JsonString.length <= (index+Length)){
				array = new Array("End", JsonString.substring(index, JsonString.length));
			}
			index = index + Length;
			ssocket.emit(Command, array);
		}
		else if(Return == "End")
		{
			Callback();
		}
	});
};

ComPortInterfaceSetting.prototype._SaveFinished_ = function(that, ssocket)
{
	ssocket.emit("BackgroundExecution");
	ssocket.on("BackgroundExecution", function (Return) {
		if(Return == true)
		{
			$(that).closest('.Form').find(".Loading").hide();
			$(that).closest('.Form').find(".Message").eq(0).show();
		}
		else
		{
			$(that).closest('.Form').find(".Loading").hide();
			$(that).closest('.Form').find(".Message").eq(1).show();
		}
		ssocket.emit("SocketClose");
	});
}

ComPortInterfaceSetting.prototype._SaveComPortInterfaceSetting_ = function(that)
{
	$(that).closest('.Form').find(".Loading").show();
	$(that).closest('.Form').find(".Message").hide();

	var GetClass = new GetValue();
	var ssocket = GetClass.SocketIo();
	var Callback0 = function(){ComPortInterfaceSetting.prototype._SaveFinished_(that, ssocket);}
	var JsonString = JSON.stringify(Global_ComPort);
	ComPortInterfaceSetting.prototype._TransmissionJson_(ssocket, "SaveComPortSetting", JsonString, Callback0);
};

ComPortInterfaceSetting.prototype._ShowUi_ = function(that)
{
	var Result={"Input":null};
	ComPortInterfaceSetting.prototype._LoadComPortName_(Result);
	var SetInterval = setInterval(function()
	{
		if(Result["Input"] == true)
		{
			clearInterval(SetInterval);
			ComPortInterfaceSetting.prototype._ReadData_();
		}
	},500);
};

ComPortInterfaceSetting.prototype._LoadComPortName_ = function(Result)
{
	var Return={"Input":null};
	var Class = new LoadFile();
	Class.ReadFile("./File/ComPortInterfaceSetting.json", new Object(), Return);
	var SetInterval = setInterval(function()
	{
		if(Return["Input"] != null)
		{
			clearInterval(SetInterval);
			Class = null;
			var ComPort = Object.keys(Return["Input"] );
			var ComPortDevice = $(".Form").eq(0).find(".Row").eq(0).find(".Select");
			for(var i=0; i<ComPort.length; i++){
				ComPortDevice.append($("<option></option>").attr("value",ComPort[i]).text(ComPort[i]));
			}
			Result["Input"]=true;
		}
	},500);
}

ComPortInterfaceSetting.prototype._CheckPollingRate_ = function()
{
	var PollingRate = $("#SerialSetting").find(".Row").eq(4).find(".Text").eq(0).val();
	PollingRate = parseInt(PollingRate);
	var Class = new Type();
	if(Class.CheckPositiveIntegers(PollingRate) == false || 
	   PollingRate<20)
	{
		$("#SerialSetting").find(".Row").eq(4).find(".Text").eq(0).val(20);
	}
};