Jump to content
The simFlight Network Forums

Recommended Posts

Posted

I am trying to change a switch which has LVAR: ASD_SWITCH_EXT_POWER using C++ code, so I am using UIPC_SDK_C_version2.
Could anyone give me a snippet of code on how to read the value of the switch and how to change its value to 1. 
Also trying to build any code using FSUIPC_User64.h results in build error ( The library was created by a different version of the compiler ) is there is something I am missing?
Thanks In Advance.

Posted
5 hours ago, Mostafa said:

Also trying to build any code using FSUIPC_User64.h results in build error ( The library was created by a different version of the compiler ) is there is something I am missing?

The source is provided so you can recompile it with the latest compiler. However, I did recompile this recently (for FSUIPC7), so I have attached this below.

5 hours ago, Mostafa said:

I am trying to change a switch which has LVAR: ASD_SWITCH_EXT_POWER using C++ code, so I am using UIPC_SDK_C_version2.

Sorry, but I just don't have the time to provide an example. I have never used most of the provided SDKs and they are provided as-is, and most donated by other authors.

You need to first write the new value to a user offset (e.g. 0x66C0) using FSUIPC_Write, then write the offset address used + the value format (as described in the offset status document) to offset 0x0D6C (again, using FSUIPC_Write), and then the lvar write request, which would be "::ASD_SWITCH_EXT_POWER", to offset 0x0D70 (using FSUIPC_Write), and then call FSUIPC_Process to apply.

Note that the only supported SDK is the .Net / C# one provided by Paul Henty - there is a sub-forum for this interface: https://forum.simflight.com/forum/167-fsuipc-client-dll-for-net/

UIPC64_SDK_C_version2.zip

Posted

Using this code as your instructions just added a FSUIPC_Read function before Close:

 

#include <iostream>
#include <windows.h>
#include "FSUIPC_User64.h"
#include <iomanip>

using namespace std;


int main()
{
    DWORD dwResult;

    if (FSUIPC_Open(SIM_ANY, &dwResult))
    {
        std::cout << "Connected to FSUIPC" << std::endl;

        double newLvarValue = 1.0; // The value you want to set

        // Step 1: Write the new LVAR value to user offset 0x66C0
        if (!FSUIPC_Write(0x66C0, sizeof(newLvarValue), &newLvarValue, &dwResult))
        {
            std::cout << "Failed to write new LVAR value to offset 0x66C0" << std::endl;
        }

        // Step 2: Write the offset address (0x66C0) and format specifier (0 for double) to 0x0D6C
        DWORD param = 0x66C00000; // 0x66C0 offset + format specifier (0 = double)
        if (!FSUIPC_Write(0x0D6C, sizeof(param), &param, &dwResult))
        {
            std::cout << "Failed to write parameter to offset 0x0D6C" << std::endl;
        }

        // Step 3: Write the LVAR command "::ASD_SWITCH_EXT_POWER" to 0x0D70
        const char lvarCommand[] = "::ASD_SWITCH_EXT_POWER";
        if (!FSUIPC_Write(0x0D70, sizeof(lvarCommand), (void*)lvarCommand, &dwResult))
        {
            std::cout << "Failed to write LVAR command to offset 0x0D70" << std::endl;
        }

        // Step 4: Process the writes
        if (!FSUIPC_Process(&dwResult))
        {
            std::cout << "FSUIPC process failed" << std::endl;
        }
        else
        {
            std::cout << "LVAR write command sent successfully" << std::endl;
        }

        // Step 5: Read back the value from 0x66C0 to confirm the change
        double readBackValue = 0.0;
        if (FSUIPC_Read(0x66C0, sizeof(readBackValue), &readBackValue, &dwResult))
        {
            FSUIPC_Process(&dwResult);
            std::cout << "LVAR ASD_SWITCH_EXT_POWER updated to: " << readBackValue << std::endl;
        }
        else
        {
            std::cout << "Failed to read back LVAR value" << std::endl;
        }

        FSUIPC_Close();
    }
    else
    {
        std::cout << "Failed to connect to FSUIPC" << std::endl;
    }
}

 

This results in :
Connected to FSUIPC
LVAR write command sent successfully
LVAR ASD_SWITCH_EXT_POWER updated to: 1

