How to log from instrument code

Support for Air Player desktop.

Moderators: russ, Ralph

Message
Author
Tetrachromat
Posts: 236
Joined: Sun Feb 14, 2021 6:55 pm

How to log from instrument code

#1 Post by Tetrachromat »

How do I write some output for logging from instrument code running in Air Player?

Where do the print statements output go? Is there some kind of console? Or do I need to write to files?

Paul

lonespace
Posts: 64
Joined: Wed Mar 25, 2020 1:58 am

Re: How to log from instrument code

#2 Post by lonespace »

If you just want to print some statements to the console located on the instrument edit screen, you can simply use print().

If you want to log data for further analysis, give this page a read: https://siminnovations.com/wiki/index.php?title=Log

That logs to the air manager log file.

Tetrachromat
Posts: 236
Joined: Sun Feb 14, 2021 6:55 pm

Re: How to log from instrument code

#3 Post by Tetrachromat »

I do know the log() function. But it's output goes to file. For testing I need something like a console to observe the output while the code is running. A file I can only consult after the test has ended.

The console in Air Manager does not show output from instruments running in Air Player. And it only shows the output from running single instruments in edit mode. As far as I have observed.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: How to log from instrument code

#4 Post by Keith Baxter »

Hi,

You can write to a persist file and display the text. Wrapping the text is a feature asked for and hidden at the bottom of the SI dev teams TODO list.

I use this method to record events like a "BLACK BOX" recorder where text wrapping is not required.


Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

Tetrachromat
Posts: 236
Joined: Sun Feb 14, 2021 6:55 pm

Re: How to log from instrument code

#5 Post by Tetrachromat »

By writing to persist file you mean to use the persist_add and _put function, right?

But what do you mean by 'display the text'?
If you hint at text_add and text_set?

Tetrachromat
Posts: 236
Joined: Sun Feb 14, 2021 6:55 pm

Re: How to log from instrument code

#6 Post by Tetrachromat »

Maybe I need to explain the background. I'm currently exploring the new feature 'Game Controller'. I created some instruments to receive controller inputs and send events to the simulator.

The instrument do not have any nodes (images, text etc.) and will be contained in a panel that is not displayed.

For prototyping a single instrument I use console in Air Manager output looks like :

Code: Select all

INFO - Game Controller added: Saitek X52 Pro Flight Control System
INFO - Game controller callback with type = 0, index = 2, input = 1.0
INFO - AXIS_THROTTLE1_SET = -16383
INFO - Game controller callback with type = 0, index = 4, input = -1.0000305175781
INFO - AXIS_PROPELLER1_SET = 16383
INFO - Game controller callback with type = 0, index = 5, input = 0.023804437369108
INFO - AXIS_MIXTURE1_SET = 389
When testing the final panel with 3 instruments running in Air Player, I do not have such a console.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: How to log from instrument code

#7 Post by Keith Baxter »

Hi,

To log immediate data use tables. Create a table <my_table={}>

then
table.insert(my_table,value) Look up LUA on tables and how to do this.

You can use this table to display data.

If you want to save the data for "After event" retrieval use persist.

Keith

EDIT: I use this technique to list alerts and display in a list . Example is for the alerts for the bell 407

Code: Select all

function callback_w_cas(batH,fire,EoilT,EoilP,Eout,rpm,fadec,xmsnp,xmsnt,ap,ap_trim,baggage,Echip,oilpH,mgt_ex,float_arm,fuelQ,hydr,xfrL,xfrR,gen,ignit,antiice,wog,Q,nr1,np1,ng1,mgt1,Pstop,igw)

local casW_list ={}
	if batH ==1                 then table.insert(casW_list,bell_casW_alerts[1])end --BATTERY HOT
	if fire[1] ==1              then table.insert(casW_list,bell_casW_alerts[2])end --ENGINE FIRE
	if EoilT[1] ==1             then table.insert(casW_list,bell_casW_alerts[3])end --ENGINE OIL HOT
	if EoilP[1] ==1             then table.insert(casW_list,bell_casW_alerts[4])end --ENGIN OIL PSI LOW
	if Eout ==1                 then table.insert(casW_list,bell_casW_alerts[5])end --ENGINE OUT
	if rpm >=102.1              then table.insert(casW_list,bell_casW_alerts[6])end --ENGINE OVERSPEED
	if fadec == 1               then table.insert(casW_list,bell_casW_alerts[7])end --FADEC FAIL
	if xmsnp <=3                then table.insert(casW_list,bell_casW_alerts[8])end --XMSN OIL PRESS
	if xmsnt >= 11              then table.insert(casW_list,bell_casW_alerts[9])end --XMSN OIL TEMP
	
