• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

MSFS Reading traffic information

Messages
531
Country
france
I am trying to read traffic information from MSFS and I use the Coherent.call("GET_AIR_TRAFFIC") that is used by Asobo and all mods.
As I am not very familiar with using Promises in JavaScript, I wrote a very simple code to test it was OK, something like this:

Coherent.call("GET_AIR_TRAFFIC").then((obj) => {
console.log("TRAFFIC : " + obj.length + " airplanes found");

});

As you see, it is extremely simple and just shows the number of airplanes found in the traffic, nothing more.
Unfortunately, whatever I do, I never get anything to show in the console, not only to say that 0 airplane were found. I just have nothing, as if my code was never executed because the promise is rejected.
Does any of you can tell me if something is wrong in my code?

Thanks,
Eric
 
Messages
244
Country
unitedkingdom
(necro alert) 2 suggestions: (1) can you confirm which 'console' you're using, (2) did you take the obj.length out of the print expression just in case that is crashing the code because obj doesn't have a length?
 
Messages
531
Country
france
Thank you for taking care of my question. The console is OK, the problem was somewhere else and it has been solved. It was because of a listener registration that was missing. My TCAS now works fine.
 

WebSimConnect

Resource contributor
Messages
154
Hi Eric,

Could you please explain how did you solve it ? I am facing similar problem. Many thx in advance.
 
Messages
531
Country
france
Sure.
Unless your instrument class is a subclass of a BingMap class (I don't remember the exact class name), you need to register a listener before using this coherent call, otherwise it doesn't work.
The code to register the listener is something like:

let listener = RegisterViewListener('JS_LISTENER_MAPS', () => {
listener.trigger('JS_BIND_BINGMAP', 'testMap', false);
});

Hope this will help.
Eric
 

WebSimConnect

Resource contributor
Messages
154
Many thanks Eric. It worked. Pity we do not have decent SDK but have to do reverse engineering ... reminds me FS9-FSX times.
 

=rk=

Resource contributor
Messages
4,450
Country
us-washington
Many thanks Eric. It worked. Pity we do not have decent SDK but have to do reverse engineering ... reminds me FS9-FSX times.
That is to be expected, since MSFS is reverse engineered from FSX. Interestingly enough, the very original version of FS was reverse engineered from it's developer, Bruce Artwick. He never provided Microsoft the code to decompile his .bgl format, just the tools to compile.
(.bgl = Bruce Artwick Organization Graphical Language)
 
Messages
244
Country
unitedkingdom
Hi Eric can you provide any more clues on when/whether to use the RegisterViewListener() call in general? Is that generally related to the Coherent.call() method or is it something you might need to do for other reasons (e.g. I'm using a MapInstrument in one of my divs, which is working ok, but there's no guarantee I spotted everything I could possibly need to know from inspecting the Asobo examples). Is RegisterViewListener a "Coherent" thing or an "Asobo" thing ? I'm using Coherent.call("GET_FLIGHTPLAN")

Reverse Engineering has a whole new meaning in MSFS with the colossal HTML/JS codebase - on the upside the code is publicly readable but it's uncommented and undocumented.
 
Messages
531
Country
france
Hi Eric can you provide any more clues on when/whether to use the RegisterViewListener() call in general? Is that generally related to the Coherent.call() method or is it something you might need to do for other reasons (e.g. I'm using a MapInstrument in one of my divs, which is working ok, but there's no guarantee I spotted everything I could possibly need to know from inspecting the Asobo examples). Is RegisterViewListener a "Coherent" thing or an "Asobo" thing ? I'm using Coherent.call("GET_FLIGHTPLAN")

Reverse Engineering has a whole new meaning in MSFS with the colossal HTML/JS codebase - on the upside the code is publicly readable but it's uncommented and undocumented.
I'm afraid I can't tell you much more about this. I am registering this listener in my class constructor and as far as I know this listener is necessary only for the traffic, which doesn't mean every coherent call requires a listener.

I had to use this listener because my class is a subclass of BaseAirliner but I think the listener is not necessary in the case of a Map Instrument, not sure...

Eric
 

WebSimConnect

Resource contributor
Messages
154
I am not sure if it is MSFS bug or done on purpose but if you switch from live traffic to AI traffic, the Coherent.call("GET_AIR_TRAFFIC") returns empty list. You can observe that on VFR map, while devtool shows the traffic objects, simconnects reads them as well, the VFR map is empty...
 

=rk=

Resource contributor
Messages
4,450
Country
us-washington
AI implementation is yet waay too buggy to suspect a nuanced dysfunctionality is intentional, imo.
 
Top