function Application()

	SMC:Log("debug", "Starting Application")

	while true
	do
		SMC:Log("debug", "Waiting");
		Wait(1000)
		SMC:Log("debug", "Back from waiting")
	end

end

function Wait(timeout)

	waitTimer = SMC:NewTimer("wait", timeout)

	while waitTimer ~= nil
	do
		coroutine.yield()

		if gasynch ~= nil then
			SMC:Log("debug", "reporting completion")
			gasynch:AppendOutput("output1")
			gasynch:AppendOutput("output2")
			gasynch:ReportComplete()
			gasynch:AppendOutput("output after complete")
			gasynch = nil
		end
	end 

end

function SMCReportSerialData(portName,data)

end

function SMCReportTimeout(timerName)

	SMC:Log("debug", "SMCReportTimeout timerName="..timerName)

	if timerName == "wait" then
		waitTimer = nil
		collectgarbage("collect")
		coroutine.resume(appRtn, nil)
	end

	SMC:Log("debug", "exiting SMCReportTimeout")

end

function T1()

	SMC:Log("debug", "SMC"..tostring(SMC))
	SMC:Log("debug", "SMCContext="..tostring(SMCContext))

	if (SMCContext ~= nil) then
		SMC:Log("debug", "setting asynch "..tostring(gasynch))
		gasynch = SMCContext
		gasynch:SetAsynch()
	end
end

function T2()
	return 13,34
end

function T3()
	return "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF\r\nGHIJKLMNOPQRSTUVWXYZ","ABCDEFGHIJKLMN\r\nOPQRSTUVWXYZ",34
end

function T4()
	return "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF\r\nGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
end

SMC:Log("debug", "Starting test2")

gasynch = nil

appRtn = coroutine.create(function()
	Application()
end)

coroutine.resume(appRtn)

