Jump to content
The simFlight Network Forums

Setting a SimVar from an LVar with FSUIPC


jsmarko3

Recommended Posts

I've found that a lot of third-party planes for MSFS don't set the standard seatbelt sign variable, so PACX doesn't pick up on it.  I'm trying to fix this using FSUIPC as the bridge between the LVars and the simvar, but unfortunately, I'm in way over my head with all of this.  I'd like to think I'm a technical guy, being an engineer and all, but I must be lacking some very basic context on how this all works under the hood because I'm not understanding most of the advanced user guide at all.

Tthe main problem:  I'd like to set CABIN SEATBELTS ALERT SWITCH, a bool, which looks to already have an offset of 0x341D, based on the position of the Aerosoft CRJ seatbelt sign switch.  The LVar for that is ASCRJ_OVHD_SEAT_BELTS, and it has three possible values: 2 for On, 1 for Off, 0 for Auto.  I have successfully mapped it to an offset (UB0xA000) and I can read it no problem.

At this point, though, I'm not sure what my next step would be.  I don't want to assign it to a button or an axis, I would like it to update the simvar whenever the LVar is updated.  I have had some limited success with other aircraft mapping axes to offsets to control things like oil coolers, but I don't see a way to just update one var from another.  I could try assigning ASCRJ_OVHD_SEAT_BELTS just to 0x341D and see what happens, but given that it has values of 0, 1, and 2 I don't expect it to work very well.

I have also discovered, from perusing here, the Mobiflight events list that comes with FSUIPC, and there exists a set for the CRJ, including some code for the seatbelt sign:

