static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletLaserRangeFinder lrf = new BrickletLaserRangeFinder(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Turn laser on and wait 250ms for very first measurement to be ready lrf.EnableLaser(); Thread.Sleep(250); // Register distance callback to function DistanceCB lrf.DistanceCallback += DistanceCB; // Set period for distance callback to 0.2s (200ms) // Note: The distance callback is only called every 0.2 seconds // if the distance has changed since the last call! lrf.SetDistanceCallbackPeriod(200); Console.WriteLine("Press enter to exit"); Console.ReadLine(); lrf.DisableLaser(); // Turn laser off ipcon.Disconnect(); }
static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletLaserRangeFinder lrf = new BrickletLaserRangeFinder(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Turn laser on and wait 250ms for very first measurement to be ready lrf.EnableLaser(); Thread.Sleep(250); // Get threshold callbacks with a debounce time of 10 seconds (10000ms) lrf.SetDebouncePeriod(10000); // Register distance reached callback to function DistanceReachedCB lrf.DistanceReachedCallback += DistanceReachedCB; // Configure threshold for distance "greater than 20 cm" (unit is cm) lrf.SetDistanceCallbackThreshold('>', 20, 0); Console.WriteLine("Press enter to exit"); Console.ReadLine(); lrf.DisableLaser(); // Turn laser off ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Laser Range Finder Bricklet static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletLaserRangeFinder lrf = new BrickletLaserRangeFinder(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Turn laser on and wait 250ms for very first measurement to be ready lrf.EnableLaser(); Thread.Sleep(250); // Get current distance (unit is cm) int distance = lrf.GetDistance(); Console.WriteLine("Distance: " + distance + " cm"); Console.WriteLine("Press enter to exit"); Console.ReadLine(); lrf.DisableLaser(); // Turn laser off ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Laser Range Finder Bricklet // Callback function for distance callback (parameter has unit cm) static void DistanceCB(BrickletLaserRangeFinder sender, int distance) { Console.WriteLine("Distance: " + distance + " cm"); }