Jason Fayre Posted July 26, 2020 Report Posted July 26, 2020 Hi Paul, I'm wondering if we might be able to get a function for parsing simconnect menus with the dll? One of the functions of my software is to read simconnect messages and menus via text to speech. For example, something like the menus that GSX displays. Multi-line messages are split by null characters, and the length of the message is stored in another offset. These offset start at 0xb000. Just wondering if we might get a convenience function to parse the messages into an array of strings. If not, have you found an easy way of dealing with these?
Paul Henty Posted July 26, 2020 Report Posted July 26, 2020 Hi Jason, I've added a new class called TextMenu in Version 3.1.17 to handle this. Now available on NuGet. To use this, create a new instance of TextMenu: private TextMenu textMenu = new TextMenu(); To get the last text/menu displayed on screen call RefreshData() and then get the text from various properties: this.textMenu.RefreshData(); if (this.textMenu.Changed) // Check if the text/menu is different from the last time we called RefreshData() { this.lblDuration.Text = this.textMenu.Duration.ToString(); // The number of seconds the message will stay on the screen this.lblID.Text = this.textMenu.ID.ToString(); // The ID of the SimConnect event that created this message if (this.textMenu.IsMenu) // Check if it's a menu (true) or a simple message (false) { // Display different parts of the menu dialog this.txtTitle.Text = this.textMenu.MenuTitleText; // The title bar of the menu dialog this.txtPrompt.Text = this.textMenu.MenuPromptText; // The prompt text (text above the first menu option this.lstMenuItems.Items.Clear(); foreach (string line in this.textMenu.MenuItems) // MenuItems is an array of strings, one string per item { this.lstMenuItems.Items.Add(line); } this.lblLineCount.Text = this.textMenu.MenuItemCount.ToString(); // Number of menu items } else { // Display message this.txtMessage.Text = this.textMenu.Message; } } The ToString() method will also give you back all entire menu text as a single string. this.txtCompleteString.Text = this.textMenu.ToString(); There is also an overload on ToString() that give you more control. The parameters are: RowDelimiter - A string that will be used to mark the end of each row IncludeMenuTitle - Pass true to include the title of the menu in the string IncludeMenuPrompt - Pass true to include the menu prompt in the string AddNumbersToMenuItem - Pass true to automatically add numbers to the menu items The plain ToString() method defaults everything to 'true' with a delimiter of "/r/n" (VbCrLf in VB.NET). To make this work I had to change my FSUIPC4.INI file: NewInterceptTextMenu=Yes It was set to No. I've tested here with a demo of GSX. Paul
Jason Fayre Posted July 26, 2020 Author Report Posted July 26, 2020 Wow this is brilliant! Thank you so much! Interestingly, you got this to work on fsuipc 4? I've been having trouble getting simconnect messages to work under fsuipc 4 with fsx. They work in prepar3d version 4 with fsuipc 5 though. This was with the older python version of my software that I'm porting over to .net.
Paul Henty Posted July 26, 2020 Report Posted July 26, 2020 You're welcome. Yes it's working here on FSUIPC4 with FSX Steam Edition. Requirements are: Registered FSUIPC version 4.924 and later FSX Acceleration and SP2, or P3D version 2 and above NewInterceptTextMenu=Yes (or =Full) in the FSUIPC ini file. Paul
Jason Fayre Posted July 26, 2020 Author Report Posted July 26, 2020 Ok great. Just to be clear, your not running this over WideFS right? I think there were some issues where these offsets worked over widefs, but not locally.
Paul Henty Posted July 26, 2020 Report Posted July 26, 2020 Quote Just to be clear, your not running this over WideFS right? No, everything is running on the same machine.
Delphi Posted July 28, 2020 Report Posted July 28, 2020 On 7/26/2020 at 5:04 PM, Paul Henty said: NewInterceptTextMenu=Yes Hi Paul, do you know whether this is required for FSUIPC6 too? I asks, because I could not find this entry in FSUIPC6. Kind regards, Ruediger
Paul Henty Posted July 28, 2020 Report Posted July 28, 2020 Sorry, I don't know. @John Dowson will be able to tell us. Paul
John Dowson Posted July 28, 2020 Report Posted July 28, 2020 35 minutes ago, Delphi said: do you know whether this is required for FSUIPC6 too? No, thats an ini parameter for FSUIPC4 only. John
Delphi Posted August 7, 2020 Report Posted August 7, 2020 Hi Paul, first of all many thanks for the that new function. Very usefull. I adapted my complete GSX handler to that new function. One think I found that some messages are catched as 'textmenu' with the length of '0'. textMenu.IsMenu is TRUE textMenu.MenuItemCount is '0' textMenu.MenuTitleText contains the message Some examples from GSX are: "You need to set Parking Brakes to request ground services" "You need to stop the engines to request ground services" "Please set parking brakes" Other messages like "Fuel Truck is on its way" "Stairs operation completed" These messages are catched as textMenu.Message Ruediger
Paul Henty Posted August 7, 2020 Report Posted August 7, 2020 Hi Ruediger, Thanks for the bug report. Fixed in 3.1.18, now up on NuGet. Paul
737-SimGuy Posted August 17, 2020 Report Posted August 17, 2020 Paul, Is there much overhead in the RefreshData method? Is it a problem calling it say every 50 or 100 ms? I have been doing all this manually until just now seeing this thread, thought I might give it a try. With my code I am simply checking the status of B000 every 100ms, is that what refresh data is doing? Thank you, James
Paul Henty Posted August 17, 2020 Report Posted August 17, 2020 Hi James, Yes, RefreshData() is just calling Process() for an internal group containing the 0xB000 offset. It then parses the 2048 bytes that get returned and populates the string properties for you to read. The parsing time is negligible compared to the Process() call, so there's no more overhead than a normal Process(). Paul
737-SimGuy Posted December 1, 2020 Report Posted December 1, 2020 Hi Paul, I finally got around to implementing your TextMenu class replacing mine. It works mostly well except for a few things: 1. I occasionally get this error when calling the Refresh method: "Group '0~~SimConnectTextDisplay~~' does not exist." 2. The Simconnect event ID is always zero. 3. In my old code I was able to detect the Clear event. That kind of still happens with yours, it sends an empty message of length 0, but it always receives as a TextMessage, never a Menu, so I am only able to clear the TextMessage and not the Menu items. I used to detect the difference similar to this: If etmDataLength.Value = 0 Then Select Case etmTypeValue.Value Case 512 If Not Cleared Then Cleared = True End If Case 257 If Not ClearedTxt Then ClearedTxt = True End If End Select End If I am using P3D 5.1.12.26829 and FSUIPC_Client.DLL version 3.1.22 with FSUIPC 6.0.10a via WideClient version 7.159. Below is an excerpt from my log. Maybe will give you a clue, maybe not. Thanks for any help! James Log excerpt: 4:36:48 PM : New SimConnect Event 4:36:48 PM : ID of the SimConnect event: 0 4:36:48 PM : Duration: 0 seconds 4:36:48 PM : It's a MESSAGE: 4:36:48 PM : Msg: 4:36:48 PM : Message length: 0 4:36:48 PM : 4:57:24 PM : Error when calling myTextMenu.RefreshData(): Group '0~~SimConnectTextDisplay~~' does not exist. InnerException: 5:02:24 PM : Error when calling myTextMenu.RefreshData(): Group '0~~SimConnectTextDisplay~~' does not exist. InnerException: 5:16:29 PM : New SimConnect Event 5:16:29 PM : ID of the SimConnect event: 0 5:16:29 PM : Duration: 9 seconds 5:16:29 PM : It's a MESSAGE: 5:16:29 PM : Msg: Cabin Ready 5:16:29 PM : Message length: 11 5:16:29 PM : Sending message to PFD AUX... 5:16:29 PM : Line0: Cabin Ready 5:16:29 PM : TextIndex(0): 19 5:16:29 PM : 5:16:38 PM : New SimConnect Event 5:16:38 PM : ID of the SimConnect event: 0 5:16:38 PM : Duration: 0 seconds 5:16:38 PM : It's a MESSAGE: 5:16:38 PM : Msg: 5:16:38 PM : Message length: 0 5:16:38 PM : ClrText 5:16:38 PM : Cleared text message 5:16:38 PM : 5:16:39 PM : Error when calling myTextMenu.RefreshData(): Group '0~~SimConnectTextDisplay~~' does not exist. InnerException: 5:18:17 PM : Error when calling myTextMenu.RefreshData(): Group '0~~SimConnectTextDisplay~~' does not exist. InnerException: 5:27:40 PM : New SimConnect Event 5:27:40 PM : ID of the SimConnect event: 0 5:27:40 PM : Duration: 9 seconds 5:27:40 PM : It's a MESSAGE: 5:27:40 PM : Msg: Ground Power Available 5:27:40 PM : Message length: 22 5:27:40 PM : Sending message to PFD AUX... 5:27:40 PM : Line0: Ground Power Available 5:27:40 PM : TextIndex(0): 20 5:27:40 PM : 5:27:49 PM : New SimConnect Event 5:27:49 PM : ID of the SimConnect event: 0 5:27:49 PM : Duration: 0 seconds 5:27:49 PM : It's a MESSAGE: 5:27:49 PM : Msg: 5:27:49 PM : Message length: 0 5:27:49 PM : ClrText 5:27:49 PM : Cleared text message
Paul Henty Posted December 1, 2020 Report Posted December 1, 2020 Hi James, Version 3.1.23 BETA is now on Nuget. (Tick the 'Include Prereleases' box to make it show up). Quote 1. I occasionally get this error when calling the Refresh method: "Group '0~~SimConnectTextDisplay~~' does not exist." I didn't make textmenus thread safe. Should be okay now. Quote 2. The Simconnect event ID is always zero. Strange as I'm not seeing that here with FSX/FSUIPC4. The Simconnect ID is an Integer stored in offset 0xB00C. Can you check that your end please e.g. via the FSUIPC Logging? If it's also 0 there, then you'll have to speak to John/Pete about it in the main forum. Quote 3. it sends an empty message of length 0, but it always receives as a TextMessage, never a Menu, The menu/message detection was not reliable. I've fixed it now so you should see menus with empty titles. Let me know how you get on... Paul
737-SimGuy Posted December 1, 2020 Report Posted December 1, 2020 Hi Paul, Pete, and John, Thank you for this, I will be testing your new build in a few minutes, but further to the offsets issues I've done some testing with FSInterogate. Maybe I am not understanding correctly but according to the FSUIPC version 6 docs the offsets should be this (for at least FSUIPC 4&5, no idea about 6 as the docs don't mention it): B000 4 bytes changed indicator (tick count at time) B004 4 bytes type value (as documented for Lua) B008 4 bytes display duration in secs (32-bit float) B00C 4 bytes the ID of the SimConnect event B010 4 bytes the length of the data following B014 he text data received (<= 2028 bytes) According to the LUA docs for B004 this is now a bit mask, but even at that I get strange returns with FSUIPC 6.00.10a and P3D5.1hf1. It appears to be more like the Simconnect event ID in B004. For a text menu it returns value 257, for a GSX SimconnectMenu 512, and for the FSUIPC logging window 768, not 0,1,2. B008 is correct. B00C is always zero. B010 and B014 seem correct. I had mine working by testing for 257 or 512, not 1 or 2. Maybe I just don't understand. I'm off to testing your new build... James
Paul Henty Posted December 1, 2020 Report Posted December 1, 2020 Quote I had mine working by testing for 257 or 512, not 1 or 2. Yes this confused me at first. That's why it wasn't working properly before. The documentation appears wrong. What I discovered is that in Hex these values are 01nn for messages and 02nn for menus. I've no idea what the last byte means so I just ignore it now and test 0xB005 for 1 and 2. That seems to work nicely. Thanks for confirming you're seeing 0 for the simconnect id (0xB00C). That seems to be a problem specific to FSUIPC6. With FSUIPC4 it's fine for me here. Paul
John Dowson Posted December 1, 2020 Report Posted December 1, 2020 I'll take a look at this and get back to you. John
737-SimGuy Posted December 1, 2020 Report Posted December 1, 2020 1 hour ago, Paul Henty said: Yes this confused me at first. Well that makes me feel better 😉 Thought I was going senile LOL. Your new build is working nicely now thank you Paul! Let's see what John comes up with... James 1
John Dowson Posted December 2, 2020 Report Posted December 2, 2020 @737-SimGuy Could you add the following to the [General] section of your ini, repeat your tests and show me your .log file please: TestOptions=x8000 Thanks, John
John Dowson Posted December 2, 2020 Report Posted December 2, 2020 It seems that the 'type' field for offset B000 is not documented correctly. This actually holds the simconnect codes (not the lua codes), so they are 0x400 -> 16 = File 0xFFF -> 8 = ActiveSky weather 0x300 -> 4 = SimC message window text 0x200 -> 2 = SimC menu and for text types, the SimConnect_Text_TYPE enum is used: Quote enum SIMCONNECT_TEXT_TYPE{ SIMCONNECT_TEXT_TYPE_SCROLL_BLACK, SIMCONNECT_TEXT_TYPE_SCROLL_WHITE, SIMCONNECT_TEXT_TYPE_SCROLL_RED, SIMCONNECT_TEXT_TYPE_SCROLL_GREEN, SIMCONNECT_TEXT_TYPE_SCROLL_BLUE, SIMCONNECT_TEXT_TYPE_SCROLL_YELLOW, SIMCONNECT_TEXT_TYPE_SCROLL_MAGENTA, SIMCONNECT_TEXT_TYPE_SCROLL_CYAN, SIMCONNECT_TEXT_TYPE_PRINT_BLACK = 0x0100, SIMCONNECT_TEXT_TYPE_PRINT_WHITE, SIMCONNECT_TEXT_TYPE_PRINT_RED, SIMCONNECT_TEXT_TYPE_PRINT_GREEN, SIMCONNECT_TEXT_TYPE_PRINT_BLUE, SIMCONNECT_TEXT_TYPE_PRINT_YELLOW, SIMCONNECT_TEXT_TYPE_PRINT_MAGENTA, SIMCONNECT_TEXT_TYPE_PRINT_CYAN, SIMCONNECT_TEXT_TYPE_MENU = 0x0200 SIMCONNECT_TEXT_TYPE_MESSAGE_WINDOW = 0x0300 So a value of 512 (0x200) is a Simconnect menu, and 257 (0x101) would be white text. Does that make sense? I will update the documentation for this in the next release. Also seems that the SimConnect event Id is not populated (always 0). Is this needed? John
Pete Dowson Posted December 2, 2020 Report Posted December 2, 2020 The "type" in offset B004 is in fact decoded to the documented Lua types in WideClient for use in event.textmenu when it receives the offset data. The original data is actually the SimConnect type with additions. So, apologies, the offset documentation is currently wrong. The types and their Lua classification are: 0x000-0x007 SimConnect scrolling text line in one of 8 colours (Lua type 1) 0x100-0x107 SimConnect non-scrolling text line in one of 8 colours (also Lua type 1) 0x200 SimConnect menu (Lua type 2) 0x300 SimConnect message window (Lua type 4) 0x400 File display facility (Lua type 16) 0xFFF Active Sky weather summary for planned route (Lua type 8) The Lua types are bit flags which can be combined in the event.textmenu to trap more than one of these, hence the coding conversion. [LATER] Oops. I see John has also replied in the same vein! Pete
Paul Henty Posted December 2, 2020 Report Posted December 2, 2020 Thanks for the info Pete and John. Paul
737-SimGuy Posted December 2, 2020 Report Posted December 2, 2020 1 hour ago, John Dowson said: Also seems that the SimConnect event Id is not populated (always 0). Is this needed? Hi John, IMO no, not needed. But I'm just a nobody 😉 >>>So a value of 512 (0x200) is a Simconnect menu, and 257 (0x101) would be white text. Does that make sense? Does here, that's what I was using in my old code. Also explains why it didn't work when I changed it in P3D to scrolling text. James
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now