1 (L:ASCRJ_OVHD_SEAT_BELTS, Number) 0 == if{ 1 (>L:ASCRJ_OVHD_SEAT_BELTS, Number) } 
els{ (L:ASCRJ_OVHD_SEAT_BELTS, Number) 1 == if{ 2 (>L:ASCRJ_OVHD_SEAT_BELTS, Number) } 
els{ (L:ASCRJ_OVHD_SEAT_BELTS, Number) 2 == if{ 0 (>L:ASCRJ_OVHD_SEAT_BELTS, Number) }

I didn't find the advanced guide very helpful in either deciphering what this does, how to use it, or if events are something I would want to use for this purpose.

Given all of that, what path do I want to go down in order to do this seemingly simple task, and where in the documentation should I start?  Thanks for any and all pointers.

-Joe Markowski

 

Link to comment
Share on other sites

5 hours ago, jsmarko3 said:

I would like it to update the simvar whenever the LVar is updated.  I have had some limited success with other aircraft mapping axes to offsets to control things like oil coolers, but I don't see a way to just update one var from another.

You need to use a lua script, with event.offset (on 0xA000 ) that calls a handling function that writes the offset value (0x341D) when the lvar offset (0xA000) changes. However, this is probably not what you want, as writing to that offset may not actually change the offset value if the simvar is not being used by the aircraft. It may work, you need to try this.
Alternatively, what you may need is to 'spoof' the offset 0x341D to the value of offset 0xA000, so when anything external tries to read offset  0x341D, it actually gets the value stored in offset 0xA000. The spoofing facility is in offset 0x0024 - if you search the forums, there are various examples on how to use this facility, most recently for spoofing the Parking Brake for the A320.

5 hours ago, jsmarko3 said:

I have also discovered, from perusing here, the Mobiflight events list that comes with FSUIPC, and there exists a set for the CRJ, including some code for the seatbelt sign:

1 (L:ASCRJ_OVHD_SEAT_BELTS, Number) 0 == if{ 1 (>L:ASCRJ_OVHD_SEAT_BELTS, Number) } 
els{ (L:ASCRJ_OVHD_SEAT_BELTS, Number) 1 == if{ 2 (>L:ASCRJ_OVHD_SEAT_BELTS, Number) } 
els{ (L:ASCRJ_OVHD_SEAT_BELTS, Number) 2 == if{ 0 (>L:ASCRJ_OVHD_SEAT_BELTS, Number) }

I didn't find the advanced guide very helpful in either deciphering what this does, how to use it, or if events are something I would want to use for this purpose.

I would recommend that you use presets rather than MobiFlight events. The MF preset for that calculator code is called ASCRJ_OVHD_SEAT_BELTS_SWITCH, and is directly assignable in FSUIPC7 with the control Preset:ASCRJ Ovhd Seat Belts Switch. All MobiFlight events are available using presets, and you do not need to install the MobiFlight WASM module to use them (as you would if you used the actual events).

Please see the section on the WASM module in the Advanced User guide to understand presets and how to use them. Also take a look at the MF Hub Hop preset list (https://hubhop.mobiflight.com/presets/). That is a good resource for finding presets available for any aircraft. You can also download the latest events.txt file from that site (you need to create an account first) which you can do if there is a preset mentioned there that is not currently available in FSUIPC7. The MF events.txt file included with FSUIPC7 is only updated when I release a new version of FSUIPC7.

John

Link to comment
Share on other sites

1 hour ago, John Dowson said:

You need to use a lua script, with event.offset (on 0xA000 ) that calls a handling function that writes the offset value (0x341D) when the lvar offset (0xA000) changes. However, this is probably not what you want, as writing to that offset may not actually change the offset value if the simvar is not being used by the aircraft. It may work, you need to try this.
Alternatively, what you may need is to 'spoof' the offset 0x341D to the value of offset 0xA000, so when anything external tries to read offset  0x341D, it actually gets the value stored in offset 0xA000. The spoofing facility is in offset 0x0024 - if you search the forums, there are various examples on how to use this facility, most recently for spoofing the Parking Brake for the A320.

Thanks for the pointer John.  Oh boy, that's quite the mouthful, but I haven't cracked the lua portion of the manual yet so I'll take a look at that.  It's not the aircraft that I want to use the simvar, though, it's an external app called PACX that reads that var to determine the seatbelt sign status.

Is there an updated version of the manual available for download anywhere?  I'll be away from my PC with my FSUIPC installation for a while but I'd like to start reading up on lua, and the link here on the forums is from January of '21, at least the advanced user guide was.

Link to comment
Share on other sites

53 minutes ago, jsmarko3 said:

It's not the aircraft that I want to use the simvar, though, it's an external app called PACX that reads that var to determine the seatbelt sign status.

Simvars are created by the FS, and can be used by the aircraft or not. It is the aircraft (model) that creates the lvars. Is PACX reading that simvar, or accessing its value via the FSUIPC offset? Either way, the first thing to try is updating that simvar. Doing this will NOT have the desired affect (i.e. will not set or toggle the seatbelt switch) - you need to use the preset/calculator code for that, but you need to cgeckif the simvar is updated upon request. You may find that this I not the case if the simvar isn't being used, but a simple test of writing to the offset and then reading it back should tell you this. If it isn't being updated, and PACX is reading the FSUIPC offset for this value, you will need to 'spoof' the value of this offset with the value of the lvar.

1 hour ago, jsmarko3 said:

Is there an updated version of the manual available for download anywhere?  I'll be away from my PC with my FSUIPC installation for a while but I'd like to start reading up on lua, and the link here on the forums is from January of '21, at least the advanced user guide was.

The latest documentation is always included with the latest FSUIPC release. The latest Advanced User Guide is dated May 2022 and was last updated for FSUIPC7 v7.3.5. The latest FSUIPC7 version is v7.3.6. Uf the manual you are looking at is dated Jan 2021, that is extremely old now. Please download and install the latest version of FSUIPC7.

I recommend that you always check you are using the latest version of FSUIPC before asking/posting in the support forums. Only the latest version of each major FSUIPC version is ever supported.

John

Link to comment
Share on other sites

1 minute ago, John Dowson said:

Simvars are created by the FS, and can be used by the aircraft or not. It is the aircraft (model) that creates the lvars. Is PACX reading that simvar, or accessing its value via the FSUIPC offset? Either way, the first thing to try is updating that simvar. Doing this will NOT have the desired affect (i.e. will not set or toggle the seatbelt switch) - you need to use the preset/calculator code for that, but you need to cgeckif the simvar is updated upon request. You may find that this I not the case if the simvar isn't being used, but a simple test of writing to the offset and then reading it back should tell you this. If it isn't being updated, and PACX is reading the FSUIPC offset for this value, you will need to 'spoof' the value of this offset with the value of the lvar.

The latest documentation is always included with the latest FSUIPC release. The latest Advanced User Guide is dated May 2022 and was last updated for FSUIPC7 v7.3.5. The latest FSUIPC7 version is v7.3.6. Uf the manual you are looking at is dated Jan 2021, that is extremely old now. Please download and install the latest version of FSUIPC7.

I recommend that you always check you are using the latest version of FSUIPC before asking/posting in the support forums. Only the latest version of each major FSUIPC version is ever supported.

John

John,

Apologies, I believe I might have worded something incorrectly.  Just in case this changes the direction I need to go, I am not trying to set anything in the CRJ.  I plan on using the switch in the virtual cockpit to toggle the seatbelts, but this does not update the simvar.  PACX reads the simvar, and thus cannot tell when I have the seatbelt signs on or off, so I'm looking to read the CRJ switch value and then set the simvar based on that.  I am uncertain if it is trying to read the variable or an offset (not that I really understand the difference tbh), the only nugget I have to go on so far is this: https://forums.tfdidesign.com/index.php?/topic/5716-seatbelt-state-question/ To my untrained eye, it looks like he's setting the variable and not an offset, but it wouldn't surprise me if I'm wrong.  I assumed I would need to set an offset, as I have tried LVar manipulation in the past (I acknowledge these are different things so the results might not be the same) and not had any results until I started using offsets, so I went digging through the provided offsets and found you have already assigned it 0x341D.  I did find the above referenced topic on the A320 parking brake and will read it, and also that there is an example lua for the spoofing function included with FSUIPC.

Regarding the documentation, yes, I have the latest version installed, or at least no more than 2-3 weeks out.  I was asking specifically about download locations for it since I was hoping to do some reading while away from my PC, but the download link here on the forums here 

is what is dated January 2021.

Link to comment
Share on other sites

23 minutes ago, jsmarko3 said:

Regarding the documentation, yes, I have the latest version installed, or at least no more than 2-3 weeks out.  I was asking specifically about download locations for it since I was hoping to do some reading while away from my PC, but the download link here on the forums here 

is what is dated January 2021.

Yes, I don't update that section very often. If you want to read away from your PC, just copy the latest manuals from your FSUIPC documents folder to the device you will be using.

25 minutes ago, jsmarko3 said:

PACX reads the simvar, and thus cannot tell when I have the seatbelt signs on or off, so I'm looking to read the CRJ switch value and then set the simvar based on that.

Then use lua, as I have advised. Everything I have said is still applicable.

26 minutes ago, jsmarko3 said:

I am uncertain if it is trying to read the variable or an offset (not that I really understand the difference tbh),

A simvar is a simulator A-type variable. An offset is an FSUIPC memory location. Some FSUIPC memory locations/offsets hold the value of simvars (not all), and some allow you to write to them which will trigger FSUIPC to tell the sim to update the simvar either directly or by sending an event/control.

30 minutes ago, jsmarko3 said:

the only nugget I have to go on so far is this: https://forums.tfdidesign.com/index.php?/topic/5716-seatbelt-state-question/ To my untrained eye, it looks like he's setting the variable and not an offset, but it wouldn't surprise me if I'm wrong.

That link says that it is using the simvar. So, if you are using the cockpit UI, you need a lua script to monitor the lvar value (using event.lvar() - no need to add the lvar to an offset), and in the event handling function you could try to write the value received directly to offset 0x341D, If that doesn't work (i.e. writing to the offset doesn't update its value), then you can use the ipc.execCalcCode("<code>") function instead to set the simvar using the <code>
    0 (>A:CABIN SEATBELTS ALERT SWITCH,bool)
or
    1 (>A:CABIN SEATBELTS ALERT SWITCH,bool)

depending upon the value received (i.e. of the lvar).

John

 

Link to comment
Share on other sites

Hi John,

I took a first crack at a lua script to do the job, but I don't think the lua script is actually running.  I have Lua Plugins and Log Lua Separately checked in the Log menu, but I'm not seeing anything other than the standard FSUIPC log.

I use the Profiles as Files option instead of having it all in the ini file, so when it didn't seem to work putting [Auto] in the CRJ.ini file I tried putting [Auto.CRJ] in the main ini file, but that didn't seem to work either.  I have attached the four relevant files in the hopes that something is obvious to you that it isn't to me.

FSUIPC7.log FSUIPC7.ini CRJ.ini CRJSeatbelts.lua

Link to comment
Share on other sites

16 hours ago, jsmarko3 said:

I have attached the four relevant files in the hopes that something is obvious to you that it isn't to me.

They look ok to me - at least, nothing obvious stands out.
I will check this here (most probably tomorrow or Monday) and get back you. I see you are using the LuaPath ini parameter. Could you test without that - comment it out or remove it, and copy your lua file to the FSUIPC7 installation folder.

Link to comment
Share on other sites

I'll give that a try and report back.  Last night I did try dropping 1 (>A:CABIN SEATBELTS ALERT SWITCH,bool) into the Exec Calculator Code window under the WASM menu and that didn't have any effect, unsure if that means anything.

Link to comment
Share on other sites

2 hours ago, jsmarko3 said:

I did try dropping 1 (>A:CABIN SEATBELTS ALERT SWITCH,bool) into the Exec Calculator Code window under the WASM menu and that didn't have any effect, unsure if that means anything.

Well yes...but is that updating the lvar?
Can you monitor offset 0x341D using FSUIPC's offset monitoring facilities - you can select to send this to the FS title bar (as UB) and key an eye on that. Then try sending either
     1 (>A:CABIN SEATBELTS ALERT SWITCH)
ot
     0 (>A:CABIN SEATBELTS ALERT SWITCH)
after you have switched the alert switch on/off in the cockpit UI, to see if these requests are actually changing the simvar.

I will still look into the auto-not-loading issue, as this seems strange to me...

John

 

 

Link to comment
Share on other sites

I think I'm having profile issues for some reason.  I've tried monitoring the offset I still have set in my CRJ profile, A000 for the CRJ seatbelt var, and I don't see that being updated despite seeing the LVar change when I repeatedly List LVars.

I tried running the calculator code and monitoring offset 341D which was unaffected.  PACX did change it when the boarding doors were closed, so that is the correct offset/variable.  I have PACX change it automatically during critical portions of the flight until I figure this out, but just in case that was somehow interfering I turned it off.  Still no effect.

I did try rewriting the lua script using writeOffset instead of execCalcCode, but with the fact that I'm not sure my lua is running and/or having profile troubles, that didn't surprise me.

EDIT: Alright, now suddenly the A000 offset for the CRJ seatbelt sign variable is reading appropriately, maybe now the lua script will run.  I did have to reinstall the CRJ, maybe the profile was corrupted.

EDIT2: Nope, not working again.

Link to comment
Share on other sites

John,

Sorry for taking up so much of your time with what should have been a simple issue.  I believe I have finally solved it.

It looks like there might be a problem with UseProfiles=Files, or maybe how I had them formatted.  FSUIPC looks like it would create profiles as files ok, and maybe even update them, but it doesn't seem to want to load them when it starts fresh.  I was noticing, based on my inability to read that offset I had set and opening the button binding window, that when I would start a fresh instance of FSUIPC it was not loading the CRJ profile.  I say fresh instance because when I made changes to the script, ini file, whatever, I would close FSUIPC and reload it, unsure what it does and doesn't auto detect.  I promise I wasn't trying to run it multiple times.

I have put the few lines that were in the CRJ.ini file in the FSUIPC.ini file and removed UseProfiles=Files and not only can I monitor the offset, but now the simvar is being properly updated as well.  Works like a charm and PACX is now registering the proper seatbelt sign values based on the seatbelt sign switch in the VC.

I am attaching my files (I can include the log if you would like it, but it's currently still running while I tinker) in case they help debugging UseProfiles=Files, or the more likely case where it's a formatting issue on my end.

FSUIPC7.ini CRJSeatbelts.lua CRJ.ini

Link to comment
Share on other sites

Hi Joe,

ok, thanks for the updates. It does look like an issue when using profiles in separate files. I will look into this - I must admit, its not something I use (and would discourage others - maybe I will remove the documentation for this feature in a future update...) and don't test, except when problems are reported. And this can be related to when FSUIPC is started - I will check that.

Thanks again - I will report back once I have looked into this in more detail.

John

 

 

  • Thanks 1
Link to comment
Share on other sites

Thanks for all the help John.

I would have thought that using individual files would be the preferred method so as not to clutter up the main ini, but since I don't have much at this point it would be easy to change back over.  If you're thinking if deprecating that functionality, I can do that going forward.

Link to comment
Share on other sites

20 hours ago, jsmarko3 said:

If you're thinking if deprecating that functionality, I can do that going forward.

I don' think I'll deprecate it - just not advertise/document it. It will still be available for those that already use this feature.
But I will certainly make sure its working correctly first!

John

Link to comment
Share on other sites

On 6/25/2022 at 8:20 PM, jsmarko3 said:

It looks like there might be a problem with UseProfiles=Files, or maybe how I had them formatted.  FSUIPC looks like it would create profiles as files ok, and maybe even update them, but it doesn't seem to want to load them when it starts fresh.  I was noticing, based on my inability to read that offset I had set and opening the button binding window, that when I would start a fresh instance of FSUIPC it was not loading the CRJ profile.  I say fresh instance because when I made changes to the script, ini file, whatever, I would close FSUIPC and reload it, unsure what it does and doesn't auto detect.  I promise I wasn't trying to run it multiple times.

I've checked this now, and it all seems to be working as expected, except for one thing: the profile [LvarOffsets.xxx] sections are not moved to the separate profile files when setting UseProfiles=Files for the first time. I have corrected this in the next release.

But both general autos and profile-specific ones are being started correctly, irrespective of when FSUIPC7 is started. I think your issue maybe due to when you are editing the ini files - if you do this when FUIPC7 is open, then when you exit FSUIPC the ini file will be re-written and you will have lost your changes.

I have also tested this when using the LuaPath ini parameter, and that is also working as expected.

Maybe you could test again with the attached version, v7.3.7d. If your lua's aren't starting correctly, we can maybe add more logging to see why this isn't working for you.

John

FSUIPC7.exe

 

Link to comment
Share on other sites

Hi John,

I was indeed modifying the ini files while it was running, so that could be the cause.  I'll give this new version a try and go back to using profiles and see what happens.

Is this an installer, or a replacement for the exe?

Link to comment
Share on other sites

Hi John.

Attached is another log file, as well as my adjusted INI file and the MD82 profile I'm working on.  The profile is identical to the CRJ one with the exception of the livery name and the specific lua script called.  Again, it doesn't seem like FSUIPC is reading the profile INIs with UseProfiles=Files.

I am, however, starting FSUIPC after MSFS is running when testing this (mostly).  It auto starts with the sim, however as I've been making changes I have been closing it and then restarting it.  I do run it as an administrator; I need to run MSFS like that for several add-ons.  I assume FSUIPC usually starts as an admin since the sim is launching it, but when I manually close and reopen it, I make sure to choose run as administrator for that reason.

I just switched back to my old INI file (and renamed my Profiles folder, otherwise it keeps setting UseProfiles=Files), and it works like a charm, so something about reading profile files is funky for me.

 

The one thing I will remember to do is to set up the profile files again BEFORE I start the sim, I'll let you know if that works so maybe the problem is with me restarting FSUIPC while everything is running.

FSUIPC7.ini FSUIPC7.log MD82.ini

Link to comment
Share on other sites

I don't understand why you have the aircraft for your profile in the profile file, rather than in the FSUIPC7.ini file.
Did you create this manually or did FSUIPC7 do this? The [Profile.xxx] sections should still be in your FSUIPC7.ini file listing the aircraft that use that profile, i.e you need this in your FSUIPC7.ini:

[Profile.MD82]
1=Gateway Airlines Classic White

This then matches the aircraft and the MD82.ini will then be read/processed.

The [Profile] section in your profile ini file should just contain the Created timestamp, not the aircraft that use that profile, as they should be in your FSUIPC7.ini.

John

 

  • Thanks 1
Link to comment
Share on other sites

Oops, that one is 100% user error.  No, FSUIPC didn't do that, I did.  It created the profile files but left that in the ini and I said "why is this still here?" and moved it.

That would probably explain why it seems like it forgets I have profiles at all.  I'll fix that and give it a try.

Sorry!

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.