But the switch in the simulator doesn't change, I am sure that the switch named ASD_SWITCH_EXT_POWER as I use SPAD.next to get LVARs. Is there is something I am missing ?
Thanks In Advance. @John Dowson

Posted (edited)
1 hour ago, Mostafa said:

DWORD param = 0x66C00000; // 0x66C0 offset + format specifier (0 = double)

According to the docs, this should be
    DWORD param = 0x066C0
From the docs:

Quote
This offset value only occupies the low 16-bits (LOWORD) of the 32-bit value. The high part specifies the value format. Assuming the offset is ‘nnnn’, the options are:
    0x0nnnn for 64-bit double (as before)
    0x1nnnn for 32-bit float (FLT)
    0x2nnnn for 32-bit signed integer (SD)
    0x3nnnn for 32-bit unsigned integer (UD)
    0x4nnnn for 16-bit signed integer (SW)
    0x5nnnn for 16-bit unsigned integer (UW)
    0x6nnnn for 8-bit signed integer (SB)
    0x7nnnn for 8-bit unsigned integer (UB)

 

As this lvar looks to only have values 0 & 1, you could also use a boolean/unsigned byte.

You can check/verify that the lvar value is changing by listing the lvars (Add-ons->WASM->List lvars) [specific lvar logging facilities are also provided but probably overkill for this], and you can check that setting/changing the lvar value has the required effect using the Add-ons->WASM->Set Lvar menu item to change the lvar value.

1 hour ago, Mostafa said:

if (FSUIPC_Read(0x66C0, sizeof(readBackValue), &readBackValue, &dwResult))
        {
            FSUIPC_Process(&dwResult);
            std::cout << "LVAR ASD_SWITCH_EXT_POWER updated to: " << readBackValue << std::endl;
        }
        else
        {
            std::cout << "Failed to read back LVAR value" << std::endl;
        }

This will always log "LVAR ASD_SWITCH_EXT_POWER updated to: 1" regardless of the value of the lvar as you are just reading the value from the offset that you wrote the value of 1.0 to. You would need to write a read lvar request to offset 0x0D70 to get the actual value of the lvar.

John

Edited by John Dowson
Further info added
Posted

Thank you for your support. 
This is the code that worked for me:

#include <iostream>
#include <windows.h>
#include "FSUIPC_User64.h"
#include <iomanip>

using namespace std;


int main()
{
    DWORD dwResult;

    if (FSUIPC_Open(SIM_ANY, &dwResult))
    {
        std::cout << "Connected to FSUIPC" << std::endl;

        double newLvarValue = 1.0; // The value you want to set

        // Step 1: Write the new LVAR value to user offset 0x66C0
        if (!FSUIPC_Write(0x66C0, sizeof(newLvarValue), &newLvarValue, &dwResult))
        {
            std::cout << "Failed to write new LVAR value to offset 0x66C0" << std::endl;
        }

        // Step 2: Write the offset address (0x66C0) and format specifier (0 for double) to 0x0D6C
        DWORD param = 0x066C0; // 0x66C0 offset + format specifier (0 = double)
        if (!FSUIPC_Write(0x0D6C, sizeof(param), &param, &dwResult))
        {
            std::cout << "Failed to write parameter to offset 0x0D6C" << std::endl;
        }

        // Step 3: Write the LVAR command "::ASD_SWITCH_EXT_POWER" to 0x0D70
        const char lvarCommand[] = "::ASD_SWITCH_EXT_POWER";
        if (!FSUIPC_Write(0x0D70, sizeof(lvarCommand), (void*)lvarCommand, &dwResult))
        {
            std::cout << "Failed to write LVAR command to offset 0x0D70" << std::endl;
        }

        // Step 4: Process the writes
        if (!FSUIPC_Process(&dwResult))
        {
            std::cout << "FSUIPC process failed" << std::endl;
        }
        else
        {
            std::cout << "LVAR write command sent successfully" << std::endl;
        }

        

        FSUIPC_Close();
    }
    else
    {
        std::cout << "Failed to connect to FSUIPC" << std::endl;
    }
}

Could you help me read an LVAR?
@John Dowson

Posted
4 minutes ago, Mostafa said:

Could you help me read an LVAR?

Read the documentation! Its the same as a write, but write to offset 0x0D70 with one colon, not two, e.g. ":ASD_SWITCH_EXT_POWER"

Then read the value from the offset you wrote to 0x0D6C (0x66C0 in this case).

John

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.