Giter Site home page Giter Site logo

Comments (11)

Pomax avatar Pomax commented on July 17, 2024 2

Oh! So if I change the STRINGV back to STRING128, with null, it works!

    handle.addToDataDefinition(
      POSITION_DATA,
      "TITLE",
      null,
      SimConnectDataType.STRING128,
      0,
      SimConnectConstants.UNUSED
    );

from node-simconnect.

RobsonMi avatar RobsonMi commented on July 17, 2024 1

Hi, have you tried with STRINGV and readStringV() as per the samples?
https://github.com/EvenAR/node-simconnect/blob/master/samples/typescript/aircraftInformation.ts

from node-simconnect.

EvenAR avatar EvenAR commented on July 17, 2024 1

You're welcome!

I just tested the sample, and it does work as expected (at least on my machine). However, changing SimConnectPeriod.ONCE to something else (like SimConnectPeriod.SECOND) gives me the same exception (28). It looks like STRINGV can only be used with SimConnectPeriod.ONCE.

I think you can close this issue. I will update the sample to use STRING32 and STRING128 right away to avoid future confusion 😃

from node-simconnect.

Pomax avatar Pomax commented on July 17, 2024

I had not, because the MSFS Simvar docs says its unit is "String (max 128 chars)". Are there docs somewhere that explain when node-simconnect needs a StringV type and when it needs String<num>?

from node-simconnect.

Pomax avatar Pomax commented on July 17, 2024

Updated the code to StringV, looks like the same problem (testing this while sitting in-sim with an airplane loaded on the apron):

import {
  open,
  Protocol,
  SimConnectDataType,
  SimConnectPeriod,
  SimConnectConstants,
} from "node-simconnect";

const POSITION_DATA = 1;
const REQUEST_ID_POSITION_DATA = 1;
const EVENT_ID_PAUSE = 1;

open("My app", Protocol.FSX_SP2)
  .then(function ({ recvOpen, handle }) {
    console.log("Connected to", recvOpen.applicationName);

    handle.addToDataDefinition(
      POSITION_DATA,
      "PLANE LATITUDE",
      "degrees",
      SimConnectDataType.FLOAT64,
      0.0,
      SimConnectConstants.UNUSED
    );
    handle.addToDataDefinition(
      POSITION_DATA,
      "PLANE LONGITUDE",
      "degrees",
      SimConnectDataType.FLOAT64,
      0.0,
      SimConnectConstants.UNUSED
    );

    handle.addToDataDefinition(
      POSITION_DATA,
      "TITLE",
      "string",
      SimConnectDataType.STRINGV,
      0.0,
      SimConnectConstants.UNUSED
    );

    handle.requestDataOnSimObject(
      REQUEST_ID_POSITION_DATA,
      POSITION_DATA,
      SimConnectConstants.OBJECT_ID_USER,
      SimConnectPeriod.SECOND,
      0,
      0,
      0,
      0
    );
    handle.subscribeToSystemEvent(EVENT_ID_PAUSE, "Pause");

    handle.on("event", function (recvEvent) {
      switch (recvEvent.eventID) {
        case EVENT_ID_PAUSE:
          console.log(recvEvent.data === 1 ? "Sim paused" : "Sim unpaused");
          break;
      }
    });

    handle.on("simObjectData", function (recvSimObjectData) {
      switch (recvSimObjectData.requestID) {
        case POSITION_DATA:
          console.log({
            latitude: recvSimObjectData.data.readFloat64(),
            longitude: recvSimObjectData.data.readFloat64(),
            title:  recvSimObjectData.data.readStringV(),
          });
          break;
      }
    });
    handle.on("quit", function () {
      console.log("Quit");
    });
  })
  .catch(function (error) {
    console.log("Connection failed:", error);
  });

Error:

D:\temp>node repro.js
Connected to KittyHawk
D:\temp\node_modules\bytebuffer\dist\bytebuffer-node.js:1861
                throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.length);
                ^

RangeError: Illegal offset: 0 <= 44 (+1) <= 44
    at ByteBuffer.module.exports.ByteBufferPrototype.readCString (D:\temp\node_modules\bytebuffer\dist\bytebuffer-node.js:1861:23)
    at makeString (D:\temp\node_modules\node-simconnect\dist\RawBuffer.js:150:24)
    at RawBuffer.readStringV (D:\temp\node_modules\node-simconnect\dist\RawBuffer.js:139:16)
    at SimConnectConnection.<anonymous> (file:///D:/temp/repro.js:69:44)
    at SimConnectConnection.emit (node:events:513:28)
    at SimConnectConnection.emit (D:\temp\node_modules\node-simconnect\dist\SimConnectConnection.js:78:22)
    at SimConnectConnection._handleMessage (D:\temp\node_modules\node-simconnect\dist\SimConnectConnection.js:1031:22)
    at SimConnectSocket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)

from node-simconnect.

EvenAR avatar EvenAR commented on July 17, 2024

What happens if you replace "string" with "NULL" or null? According to the official docs for SimConnect_AddToDataDefinition, units name should be "NULL" when requesting strings or structures. In the samples I have used null, so perhaps both variants works 🤷

from node-simconnect.

Pomax avatar Pomax commented on July 17, 2024

If I set it to null, the script seems to just "hang", where it logs Connected to KittyHawk and then doesn't generate any output until I kill node. If I try "NULL" or "null", I get the same crash as above.

from node-simconnect.

EvenAR avatar EvenAR commented on July 17, 2024

Hmm, ok. There could be a SimConnect exception happening. Do you get anything if you add this?

handle.on("exception", function (ex) {
  console.log(ex);
});

from node-simconnect.

Pomax avatar Pomax commented on July 17, 2024

ooh, you're right: RecvException { exception: 28, sendId: 4, index: 2 }, so it looks like that's SIMCONNECT_EXCEPTION_DEFINITION_ERROR , which is described as

Specifies that there is a problem with a data definition. Currently this is only used if a variable length definition is sent with SimConnect_RequestDataOnSimObject.

though I admit I'm not sure what a variable length definition is in this context.

from node-simconnect.

EvenAR avatar EvenAR commented on July 17, 2024

My only guess is that it refers to variable length strings (STRINGV)

Edit: Great! 🙌

from node-simconnect.

Pomax avatar Pomax commented on July 17, 2024

@EvenAR @RobsonMi thanks for the (ridiculously fast! =D) help! Should I close this and file a new issue to update the .ts example(s), or keep this one open?

from node-simconnect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.