Building my own plugin

Discussion in 'Plugins' started by Rick Jansen, May 26, 2017.

  1. Rick Jansen

    Rick Jansen Registered

    Joined:
    May 26, 2017
    Messages:
    2
    Likes Received:
    0
    Hi, Currently I'm building my own plugin based on the Example plugin where it writes telemetry to a text file. I've added some extra data to write to the text like current time. I'm able to build the plugin, release x64, and it works with rFactor2 (you can see it in the plugin overview and the text file is been created).

    Still I've got a few issues and not sure where it goes wrong.
    1) Sometimes it isn't getting the telemetry data at all
    2) It only gets the first 6 seconds of data then it stops writing. It seems not to be an issue with writing to the text file as I've done the writing every frame or each 10th frame.

    Start:
    -STARTUP- (version 11.108)
    --STARTSESSION--
    CurrentTime= 2017-05-26.11:25:24
    Lap= 0
    Vehicle= Formula ISI 2012 #11
    SpeedLimiter= 0
    Pos= (-232.191,19.859,376.344)
    DT= 0.0100 ET= 1.0000
    Gear= 0
    RPM= 0.0
    RevLimit= 18000.0
    Water= 63.5 Oil=63.5
    Fuel= -536870912
    Speed= 0.0 KPH
    Speed= 0.0 MPH
    Pitch= -0.5 deg, Roll= -0.2 deg

    End:
    CurrentTime= 2017-05-26.11:25:30
    Lap= 0
    Vehicle= Formula ISI 2012 #11
    SpeedLimiter= 1
    Pos= (-235.517,19.869,379.679)
    DT= 0.0100 ET= 7.0125
    Gear= 2
    RPM= 2807.2
    RevLimit= 18000.0
    Water= 71.7 Oil=73.7
    Fuel= 536870912
    Speed= 21.2 KPH
    Speed= 13.1 MPH
    Pitch= -0.3 deg, Roll= -0.5 deg

    I hope you can help me out.
     
  2. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,385
    Likes Received:
    6,601
    @Rick Jansen What conditions do you have in your updatetelemetry() ? I haven't played around with the raw example code for quite a while, but I'm not aware of anything that would stop it. I'm pretty sure I've ended up with quite large text files when I forgot to take out some of the example code.

    Have you changed the file writing code at all? The default is to create 3 text files, opening and closing them each frame. Perhaps you've changed something in there and at some point (after 6 seconds, evidently) the target file is no longer valid?
     
  3. Rick Jansen

    Rick Jansen Registered

    Joined:
    May 26, 2017
    Messages:
    2
    Likes Received:
    0
    @Lazza I've fixed the issue. For each line of telemetry (gear, speed, etc) if was using a function which opened en closed the file. Now I'm opening the file at the beginnen of Telemetry and closing it at the end. It all work fine now. Thanks.
     
  4. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    Note that this is still slow approach to close file so often (will affect FPS), you may want to use buffered io instead, here's how I do it in shared memory plugin:
    setvbuf(SharedMemoryPlugin::msDebugFile, nullptr, _IOFBF, SharedMemoryPlugin::BUFFER_IO_BYTES);
     
  5. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,385
    Likes Received:
    6,601
    Alternatively, open the file once and don't close it until you're done, if that's acceptable (or close and reopen it at key points, so other programs can see up to that point). System file buffering will keep performance up if you're only saving even once a second.

    Glad it works now, anyway :)
     

Share This Page