EvenAR / node-simconnect

A cross platform SimConnect client library for Node.JS
GNU Lesser General Public License v3.0
94 stars 33 forks source link

Need example on how to write simulation variables #61

Closed MatthausNawan closed 1 year ago

MatthausNawan commented 1 year ago

Help, I need a Example how i can set a fuel tank quantity. EG "FUEL TANK CENTER LEVEL"

MatthausNawan commented 1 year ago

I 've trying to set some SIMVAR but i dont find a documentation how to.

 open('FUEL_SYSTEM', Protocol.FSX_SP2).then(({ recvOpen, handle }) => {

        console.log('Connected:', recvOpen);

        handle.addToDataDefinition(DefinitionID.DEF_FUEL, "CENTER TANK QUANTITY", 'percent', SimConnectDataType.INT32, 0);

        handle.setDataOnSimObject(DefinitionID.DEF_FUEL, SimConnectConstants.OBJECT_ID_USER,)
        )

I need a example for setData for any SIMVARS for LIGHTS, FUEL,AP

EvenAR commented 1 year ago

I'm not currently able to test this myself, but I believe something like this should work:

const data = new RawBuffer(4); // we plan to write 4 bytes
data.writeInt(50); // 50%

handle.setDataOnSimObject(
    DefinitionID.DEF_FUEL,
    SimConnectConstants.OBJECT_ID_USER,
    { buffer: data, arrayCount: 0, tagged: false }
)

Are you sure "CENTER TANK QUANTITY" is a simulation variable btw? I can't find it in the docs 🤔

sadu commented 1 year ago
const data = new RawBuffer();
data.writeInt(50); // 50%

I can't initialize this RawBuffer without a constructor parameter. Is there any reference in source code where the buffer size(which is the parameter I am guessing) is not being set initially?

Do you have any instances in the lib or any project that utilize node-simconnect to write a simvar?

Edit: following is what I use to get around, or is there a right way to do this?

    const buffer = new RawBuffer(Buffer.from(''));

    buffer.writeInt(300);
EvenAR commented 1 year ago

@sadu Ah, you’re right. I updated the code. You can also just provide a number for the initial size that should be allocated. It doesn’t really matter what the value is since it will only send the bytes that has been written to, and I think it will automatically allocate more space if needed.

It’s used here: https://github.com/EvenAR/node-simconnect/blob/e181433e4038bf10cc6fcfd1053868295abf7978/src/SimConnectConnection.ts#L168

EvenAR commented 1 year ago

@MatthausNawan, I have added a sample: https://github.com/EvenAR/node-simconnect/blob/9cc7185a7a7fc9be1a53c95c274390efd1d04636/samples/typescript/simulationVariablesWrite.ts Hope this is helpful.

MatthausNawan commented 1 year ago

Thank you fot that