Using VS Code and C# (CS) from sdk

Former Member
Former Member

You know I often wonder why I bother wasting many hours out of my life trying to get things working and fighting against incomplete documentation and unstated assumptions. It seems that when people write documentation they simply have an existing setup that works and assume everyone else either knows what they know or have their system setup as they do. This is rarely, if ever the case!!! Rant over.

I have VS Code, I have loaded the extensions and with a dot net generated hello world can run and debug the project.

So now I go to say CS|Examples|Decode   C:\Users\[user]\Documents\Applications\FitSDKRelease_21.47.00\cs\Examples\Decode and open the folder.

According to VS Code, C# documentation the extension shuld automatically create the .vscode tasks.json and the launch.json file. It doesn't. (It did for the sample project!).

So can you please provide the sample tasks.json and launch.json files and/or explain what needs to be done for these to be autocreated.

Using my sample code I grabbed the DecodeDemo.cs source code and pasted it into the sample.cs source code ammending the namespace.

Of course this wants to reference the assembly Dynastream.Fit (lots or error messages).  I assume I use the Dynastream.Fit.Portable.dll. But where do I put it and how do I create a reference to it. I'm assuming I need to edit the .csproj file? But nothing I tried works. 

I've tried doing all this the other way round as well by opening the folder for the decode and trying to manually create .jsons etc, but I keep running into the assembly not referenced issue.

You make it all sound so easy, but it's not!!! (And I've been programming and hacking since 1977).

My plan is to make a JavaScript version of decoding a FIT file so I can then use D3 to visualise it - something that is sadly missing from the Karoo bike computer Dashboard!!! 

Thanks to anyone who can help. I'm really frustrated today Disappointed

  • Former Member
    0 Former Member over 4 years ago

    Oh and I read the readme

    ## Prerequisites

    The following prerequisites are required for working with the example projects found in the cookbook.

    1. [Visual Studio Code](code.visualstudio.com/) with the [C# extension](marketplace.visualstudio.com/items installed.
    2. The [NET Core SDK v3.1](dotnet.microsoft.com/.../dotnet-core) or later installed.

    ## Using the recipes

    1. Open project folder in Visual Studio Code and install any extensions that are suggested for the project.
    2. To start debugging press F5, or from the menu choose Run -> Start debugging.

  • Former Member
    0 Former Member over 4 years ago

    Oh and I know how to run the .NET:Generate assets for build and debug from ctrl+shift+p (or View|Command Palette) (it creates a tasks.json, but not a launch.json (use Run and debug and create one and use the .Net Core but the following is generated

    // Use IntelliSense to learn about possible attributes.
      // Hover to view descriptions of existing attributes.
      // For more information, visit: go.microsoft.com/.../
      "version""0.2.0",
      "configurations": [
        {
          "name"".NET Core Launch (console)",
          "type""coreclr",
          "request""launch",
          "WARNING01""*********************************************************************************",
          "WARNING02""The C# extension was unable to automatically decode projects in the current",
          "WARNING03""workspace to create a runnable launch.json file. A template launch.json file has",
          "WARNING04""been created as a placeholder.",
          "WARNING05""",
          "WARNING06""If OmniSharp is currently unable to load your project, you can attempt to resolve",
          "WARNING07""this by restoring any missing project dependencies (example: run 'dotnet restore')",
          "WARNING08""and by fixing any reported errors from building the projects in your workspace.",
          "WARNING09""If this allows OmniSharp to now load your project then --",
          "WARNING10""  * Delete this file",
          "WARNING11""  * Open the Visual Studio Code command palette (View->Command Palette)",
          "WARNING12""  * run the command: '.NET: Generate Assets for Build and Debug'.",
          "WARNING13""",
          "WARNING14""If your project requires a more complex launch configuration, you may wish to delete",
          "WARNING15""this configuration and pick a different template using the 'Add Configuration...'",
          "WARNING16""button at the bottom of this file.",
          "WARNING17""*********************************************************************************",
          "preLaunchTask""build",
          "program""${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
          "args": [],
          "cwd""${workspaceFolder}",
          "console""internalConsole",
          "stopAtEntry"false
        },
        {
          "name"".NET Core Attach",
          "type""coreclr",
          "request""attach",
          "processId""${command:pickProcess}"
        }
      ]
    }
    I tried the dotnet restore (from the terminal) but it says: Nothing to do. None of the projects specified contain packages to restore.
  • Former Member
    0 Former Member over 4 years ago in reply to Former Member

    Found it!!!!

    In launch.json: should have 

    "program""${workspaceFolder}/bin/Debug/decode.exe",
    Job done, what a faff. Slight smile
  • I am sorry that things were not working for you straight out of the box. I was scratching my head until I noticed

    "[user]\Documents\Applications\FitSDKRelease_21.47.00\cs\Examples\Decode"

    The C# SDK has both Example projects and the Cookbook, which can be confusing. The Cookbook is new and only exists in the C# SDK. The readme file in the Cookbook folder applies to the Cookbook only. Eventually the Cookbook will be replicated in each language and the Example projects will go away. 

    The Example projects work with Visual Studio whereas the projects in the Cookbook work with VSCode. There are separate instructions for each here:

    https://developer.garmin.com/fit/example-projects/cs/
    and here:
    https://developer.garmin.com/fit/cookbook/

    The Example.sln file can be opened in Visual Studio and the solution contains both the Encode and Decode projects. To use one of the Cookbook projects with VSCode, open the folder of the desired project, ie ActivityDecode, and then hit F5 to start debugging. No task.json is required.

  • Former Member
    0 Former Member over 4 years ago in reply to Ben FIT

    Hi Ben FIT :), well thankyou for your great reply. I feel a bit of a chump now, though I suppose that once you gain the knowledge of the difference between the cookbook and the examples it all makes sense in the documentation. At least if anyone want to "convert" the examples to cookbook (though why would they) they'll know it's possible.

    I have to say though that trying to figure out the examples is really hard, this is not a simple thing is it.

    I'm trying to study the protocol, but it's hard.

    BTW is there something in the css for that web page that stops it reflowing properly on a tablet screen. There are no scroll bars to see what's on the right side of the text and it won't respond to pinch and zoom. The other pages seem to paginate fine.

    Has anyone got a link to any kind of duffer's guide to FIT? 

    I can read the bytes quite easily in the JavaScript, but perhaps someone can provide a basic algorithm for how I should extract the info. I know there's going to be lots of look ups and I can see that I might need to re-arrange bytes (endianess) and the datetime (even in the csv) looks tricky. I assume the dynastream dll contains lots of helper functions to decode the bytes. I'd rather do it myself I think. (part of the fun).

    Ideally I'd like something like:

    Extract n bytes for the header.

    Byte x tells you ...

    Byte y tells you ...

    Using bytes a, b ... you can grab the records

    ...

    Oh well back to the protocol ;) 

    Thanks again Ben. Slight smile

  • Former Member
    0 Former Member over 4 years ago in reply to Former Member

    Doh, I've done it again. There are some descriptions of how it works in the Decoding FIT Activity Files section, sorry.