private static string UID = "XYZ"; // Change XYZ to the UID of your Rotary Encoder Bricklet

    #endregion Fields

    #region Methods

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

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

        // Get current count without reset
        int count = re.GetCount(false);
        Console.WriteLine("Count: " + count);

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

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

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

        // Get current count without reset
        int count = re.GetCount(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
        BrickletRotaryEncoder re    = new BrickletRotaryEncoder(UID, ipcon); // Create device object

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

        // Register count callback to function CountCB
        re.CountCallback += CountCB;

        // Set period for count callback to 0.05s (50ms)
        // Note: The count callback is only called every 0.05 seconds
        //       if the count has changed since the last call!
        re.SetCountCallbackPeriod(50);

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

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

        // Register count callback to function CountCB
        re.Count += CountCB;

        // Set period for count callback to 0.05s (50ms)
        // Note: The count callback is only called every 0.05 seconds
        //       if the count has changed since the last call!
        re.SetCountCallbackPeriod(50);

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

    // Callback function for count callback
    static void CountCB(BrickletRotaryEncoder sender, int count)
    {
        Console.WriteLine("Count: " + count);
    }
    private static string UID = "XYZ"; // Change XYZ to the UID of your Rotary Encoder Bricklet

    #endregion Fields

    #region Methods

    // Callback function for count callback
    static void CountCB(BrickletRotaryEncoder sender, int count)
    {
        Console.WriteLine("Count: " + count);
    }