示例#1
0
    private static string UID  = "XYZ";    // Change XYZ to the UID of your Hall Effect Bricklet 2.0

    static void Main()
    {
        IPConnection         ipcon = new IPConnection();                   // Create IP connection
        BrickletHallEffectV2 he    = new BrickletHallEffectV2(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT);                                         // Connect to brickd
        // Don't use device before ipcon is connected

        // Get current Magnetic Flux Density
        short magneticFluxDensity = he.GetMagneticFluxDensity();

        Console.WriteLine("Magnetic Flux Density: " + magneticFluxDensity + " µT");

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
    private static string UID  = "XYZ";    // Change XYZ to the UID of your Hall Effect Bricklet 2.0

    static void Main()
    {
        IPConnection         ipcon = new IPConnection();                   // Create IP connection
        BrickletHallEffectV2 he    = new BrickletHallEffectV2(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT);                                         // Connect to brickd
        // Don't use device before ipcon is connected

        // Get current count without counter reset
        long count = he.GetCounter(false);

        Console.WriteLine("Count: " + count);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
    static void Main()
    {
        IPConnection         ipcon = new IPConnection();                   // Create IP connection
        BrickletHallEffectV2 he    = new BrickletHallEffectV2(UID, ipcon); // Create device object

        ipcon.Connect(HOST, PORT);                                         // Connect to brickd
        // Don't use device before ipcon is connected

        // Configure counter with ±3000µT threshold and 10ms debounce
        he.SetCounterConfig(3000, -3000, 10000);

        // Register counter callback to function CounterCB
        he.CounterCallback += CounterCB;

        // Set period for counter callback to 0.1s (100ms)
        he.SetCounterCallbackConfiguration(100, true);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
    private static string UID  = "XYZ";    // Change XYZ to the UID of your Hall Effect Bricklet 2.0

    // Callback function for counter callback
    static void CounterCB(BrickletHallEffectV2 sender, long counter)
    {
        Console.WriteLine("Counter: " + counter);
    }