Jump to content

Programming issues


andycruce

Recommended Posts

I am new to C# and can't get any of the examples to work.  I have copied both the simple access example and the Quaternion Call Back example.  Neither of these work for what appears to be different issues.

 

The simple Quaternion access example generates a NotSupportedException when I execute imu.GetQuaternion(out w, out x, out y, out z)  All the code is copied from the TinkerForge example, there are no compile errors.  The ipcon is properly initialized and the imu object is properly initialized with the proper UID. I've check the IMU UID on using the BrickView app.

 

I also tried the Quaternion Call Back example.  This program also complies and shows no errors during execution.  However, it appears the QuaternionCB function is never executed.  A breakpoint there is never reached and there nothing is printed.  The program gets to the Console.ReadLine statement and will exit if a return is entered.

 

In both cases I am using System and Using Tinkerforge.  I got the Tinkerforge dll from NuGet.  Programs are being run under VS2015 as a console application.

 

Any Suggestions?

 

Link zu diesem Kommentar
Share on other sites

Here is the code for the GetQuaternion function which returns the error:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Tinkerforge;

 

namespace TinkerForge_Test

{

    class Program

    {

 

        private static string HOST = "localhost";

        private static int PORT = 4223;

        private static string UID = "XXYYZZ"; // Change XXYYZZ to the UID of your IMU Brick 2.0

 

        static void Main(string[] args)

        {

            IPConnection ipcon = new IPConnection(); // Create IP connection

            BrickIMUV2 imu = new BrickIMUV2("62feo2", ipcon); // Create device object

 

            ipcon.Connect(HOST, PORT); // Connect to brickd

                                      // Don't use device before ipcon is connected

 

            // Get current quaternion

            short w, x, y, z;

//            z = (short) 5.0;

            imu.GetQuaternion(out w, out x, out y, out z);

 

 

            string s = "w: {0:F02}, x: {1:F02}, y: {2:F02}, z: {3:F02}";

            string f = String.Format(s, w / 16383.0, x / 16383.0, y / 16383.0, z / 16383.0);

            Console.WriteLine(f);

 

            Console.WriteLine("Press enter to exit");

            Console.ReadLine();

            ipcon.Disconnect();

 

        }

    }

}

 

 

Here is the code for the Quaternion Call Back example which doesn't generate an error doesn't seem to access the Call Back functions since nothing is printed on the console.  The console stays up until I enter a carriage return and the program seems to exit normally.

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Tinkerforge;

 

 

namespace ConsoleApplication1

{

    class Example

    {

        private static string HOST = "localhost";

        private static int PORT = 4223;

        private static string UID = "62feo2"; // Change XXYYZZ to the UID of your IMU Brick 2.0

 

        // Callback function for quaternion callback

        static void QuaternionCB(BrickIMUV2 sender, short w, short x, short y, short z)

        {

            string s = "w: {0:F02}, x: {1:F02}, y: {2:F02}, z: {3:F02}";

            string f = String.Format(s, w / 16383.0, x / 16383.0, y / 16383.0, z / 16383.0);

            Console.WriteLine(f);

        }

 

        static void Main()

        {

            IPConnection ipcon = new IPConnection(); // Create IP connection

            BrickIMUV2 imu = new BrickIMUV2(UID, ipcon); // Create device object

 

            ipcon.Connect(HOST, PORT); // Connect to brickd

                                      // Don't use device before ipcon is connected

 

            // Register quaternion callback to function QuaternionCB

                        imu.Quaternion += QuaternionCB;

 

 

            // Set period for quaternion callback to 0.1s (100ms)

            // Note: The quaternion callback is only called every 0.1 seconds

            //      if the quaternion has changed since the last call!

            imu.SetQuaternionPeriod(100);

 

            Console.WriteLine("Press enter to exit");

            Console.ReadLine();

            ipcon.Disconnect();

        }

    }

 

}

 

Hope this helps

 

Andy Cruce

Link zu diesem Kommentar
Share on other sites

You were right.  I was using the wrong UID.  Was using the one for the master brick as opposed to the IMU.  However, when I corrected this I received a timeout.  Attached are two screen shots.  One is the result of running the program with the correct UID - showing the timeout exception - and the other is a screen shot of the BrickView program.  Does the program require a pause after the ipcon.Connect statement to allow the system to connect.  I assumed the program wouldn't continue until the ipcom.Connect finished.

 

BrickViewer_output.thumb.jpg.7f9630b87559cc863de095d73a287020.jpg

TinkerForgeIMURead.thumb.jpg.78d6a35745c56dc601009c67d7deffd8.jpg

Link zu diesem Kommentar
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

×   Du hast formatierten Text eingefügt.   Formatierung jetzt entfernen

  Only 75 emoji are allowed.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Clear editor

×   Du kannst Bilder nicht direkt einfügen. Lade Bilder hoch oder lade sie von einer URL.

×
×
  • Neu erstellen...