Ejemplo n.º 1
0
    private static string UID = "XYZ"; // Change XYZ to the UID of your Voltage Bricklet

    #endregion Fields

    #region Methods

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

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

        // Get current voltage (unit is mV)
        int voltage = v.GetVoltage();
        Console.WriteLine("Voltage: " + voltage/1000.0 + " V");

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

    #endregion Fields

    #region Methods

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

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

        // Register voltage callback to function VoltageCB
        v.Voltage += VoltageCB;

        // Set period for voltage callback to 1s (1000ms)
        // Note: The voltage callback is only called every second
        //       if the voltage has changed since the last call!
        v.SetVoltageCallbackPeriod(1000);

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

    #endregion Fields

    #region Methods

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

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

        // Get threshold callbacks with a debounce time of 10 seconds (10000ms)
        v.SetDebouncePeriod(10000);

        // Register voltage reached callback to function VoltageReachedCB
        v.VoltageReached += VoltageReachedCB;

        // Configure threshold for voltage "greater than 5 V" (unit is mV)
        v.SetVoltageCallbackThreshold('>', 5*1000, 0);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
 // Callback function for voltage callback (parameter has unit mV)
 static void VoltageCB(BrickletVoltage sender, int voltage)
 {
     Console.WriteLine("Voltage: " + voltage/1000.0 + " V");
 }