local casC_list ={}				
--	if 							then table.insert(casC_list,bell_casC_alerts[1])end --AP DEGRADED
	if 	ap ~= 0 				then table.insert(casC_list,bell_casC_alerts[2])end --AP FAILED
	if 	ap_trim	~= 0			then table.insert(casC_list,bell_casC_alerts[3])end --AUTOTRIM
	if 	baggage >= 0.1			then table.insert(casC_list,bell_casC_alerts[4])end --BAGGAGE DOOR
--	if 				            then table.insert(casC_list,bell_casC_alerts[5])end	--BATTERY RLY
	if 	Echip[1] ~= 0	 		then table.insert(casC_list,bell_casC_alerts[6])end	--ENGINE CHIP
--	if 							then table.insert(casC_list,bell_casC_alerts[7])end	--ENG FUEL FILTER
--	if 							then table.insert(casC_list,bell_casC_alerts[8])end	--ENG OIL FILTER
	if oilpH[1] >= 140			then table.insert(casC_list,bell_casC_alerts[9])end	--ENG OIL PSI HI
	if mgt_ex == 1				then table.insert(casC_list,bell_casC_alerts[10])end --ENGINE MGT	
--	if 							then table.insert(casC_list,bell_casC_alerts[11])end --FADEC BEC
--	if 							then table.insert(casC_list,bell_casC_alerts[12])end --FADEC DEGRADED
	if float_arm == 1			then table.insert(casC_list,bell_casC_alerts[13])end --FLOAT ARM
	if fuelQ*100 <=110			then table.insert(casC_list,bell_casC_alerts[14])end --FUEL LOW
--	if 							then table.insert(casC_list,bell_casC_alerts[15])end --FUEL VALVE
	if gen == 1 				then table.insert(casC_list,bell_casC_alerts[16])end --GEN FAIL
--	if 							then table.insert(casC_list,bell_casC_alerts[17])end --HEATER OVERTEMP
	if hydr	== 1				then table.insert(casC_list,bell_casC_alerts[18])end --HYDRAULIC SYS
--	if 							then table.insert(casC_list,bell_casC_alerts[19])end --L/FUEL BOOST
	if xfrL == 0				then table.insert(casC_list,bell_casC_alerts[20])end --L/FUEL XFR
--	if 							then table.insert(casC_list,bell_casC_alerts[21])end --LITTER DOOR
	if mgt1*100 >= 780			then table.insert(casC_list,bell_casC_alerts[22])end --MGT EXCEED
	if ng1*10 >= 104			then table.insert(casC_list,bell_casC_alerts[23])end --NG EXCEED
--	if 							then table.insert(casC_list,bell_casC_alerts[24])end --NR MISCOMP
	if nr1/4.13 >= 118			then table.insert(casC_list,bell_casC_alerts[25])end --NR EXCEED
	if Pstop == 0				then table.insert(casC_list,bell_casC_alerts[26])end --PEDAL STOP
	if 	Q/100*0.865 >=102.7		then table.insert(casC_list,bell_casC_alerts[27])end --Q EXCEED
--	if 							then table.insert(casC_list,bell_casC_alerts[28])end --Q MISCOMP
--	if 							then table.insert(casC_list,bell_casC_alerts[29])end --R/FUEL BOOST
	if xfrR == 0				then table.insert(casC_list,bell_casC_alerts[30])end --R/FUEL XFR	
--	if 							then table.insert(casC_list,bell_casC_alerts[31])end --SLIDING DOOR
--	if 							then table.insert(casC_list,bell_casC_alerts[32])end --T/R CHIP
--	if 							then table.insert(casC_list,bell_casC_alerts[33])end --XMSN CHIP

local casA_list ={}
--	if 							then table.insert(casA_list,bell_casA_alerts[1])end --ALTN DATA FAIL
	if ignit[1] == 1			then table.insert(casA_list,bell_casA_alerts[2])end --AUTO RELIGHT
	if antiice == 1				then table.insert(casA_list,bell_casA_alerts[3])end --ENG ANTI-ICE
--	if 							then table.insert(casA_list,bell_casA_alerts[4])end --ENG FUEL FILT
--	if 							then table.insert(casA_list,bell_casA_alerts[5])end	--ENG MISCOMP
--	if 							then table.insert(casA_list,bell_casA_alerts[6])end	--FADEC CHAN FAIL
--	if 							then table.insert(casA_list,bell_casA_alerts[7])end	--FADEC MAINT
--	if 							then table.insert(casA_list,bell_casA_alerts[8])end	--INST FAN
--	if 							then table.insert(casA_list,bell_casA_alerts[9])end	--NG OAT LIMIT
--	if 							then table.insert(casA_list,bell_casA_alerts[10])end --QUITE MODE SEL
--	if 							then table.insert(casA_list,bell_casA_alerts[11])end --RESTART FAULT
--	if 							then table.insert(casA_list,bell_casA_alerts[12])end --START

local casS_list ={}
--	if 							then table.insert(casS_list,bell_casS_alerts[1])end --FLOAT TEST
	if igw*2.20462 >=5000		then table.insert(casS_list,bell_casS_alerts[2])end --IGW VNE
--	if 							then table.insert(casS_list,bell_casS_alerts[3])end --QUITE MODE ON
	if wog[1] == 1				then table.insert(casS_list,bell_casS_alerts[4])end --WOG

canvas_draw(cas_alerts_bell407, function()

	if casW_list ~= nil then 
		for i = 1, #casW_list do	
			_rect(225,115+(i*20),190,20)
			_fill("red")
			_txt(casW_list[i],robR_20witL,230,125+(i*20))
		end	
	end

	if casC_list ~= nil then	
		for i = 1, #casC_list do	
			_txt(casC_list[i],robR_20yelL,230,125 + (#casW_list*20)+(i*20))
		end
	end	

	if casA_list ~= nil then	
		for i = 1, #casA_list do	
			_txt(casA_list[i],robR_20witL,230,125 + (#casW_list*20)+(#casC_list*20)+(i*20))
		end
	end	

	if casS_list ~= nil then	
		for i = 1, #casS_list do	
			_txt(casS_list[i],robR_20grnL,230,125 + (#casW_list*20)+(#casC_list*20)+(#casA_list*20)+(i*20))
		end
	end	
end)
end
The refering alerts are...
But you can use self generated tables if you want.

Code: Select all

---Bell407 alerts
bell_casW_alerts={"BATTERY HOT","ENGINE FIRE","ENGINE OIL HOT","ENGIN OIL PSI LOW","ENGINE OUT","ENGINE OVERSPEED","FADEC FAIL","XMSN OIL PRESS","XMSN OIL TEMP"}
bell_casC_alerts={"AP DEGRADED","AP FAILED","AUTOTRIM","BAGGAGE DOOR","BATTERY RLY","ENGINE CHIP","ENG FUEL FILTER","ENG OIL FILTER","ENG OIL PSI HI","ENGINE MGT","FADEC BEC","FADEC DEGRADED","FLOAT ARM","FUEL LOW","FUEL VALVE","GEN FAIL","HEATER OVERTEMP","HYDRAULIC SYS","L/FUEL BOOST","L/FUEL XFR","LITTER DOOR","MGT EXCEED","NG EXCEED","NR MISCOMP","NR EXCEED","PEDAL STOP","Q EXCEED","Q MISCOMP","R/FUEL BOOST","R/FUEL XFR","SLIDING DOOR","T/R CHIP","XMSN CHIP"}
bell_casA_alerts={"ALTN DATA FAIL","AUTO RELIGHT","ENG ANTI-ICE","ENG FUEL FILT","ENG MISCOMP","FADEC CHAN FAIL","FADEC MAINT","INST FAN","NG OAT LIMIT","QUITE MODE SEL","RESTART FAULT","START"}
bell_casS_alerts={"FLOAT TEST","IGW VNE","QUITE MODE ON","WOG"}
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: How to log from instrument code

#8 Post by Keith Baxter »

Hi,

LUA is extremely powerful when it comes to tables. Under used in most cases.

I did a "BLACK BOX" instrument some time back that wrote events to a table. I could then recall the events saved to persist.

Issue was AM would CTD due to the huge file size when storing.

Keith
Last edited by Keith Baxter on Sat Jun 26, 2021 10:01 pm, edited 1 time in total.
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

Tetrachromat
Posts: 236
Joined: Sun Feb 14, 2021 6:55 pm

Re: How to log from instrument code

#9 Post by Tetrachromat »

Thank you for the sample. Can I write a table from one instrument and read it from another instrument? It would have to be a global object. Or is that table local to an instrument?

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: How to log from instrument code

#10 Post by Keith Baxter »

Tetrachromat wrote: Sat Jun 26, 2021 9:59 pm Thank you for the sample. Can I write a table from one instrument and read it from another instrument? It would have to be a global object. Or is that table local to an instrument?
I have not tried that.

Tony @Sling might know if the data can be transferred via Inter-instrument communication.

It is a Var but how much data could be stored in that var I do not know.

You might be able to record data in one instrument and save it to another instrument....not sure

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

Post Reply