C# Dot Net Tutorial

I'm trying to get the NetCoreExamples to work in C#l. I literally follow the https://mbientlab.com/tutorials/WCS.html due to my lack of knowledge of C#. I have a Program class now and a ScanConnect class in the namespace NetCoreExamples. When i run the program it gives an error:

What am i doing wrong here? Do i have to add arguments somewhere?

Comments

  • edited February 2019

    The .NET Core tutorial does not use Visual Studio. Run the project from the command line as shown in the tutorial.

  • Sorry i still don't get it. I ran the project from cmd but I keep getting a similar error.

  • Am i missing something here? Add code blocks, what does this mean?

    Could you give me an example of how the program.cs should look like to be able to run ScanConnect?

  • edited February 2019

    The tutorial project is on GitHub:
    https://github.com/mbientlab/MetaWear-Tutorial-CSharp/tree/master/NetCoreExamples

    Copy/paste the commands / code from the tutorial. You probably mistyped something.

  • Thanks Eric! It was indeed a typo. On the tutorial website there is this code in the program.cs:

    await (Task) type.GetMethod("Run", BindingFlags.NonPublic | BindingFlags.Static)
                    .Invoke(null, new object[] { args.TakeLast(args.Length - 1).ToArray() });
    

    On the github it is:

    await (Task) type.GetMethod("RunAsync", BindingFlags.NonPublic | BindingFlags.Static)
                    .Invoke(null, new object[] { args.TakeLast(args.Length - 1).ToArray() });
    

    Thanks for helping me out!

  • Thanks for pointing that out. I've updated the example code on the .NET Core tutorials and added a link to th GitHub repo.

  • It is working pretty well now thanks! There are just 2 (small) things that i did not get from the dotnet tutorial. When i use the multiaccelerometer function, sometimes the program starts with measurements even when one of the sensors is not connected yet. How can i make sure the measurements only starts when both sensors are connected? The other thing is quite similar. I can make the program run for an x amount of time, with the Task.Delay(x), however i want it to stop whenever i press a (certain) key. Is there an easy solution for this?

  • @pvandoorn said:
    It is working pretty well now thanks! There are just 2 (small) things that i did not get from the dotnet tutorial. When i use the multiaccelerometer function, sometimes the program starts with measurements even when one of the sensors is not connected yet. How can i make sure the measurements only starts when both sensors are connected?

    The script does not progress until both sensors are connected. You can check this in the console output.

    The other thing is quite similar. I can make the program run for an x amount of time, with the Task.Delay(x), however i want it to stop whenever i press a (certain) key. Is there an easy solution for this?

    Don't know. You will probably be able to get C# specific questions better answered on MSDN forums or stack overflow.

  • Ok i understand, i will look into this myself. Although I want to let you know that the multiaccelerometer function does start measurering even when only one metawear is connected.

  • That looks like one of the accelerometers was still streaming data before it connected to the app.

Sign In or Register to comment.