EvenAR / node-simconnect

A cross platform SimConnect client library for Node.JS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Need example on how to write simulation variables

MatthausNawan opened this issue · comments

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

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

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 🤔

commented
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);

@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:

this._writeBuffer = new RawBuffer(RECEIVE_SIZE);

Thank you fot that