// 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 reconnection of IP Connection static void ConnectedCB(IPConnection sender, short connectReason) { // Enumerate devices again. If we reconnected, the Bricks/Bricklets // may have been offline and the configuration may be lost. // In this case we don't care for the reason of the connection ipcon.Enumerate(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Multi Touch Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletMultiTouch mt = new BrickletMultiTouch(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current touch state int state = mt.GetTouchState(); string str = ""; if((state & (1 << 12)) == (1 << 12)) { str += "In proximity, "; } if((state & 0xfff) == 0) { str += "No electrodes touched"; } else { str += "Electrodes "; for(int i = 0; i < 12; i++) { if((state & (1 << i)) == (1 << i)) { str += i + " "; } } str += "touched"; } Console.WriteLine(str); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Tilt Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletTilt t = new BrickletTilt(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current tilt state byte state = t.GetTiltState(); switch(state) { case BrickletTilt.TILT_STATE_CLOSED: Console.WriteLine("Tilt State: Closed"); break; case BrickletTilt.TILT_STATE_OPEN: Console.WriteLine("Tilt State: Open"); break; case BrickletTilt.TILT_STATE_CLOSED_VIBRATING: Console.WriteLine("Tilt State: Closed Vibrating"); break; } Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
// Print incoming enumeration static void EnumerateCB(IPConnection sender, string uid, string connectedUid, char position, short[] hardwareVersion, short[] firmwareVersion, int deviceIdentifier, short enumerationType) { System.Console.WriteLine("UID: " + uid + ", Enumeration Type: " + enumerationType); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Industrial Digital Out 4 Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletIndustrialDigitalOut4 ido4 = new BrickletIndustrialDigitalOut4(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Turn pins alternating high/low 10 times with 100ms delay for(int i = 0; i < 10; i++) { Thread.Sleep(100); ido4.SetValue(1 << 0); Thread.Sleep(100); ido4.SetValue(1 << 1); Thread.Sleep(100); ido4.SetValue(1 << 2); Thread.Sleep(100); ido4.SetValue(1 << 3); } Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
// Print incoming enumeration static void EnumerateCB(IPConnection sender, string uid, string connectedUid, char position, short[] hardwareVersion, short[] firmwareVersion, int deviceIdentifier, short enumerationType) { System.Console.WriteLine("UID: " + uid); System.Console.WriteLine("Enumeration Type: " + enumerationType); if(enumerationType == IPConnection.ENUMERATION_TYPE_DISCONNECTED) { System.Console.WriteLine(""); return; } System.Console.WriteLine("Connected UID: " + connectedUid); System.Console.WriteLine("Position: " + position); System.Console.WriteLine("Hardware Version: " + hardwareVersion[0] + "." + hardwareVersion[1] + "." + hardwareVersion[2]); System.Console.WriteLine("Firmware Version: " + firmwareVersion[0] + "." + firmwareVersion[1] + "." + firmwareVersion[2]); System.Console.WriteLine("Device Identifier: " + deviceIdentifier); System.Console.WriteLine(""); }
// Authenticate each time the connection got (re-)established static void ConnectedCB(IPConnection sender, short connectReason) { switch(connectReason) { case IPConnection.CONNECT_REASON_REQUEST: System.Console.WriteLine("Connected by request"); break; case IPConnection.CONNECT_REASON_AUTO_RECONNECT: System.Console.WriteLine("Auto-Reconnected"); break; } // Authenticate first... try { sender.Authenticate(SECRET); System.Console.WriteLine("Authentication succeeded"); } catch(TinkerforgeException) { System.Console.WriteLine("Could not authenticate"); return; } // ...then trigger enumerate sender.Enumerate(); }
private static string UID = "XXYYZZ"; // Change XXYYZZ to the UID of your Servo Brick #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickServo servo = new BrickServo(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Register position reached callback to function PositionReachedCB servo.PositionReached += PositionReachedCB; // Enable position reached callback servo.EnablePositionReachedCallback(); // Set velocity to 100°/s. This has to be smaller or equal to the // maximum velocity of the servo you are using, otherwise the position // reached callback will be called too early servo.SetVelocity(0, 10000); servo.SetPosition(0, 9000); servo.Enable(0); Console.WriteLine("Press enter to exit"); Console.ReadLine(); servo.Disable(0); ipcon.Disconnect(); }
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) { if(deviceIdentifier == BrickletIndustrialDigitalIn4.DEVICE_IDENTIFIER) { try { brickletIndustrialDigitalIn4 = new BrickletIndustrialDigitalIn4(UID, ipcon); brickletIndustrialDigitalIn4.SetDebouncePeriod(10000); brickletIndustrialDigitalIn4.SetInterrupt(15); brickletIndustrialDigitalIn4.Interrupt += InterruptCB; System.Console.WriteLine("Industrial Digital In 4 initialized"); } catch(TinkerforgeException e) { System.Console.WriteLine("Industrial Digital In 4 init failed: " + e.Message); brickletIndustrialDigitalIn4 = null; } } } }
private static string UID = "XYZ"; // Change XYZ to the UID of your Real-Time Clock Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletRealTimeClock rtc = new BrickletRealTimeClock(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current date and time int year; byte month, day, hour, minute, second, centisecond, weekday; rtc.GetDateTime(out year, out month, out day, out hour, out minute, out second, out centisecond, out weekday); Console.WriteLine("Year: " + year); Console.WriteLine("Month: " + month); Console.WriteLine("Day: " + day); Console.WriteLine("Hour: " + hour); Console.WriteLine("Minute: " + minute); Console.WriteLine("Second: " + second); Console.WriteLine("Centisecond: " + centisecond); Console.WriteLine("Weekday: " + weekday); // Get current timestamp (unit is ms) long timestamp = rtc.GetTimestamp(); Console.WriteLine("Timestamp: " + timestamp + " ms"); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletCAN can = new BrickletCAN(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Configure transceiver for loopback mode can.SetConfiguration(BrickletCAN.BAUD_RATE_1000KBPS, BrickletCAN.TRANSCEIVER_MODE_LOOPBACK, 0); // Register frame read callback to function FrameReadCB can.FrameRead += FrameReadCB; // Enable frame read callback can.EnableFrameReadCallback(); // Write standard data frame with identifier 1742 and 3 bytes of data byte[] data = new byte[8]{42, 23, 17, 0, 0, 0, 0, 0}; can.WriteFrame(BrickletCAN.FRAME_TYPE_STANDARD_DATA, 1742, data, 3); Console.WriteLine("Press enter to exit"); Console.ReadLine(); can.DisableFrameReadCallback(); ipcon.Disconnect(); }
public DualButtonInput(IPConnection ipcon, BlockingQueue<char> keyQueue) { this.keyQueue = keyQueue; byte buttonL; byte buttonR; if (Config.UID_DUAL_BUTTON_BRICKLET[0] == null) { System.Console.WriteLine("Not Configured: Dual Button 1"); } else { dualButton1 = new BrickletDualButton(Config.UID_DUAL_BUTTON_BRICKLET[0], ipcon); try { dualButton1.GetButtonState(out buttonL, out buttonR); System.Console.WriteLine("Found: Dual Button 1 ({0})", Config.UID_DUAL_BUTTON_BRICKLET[0]); } catch (TinkerforgeException) { System.Console.WriteLine("Not Found: Dual Button 1 ({0})", Config.UID_DUAL_BUTTON_BRICKLET[0]); } dualButton1.StateChanged += StateChanged1CB; } if (Config.UID_DUAL_BUTTON_BRICKLET[1] == null) { System.Console.WriteLine("Not Configured: Dual Button 2"); } else { dualButton2 = new BrickletDualButton(Config.UID_DUAL_BUTTON_BRICKLET[1], ipcon); try { dualButton2.GetButtonState(out buttonL, out buttonR); System.Console.WriteLine("Found: Dual Button 2 ({0})", Config.UID_DUAL_BUTTON_BRICKLET[0]); } catch (TinkerforgeException) { System.Console.WriteLine("Not Found: Dual Button 2 ({0})", Config.UID_DUAL_BUTTON_BRICKLET[0]); } dualButton2.StateChanged += StateChanged2CB; } pressTimer = new Timer(delegate(object state) { PressTick(); }, null, 100, 100); }
private static int VALUE_B_ON = (1 << 1) | (1 << 2); // Pin 1 and 2 high #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletIndustrialQuadRelay iqr = new BrickletIndustrialQuadRelay(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected iqr.SetMonoflop(VALUE_A_ON, 15, 1500); // Set pins to high for 1.5 seconds ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Analog Out Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletAnalogOut ao = new BrickletAnalogOut(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Set output voltage to 3.3V ao.SetVoltage(3300); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Piezo Speaker Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletPiezoSpeaker ps = new BrickletPiezoSpeaker(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Morse SOS with a frequency of 2kHz ps.MorseCode("... --- ...", 2000); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Piezo Buzzer Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletPiezoBuzzer pb = new BrickletPiezoBuzzer(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Morse SOS pb.MorseCode("... --- ..."); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Dual Button Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletDualButton db = new BrickletDualButton(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Register state changed callback to function StateChangedCB db.StateChanged += StateChangedCB; Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your RGB LED Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletRGBLED rl = new BrickletRGBLED(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Set light blue color rl.SetRGBValue(0, 170, 234); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Multi Touch Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletMultiTouch mt = new BrickletMultiTouch(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Register touch state callback to function TouchStateCB mt.TouchState += TouchStateCB; Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Piezo Buzzer Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletPiezoBuzzer pb = new BrickletPiezoBuzzer(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Make 2 second beep pb.Beep(2000); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your UV Light Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletUVLight uvl = new BrickletUVLight(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current UV light (unit is µW/cm²) long uvLight = uvl.GetUVLight(); Console.WriteLine("UV Light: " + uvLight + " µW/cm²"); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your IO-4 Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletIO4 io = new BrickletIO4(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current value as bitmask byte valueMask = io.GetValue(); Console.WriteLine("Value Mask: " + Convert.ToString(valueMask, 2)); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Line Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletLine l = new BrickletLine(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current reflectivity int reflectivity = l.GetReflectivity(); Console.WriteLine("Reflectivity: " + reflectivity); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Distance US Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletDistanceUS dus = new BrickletDistanceUS(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current distance value int distance = dus.GetDistanceValue(); Console.WriteLine("Distance Value: " + distance); 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 #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 Current25 Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletCurrent25 c = new BrickletCurrent25(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current current (unit is mA) short current = c.GetCurrent(); Console.WriteLine("Current: " + current/1000.0 + " A"); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Ambient Light Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletAmbientLight al = new BrickletAmbientLight(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current illuminance (unit is Lux/10) int illuminance = al.GetIlluminance(); Console.WriteLine("Illuminance: " + illuminance/10.0 + " Lux"); 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 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 Linear Poti Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletLinearPoti lp = new BrickletLinearPoti(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current position (range is 0 to 100) int position = lp.GetPosition(); Console.WriteLine("Position: " + position); 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 // Get threshold callbacks with a debounce time of 10 seconds (10000ms) t.SetDebouncePeriod(10000); // Register temperature reached callback to function TemperatureReachedCB t.TemperatureReachedCallback += TemperatureReachedCB; // Configure threshold for temperature "greater than 30 °C" (unit is °C/100) t.SetTemperatureCallbackThreshold('>', 30 * 100, 0); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletUVLight uvl = new BrickletUVLight(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) uvl.SetDebouncePeriod(10000); // Register UV light reached callback to function UVLightReachedCB uvl.UVLightReachedCallback += UVLightReachedCB; // Configure threshold for UV light "greater than 75 mW/m²" uvl.SetUVLightCallbackThreshold('>', 75 * 10, 0); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletAnalogInV2 ai = new BrickletAnalogInV2(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) ai.SetDebouncePeriod(10000); // Register voltage reached callback to function VoltageReachedCB ai.VoltageReachedCallback += VoltageReachedCB; // Configure threshold for voltage "smaller than 5 V" ai.SetVoltageCallbackThreshold('<', 5 * 1000, 0); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your E-Paper 296x128 Bricklet static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletEPaper296x128 ep = new BrickletEPaper296x128(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Use black background ep.FillDisplay(BrickletEPaper296x128.COLOR_BLACK); // Write big white "Hello World" in the middle of the screen ep.DrawText(16, 48, BrickletEPaper296x128.FONT_24X32, BrickletEPaper296x128.COLOR_WHITE, BrickletEPaper296x128.ORIENTATION_HORIZONTAL, "Hello World"); ep.Draw(); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletJoystick j = new BrickletJoystick(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 0.2 seconds (200ms) j.SetDebouncePeriod(200); // Register position reached callback to function PositionReachedCB j.PositionReachedCallback += PositionReachedCB; // Configure threshold for position "outside of -99, -99 to 99, 99" j.SetPositionCallbackThreshold('o', -99, 99, -99, 99); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletLine l = new BrickletLine(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 1 second (1000ms) l.SetDebouncePeriod(1000); // Register reflectivity reached callback to function ReflectivityReachedCB l.ReflectivityReachedCallback += ReflectivityReachedCB; // Configure threshold for reflectivity "greater than 2000" l.SetReflectivityCallbackThreshold('>', 2000, 0); 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(); }
static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletDistanceUS dus = new BrickletDistanceUS(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) dus.SetDebouncePeriod(10000); // Register distance value reached callback to function DistanceReachedCB dus.DistanceReachedCallback += DistanceReachedCB; // Configure threshold for distance value "smaller than 200" dus.SetDistanceCallbackThreshold('<', 200, 0); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
static void ConnectedCB(IPConnection sender, short connectedReason) { if (connectedReason == IPConnection.CONNECT_REASON_AUTO_RECONNECT) { System.Console.WriteLine("Auto Reconnect"); while (true) { try { ipcon.Enumerate(); break; } catch (NotConnectedException e) { System.Console.WriteLine("Enumeration Error: " + e.Message); System.Threading.Thread.Sleep(1000); } } } }
private void ConnectedCB(IPConnection sender, short connectedReason) { if (connectedReason == IPConnection.CONNECT_REASON_AUTO_RECONNECT) { Log("Auto Reconnect"); while (true) { try { ipcon.Enumerate(); break; } catch (NotConnectedException e) { Log("Enumeration Error: " + e.Message); Thread.Sleep(1000); } } } }
static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletRS232V2 rs232 = new BrickletRS232V2(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Register read callback to function ReadCB rs232.ReadCallback += ReadCB; // Enable read callback rs232.EnableReadCallback(); // Write "test" string rs232.Write("test".ToCharArray()); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletAmbientLightV2 al = new BrickletAmbientLightV2(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) al.SetDebouncePeriod(10000); // Register illuminance reached callback to function IlluminanceReachedCB al.IlluminanceReachedCallback += IlluminanceReachedCB; // Configure threshold for illuminance "greater than 500 lx" al.SetIlluminanceCallbackThreshold('>', 500 * 100, 0); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your CO2 Bricklet 2.0 static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletCO2V2 co2 = new BrickletCO2V2(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current all values int co2Concentration, humidity; short temperature; co2.GetAllValues(out co2Concentration, out temperature, out humidity); Console.WriteLine("CO2 Concentration: " + co2Concentration + " ppm"); Console.WriteLine("Temperature: " + temperature / 100.0 + " °C"); Console.WriteLine("Humidity: " + humidity / 100.0 + " %RH"); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletColor c = new BrickletColor(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) c.SetDebouncePeriod(10000); // Register color reached callback to function ColorReachedCB c.ColorReachedCallback += ColorReachedCB; // Configure threshold for color "greater than 100, 200, 300, 400" c.SetColorCallbackThreshold('>', 100, 0, 200, 0, 300, 0, 400, 0); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private async void btn_addIP_Click(object sender, EventArgs e) { this.Enabled = false; bool success = false; int loop = 0; do { if (loop == 10) { break; } try { IPConnection ipConn = new IPConnection(); IP ip = new IP(); ip.ipAddress = txt_ip.Text.Replace(".", "_"); ip.availability = rb_availability_true.Checked; await ipConn.Insert(ip); success = true; loadIPWithWaitForm(); resetInputIP(); } catch { loop++; Thread.Sleep(2000); } } while (!success); if (!success) { MessageBox.Show("Đã thử " + loop + " lần mà *** đc :))"); this.Enabled = true; } this.Enabled = true; }
static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletThermalImaging ti = new BrickletThermalImaging(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected CreateThermalImageColorPalette(); // Enable high contrast image transfer for callback ti.SetImageTransferConfig(BrickletThermalImaging.IMAGE_TRANSFER_MANUAL_HIGH_CONTRAST_IMAGE); // If we change between transfer modes we have to wait until one more // image is taken after the mode is set and the first image is saved // we can call GetHighContrastImage any time. Thread.Sleep(250); byte[] imageData = ti.GetHighContrastImage(); // Create PNG with Bitmap from System.Drawing Bitmap bitmap = new Bitmap(80, 60); for (int row = 0; row < 80; row++) { for (int col = 0; col < 60; col++) { int color = imageData[row + col * 80]; bitmap.SetPixel(row, col, Color.FromArgb(paletteR[color], paletteG[color], paletteB[color])); } } // Scale to 800x600 and save thermal image! bitmap = new Bitmap(bitmap, new Size(80 * 10, 60 * 10)); bitmap.Save("thermal_image.png", ImageFormat.Png); System.Console.WriteLine("Press enter to exit"); System.Console.ReadLine(); ipcon.Disconnect(); }
static void Main() { ipcon = new IPConnection(); while (true) { try { ipcon.Connect(HOST, PORT); break; } catch (System.Net.Sockets.SocketException e) { System.Console.WriteLine("Connection Error: " + e.Message); System.Threading.Thread.Sleep(1000); } } ipcon.EnumerateCallback += EnumerateCB; ipcon.Connected += ConnectedCB; while (true) { try { ipcon.Enumerate(); break; } catch (NotConnectedException e) { System.Console.WriteLine("Enumeration Error: " + e.Message); System.Threading.Thread.Sleep(1000); } } timer = new Timer(Update, null, TimeSpan.Zero, TimeSpan.FromSeconds(1)); System.Console.WriteLine("Press enter to exit"); System.Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Particulate Matter Bricklet static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletParticulateMatter pm = new BrickletParticulateMatter(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current PM concentration int pm10, pm25, pm100; pm.GetPMConcentration(out pm10, out pm25, out pm100); Console.WriteLine("PM 1.0: " + pm10 + " µg/m³"); Console.WriteLine("PM 2.5: " + pm25 + " µg/m³"); Console.WriteLine("PM 10.0: " + pm100 + " µg/m³"); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Color Bricklet static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletColor c = new BrickletColor(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current color int r, g, b, c_; c.GetColor(out r, out g, out b, out c_); Console.WriteLine("Color [R]: " + r); Console.WriteLine("Color [G]: " + g); Console.WriteLine("Color [B]: " + b); Console.WriteLine("Color [C]: " + c_); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private 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) { if (deviceIdentifier == BrickletIndustrialQuadRelay.DEVICE_IDENTIFIER) { try { brickletIndustrialQuadRelay = new BrickletIndustrialQuadRelay(UID, ipcon); Log("Industrial Quad Relay initialized"); } catch (TinkerforgeException e) { Log("Industrial Quad Relay init failed: " + e.Message); brickletIndustrialQuadRelay = null; } } } }
private static string UID = "XYZ"; // Change XYZ to the UID of your Segment Display 4x7 Bricklet 2.0 static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletSegmentDisplay4x7V2 sd = new BrickletSegmentDisplay4x7V2(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected sd.SetBrightness(7); // Set to full brightness // Activate all segments sd.SetSegments(new bool[] { true, true, true, true, true, true, true, true }, new bool[] { true, true, true, true, true, true, true, true }, new bool[] { true, true, true, true, true, true, true, true }, new bool[] { true, true, true, true, true, true, true, true }, new bool[] { true, true }, true); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your IMU Bricklet 3.0 static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletIMUV3 imu = new BrickletIMUV3(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current quaternion short w, x, y, z; imu.GetQuaternion(out w, out x, out y, out z); Console.WriteLine("Quaternion [W]: " + w / 16383.0); Console.WriteLine("Quaternion [X]: " + x / 16383.0); Console.WriteLine("Quaternion [Y]: " + y / 16383.0); Console.WriteLine("Quaternion [Z]: " + z / 16383.0); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Accelerometer Bricklet 2.0 static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletAccelerometerV2 a = new BrickletAccelerometerV2(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current acceleration int x, y, z; a.GetAcceleration(out x, out y, out z); Console.WriteLine("Acceleration [X]: " + x / 10000.0 + " g"); Console.WriteLine("Acceleration [Y]: " + y / 10000.0 + " g"); Console.WriteLine("Acceleration [Z]: " + z / 10000.0 + " g"); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Industrial Dual Relay Bricklet static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletIndustrialDualRelay idr = new BrickletIndustrialDualRelay(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Turn relays alternating on/off 10 times with 1 second delay for (int i = 0; i < 5; i++) { Thread.Sleep(1000); idr.SetValue(true, false); Thread.Sleep(1000); idr.SetValue(false, true); } Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
static void Main() { // Create IP Connection IPConnection ipcon = new IPConnection(); // Disable auto reconnect mechanism, in case we have the wrong secret. // If the authentication is successful, reenable it. ipcon.SetAutoReconnect(false); // Register Connected Callback ipcon.Connected += ConnectedCB; // Register Enumerate Callback ipcon.EnumerateCallback += EnumerateCB; // Connect to brickd ipcon.Connect(HOST, PORT); System.Console.WriteLine("Press key to exit"); System.Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Servo Bricklet 2.0 static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletServoV2 s = new BrickletServoV2(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Servo 1: Connected to port 0, period of 19.5ms, pulse width of 1 to 2ms // and operating angle -100 to 100° s.SetDegree(0, -10000, 10000); s.SetPulseWidth(0, 1000, 2000); s.SetPeriod(0, 19500); s.SetMotionConfiguration(0, 500000, 1000, 1000); // Full velocity with slow ac-/deceleration // Servo 2: Connected to port 5, period of 20ms, pulse width of 0.95 to 1.95ms // and operating angle -90 to 90° s.SetDegree(5, -9000, 9000); s.SetPulseWidth(5, 950, 1950); s.SetPeriod(5, 20000); s.SetMotionConfiguration(5, 500000, 500000, 500000); // Full velocity with full ac-/deceleration s.SetPosition(0, 10000); // Set to most right position s.SetEnable(0, true); s.SetPosition(5, -9000); // Set to most left position s.SetEnable(5, true); Console.WriteLine("Press enter to exit"); Console.ReadLine(); s.SetEnable(0, false); s.SetEnable(5, false); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your GPS Bricklet 3.0 static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletGPSV3 gps = new BrickletGPSV3(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current coordinates long latitude, longitude; char ns, ew; gps.GetCoordinates(out latitude, out ns, out longitude, out ew); Console.WriteLine("Latitude: " + latitude / 1000000.0 + " °"); Console.WriteLine("N/S: " + ns); Console.WriteLine("Longitude: " + longitude / 1000000.0 + " °"); Console.WriteLine("E/W: " + ew); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
public TFRoboticArmWith6DOF() { // Connection to brickd ipcon = new IPConnection(); servo = new BrickServo(UID, ipcon); ipcon.Connect(HOST, PORT); servo.SetOutputVoltage(5000); // 5V MotorConfiguration mcServoTypeA = new MotorConfiguration(); mcServoTypeA.SetValue("Degree_Min", "-6700"); mcServoTypeA.SetValue("Degree_Max", "6700"); mcServoTypeA.SetValue("PulseWidth_Min", "800"); mcServoTypeA.SetValue("PulseWidth_Max", "2700"); mcServoTypeA.SetValue("Period", "19500"); mcServoTypeA.SetValue("Acceleration", "65535"); mcServoTypeA.SetValue("Velocity", "65535"); mcServoTypeA.SetValue("Position", "0"); MotorConfiguration mcServoTypeB = new MotorConfiguration(); mcServoTypeB.SetValue("Degree_Min", "-6700"); mcServoTypeB.SetValue("Degree_Max", "6700"); mcServoTypeB.SetValue("PulseWidth_Min", "800"); mcServoTypeB.SetValue("PulseWidth_Max", "2100"); mcServoTypeB.SetValue("Period", "19500"); mcServoTypeB.SetValue("Acceleration", "65535"); mcServoTypeB.SetValue("Velocity", "65535"); mcServoTypeB.SetValue("Position", "0"); SetMotorConfiguration(JOINT1_SERVO, mcServoTypeA); SetMotorConfiguration(JOINT2_SERVO, mcServoTypeA); SetMotorConfiguration(JOINT3_SERVO, mcServoTypeB); SetMotorConfiguration(JOINT4_SERVO, mcServoTypeB); SetMotorConfiguration(JOINT5_SERVO, mcServoTypeB); SetMotorConfiguration(JOINT6_SERVO, mcServoTypeB); }
private void Connect() { Log("Connecting to " + HOST + ":" + PORT); ipcon = new IPConnection(); while (true) { try { ipcon.Connect(HOST, PORT); break; } catch (System.Net.Sockets.SocketException e) { Log("Connection Error: " + e.Message); Thread.Sleep(1000); } } ipcon.EnumerateCallback += EnumerateCB; ipcon.Connected += ConnectedCB; while (true) { try { ipcon.Enumerate(); break; } catch (NotConnectedException e) { Log("Enumeration Error: " + e.Message); Thread.Sleep(1000); } } Log("Connected"); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Voltage/Current Bricklet 2.0 static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletVoltageCurrentV2 vc = new BrickletVoltageCurrentV2(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current voltage int voltage = vc.GetVoltage(); Console.WriteLine("Voltage: " + voltage / 1000.0 + " V"); // Get current current int current = vc.GetCurrent(); Console.WriteLine("Current: " + current / 1000.0 + " A"); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }