// Callback handles device connections and configures possibly lost // configuration of lcd and temperature callbacks, backlight etc. static void EnumerateCB(IPConnection sender, string UID, string connectedUID, char position, short[] hardwareVersion, short[] firmwareVersion, int deviceIdentifier, short enumerationType) { if(enumerationType == IPConnection.ENUMERATION_TYPE_CONNECTED || enumerationType == IPConnection.ENUMERATION_TYPE_AVAILABLE) { // Enumeration is for LCD Bricklet if(deviceIdentifier == BrickletLCD20x4.DEVICE_IDENTIFIER) { // Create lcd device object lcd = new BrickletLCD20x4(UID, ipcon); lcd.ButtonPressed += ButtonPressedCB; lcd.ClearDisplay(); lcd.BacklightOn(); } // Enumeration is for Temperature Bricklet if(deviceIdentifier == BrickletTemperature.DEVICE_IDENTIFIER) { // Create temperature device object temp = new BrickletTemperature(UID, ipcon); temp.Temperature += TemperatureCB; temp.SetTemperatureCallbackPeriod(50); } } }
// Callback handles device connections and configures possibly lost // configuration of lcd and temperature callbacks, backlight etc. static void EnumerateCB(IPConnection sender, string UID, string connectedUID, char position, short[] hardwareVersion, short[] firmwareVersion, int deviceIdentifier, short enumerationType) { if (enumerationType == IPConnection.ENUMERATION_TYPE_CONNECTED || enumerationType == IPConnection.ENUMERATION_TYPE_AVAILABLE) { // Enumeration is for LCD Bricklet if (deviceIdentifier == BrickletLCD20x4.DEVICE_IDENTIFIER) { // Create lcd device object lcd = new BrickletLCD20x4(UID, ipcon); lcd.ButtonPressed += ButtonPressedCB; lcd.ClearDisplay(); lcd.BacklightOn(); } // Enumeration is for Temperature Bricklet if (deviceIdentifier == BrickletTemperature.DEVICE_IDENTIFIER) { // Create temperature device object temp = new BrickletTemperature(UID, ipcon); temp.Temperature += TemperatureCB; temp.SetTemperatureCallbackPeriod(50); } } }
public TemperatureSensor(IPConnection ipConnection, string uid, int sensorCallbackPeriod, Station station) { _tinfluxWeatherStation = station; var bricklet = new BrickletTemperature(uid, ipConnection); // Register callback to function BrickletCb bricklet.TemperatureCallback += BrickletCb; // Note: The callback is only called every "sensorCallbackPeriod" // if the value has changed since the last call! bricklet.SetTemperatureCallbackPeriod(sensorCallbackPeriod); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Temperature Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletTemperature t = new BrickletTemperature(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Register temperature callback to function TemperatureCB t.Temperature += TemperatureCB; // Set period for temperature callback to 1s (1000ms) // Note: The temperature callback is only called every second // if the temperature has changed since the last call! t.SetTemperatureCallbackPeriod(1000); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletTemperature t = new BrickletTemperature(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Register temperature callback to function TemperatureCB t.TemperatureCallback += TemperatureCB; // Set period for temperature callback to 1s (1000ms) // Note: The temperature callback is only called every second // if the temperature has changed since the last call! t.SetTemperatureCallbackPeriod(1000); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }