Connect() public method

public Connect ( ) : void
return void
    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();
    }
    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();
    }
Esempio n. 3
0
    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();
    }
    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();
    }
    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();
    }
Esempio n. 6
0
    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();
    }
Esempio n. 7
0
    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 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 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 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 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 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 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();
    }
Esempio n. 15
0
    static void Main()
    {
        // Create connection and connect to brickd
        IPConnection ipcon = new IPConnection();
        ipcon.Connect(HOST, PORT);

        // Register Enumerate Callback
        ipcon.EnumerateCallback += EnumerateCB;

        // Trigger Enumerate
        ipcon.Enumerate();

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

    #endregion Fields

    #region Methods

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

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

        // Get current distance (unit is mm)
        int distance = dir.GetDistance();
        Console.WriteLine("Distance: " + distance/10.0 + " cm");

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

    #endregion Fields

    #region Methods

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

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

        // Get current pressure (unit is Pa)
        int pressure = p.GetPressure();
        Console.WriteLine("Pressure: " + pressure/1000.0 + " kPa");

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

    #endregion Fields

    #region Methods

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

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

        // Get current temperature (unit is °C/100)
        int temperature = t.GetTemperature();
        Console.WriteLine("Temperature: " + temperature/100.0 + " °C");

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

    #endregion Fields

    #region Methods

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

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

        // Get current intensity
        int intensity = si.GetIntensity();
        Console.WriteLine("Intensity: " + intensity);

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

    #endregion Fields

    #region Methods

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

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

        // Get current moisture value
        int moisture = m.GetMoistureValue();
        Console.WriteLine("Moisture Value: " + moisture);

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

    #endregion Fields

    #region Methods

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

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

        // Get current heart rate (unit is bpm)
        int heartRate = hr.GetHeartRate();
        Console.WriteLine("Heart Rate: " + heartRate + " bpm");

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
Esempio n. 22
0
    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();
    }
Esempio n. 23
0
    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 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 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 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 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 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();
    }
    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 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();
    }
Esempio n. 32
0
    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();
    }
Esempio n. 33
0
    private static string UID  = "XYZ";    // Change XYZ to the UID of your GPS Bricklet

    static void Main()
    {
        IPConnection ipcon = new IPConnection();          // Create IP connection
        BrickletGPS  gps   = new BrickletGPS(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; int pdop, hdop, vdop, epe;

        gps.GetCoordinates(out latitude, out ns, out longitude, out ew, out pdop,
                           out hdop, out vdop, out epe);

        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();
    }
Esempio n. 34
0
    private static string UID  = "XYZ";    // Change XYZ to the UID of your TNG DI8

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

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

        // Get current values
        bool[] values = di8.GetValues();

        Console.WriteLine("Channel 0: " + values[0]);
        Console.WriteLine("Channel 1: " + values[1]);
        Console.WriteLine("Channel 2: " + values[2]);
        Console.WriteLine("Channel 3: " + values[3]);
        Console.WriteLine("Channel 4: " + values[4]);
        Console.WriteLine("Channel 5: " + values[5]);
        Console.WriteLine("Channel 6: " + values[6]);
        Console.WriteLine("Channel 7: " + values[7]);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
Esempio n. 35
0
    private static string UID  = "XYZ";    // Change XYZ to the UID of your DC Bricklet 2.0

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

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

        dc.SetDriveMode(BrickletDCV2.DRIVE_MODE_DRIVE_COAST);
        dc.SetPWMFrequency(10000);   // Use PWM frequency of 10 kHz
        dc.SetMotion(4096,
                     16384);         // Slow acceleration (12.5 %/s), fast decceleration (50 %/s) for stopping
        dc.SetVelocity(32767);       // Full speed forward (100 %)
        dc.SetEnabled(true);         // Enable motor power

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();

        dc.SetVelocity(0);         // Stop motor before disabling motor power
        Thread.Sleep(2000);        // Wait for motor to actually stop: velocity (100 %) / decceleration (50 %/s) = 2 s
        dc.SetEnabled(false);      // Disable motor power

        ipcon.Disconnect();
    }
Esempio n. 36
0
    static void Main()
    {
        IPConnection  ipcon = new IPConnection();            // Create IP connection
        BrickletRS485 rs485 = new BrickletRS485(UID, ipcon); // Create device object

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

        // Set operating mode to Modbus RTU slave
        rs485.SetMode(BrickletRS485.MODE_MODBUS_SLAVE_RTU);

        // Modbus specific configuration:
        // - slave address = 17
        // - master request timeout = 0ms (unused in slave mode)
        rs485.SetModbusConfiguration(17, 0);

        // Register Modbus slave write single register request callback to function
        // ModbusSlaveWriteSingleRegisterRequestCB
        rs485.ModbusSlaveWriteSingleRegisterRequestCallback += ModbusSlaveWriteSingleRegisterRequestCB;

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
Esempio n. 37
0
    static void Main()
    {
        IPConnection ipcon = new IPConnection();      // Create IP connection
        BrickDC      dc    = new BrickDC(UID, ipcon); // Create device object

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

        // Register "velocity reached callback" to ReachedCB
        // ReachedCB will be called every time a velocity set with
        // SetVelocity is reached
        dc.VelocityReached += ReachedCB;

        dc.Enable();
        // The acceleration has to be smaller or equal to the maximum acceleration
        // of the DC motor, otherwise ReachedCB will be called too early
        dc.SetAcceleration(5000);      // Slow acceleration
        dc.SetVelocity(32767);         // Full speed forward

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

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

        // Register touch position callback to function TouchPositionCB
        lcd.TouchPositionCallback += TouchPositionCB;

        // Register touch gesture callback to function TouchGestureCB
        lcd.TouchGestureCallback += TouchGestureCB;

        // Set period for touch position callback to 0.1s (100ms)
        lcd.SetTouchPositionCallbackConfiguration(100, true);

        // Set period for touch gesture callback to 0.1s (100ms)
        lcd.SetTouchGestureCallbackConfiguration(100, true);

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
Esempio n. 39
0
    private static string UID  = "XYZ";    // Change XYZ to the UID of your IO-4 Bricklet 2.0

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

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

        // Configure channel 3 as output low
        io.SetConfiguration(3, 'o', false);

        // Set channel 3 alternating high/low 10 times with 100 ms delay
        for (int i = 0; i < 10; i++)
        {
            Thread.Sleep(100);
            io.SetSelectedValue(3, true);
            Thread.Sleep(100);
            io.SetSelectedValue(3, false);
        }

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
Esempio n. 40
0
        private void ConnectWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string[] argument = e.Argument as string[];

            ipcon = new IPConnection();

            try
            {
                relay = new BrickletIndustrialQuadRelay(argument[2], ipcon);
            }
            catch (ArgumentOutOfRangeException)
            {
                e.Result = ConnectResult.NO_DEVICE;
                return;
            }

            try
            {
                ipcon.Connect(argument[0], Convert.ToInt32(argument[1]));
            }
            catch (System.IO.IOException)
            {
                e.Result = ConnectResult.NO_CONNECTION;
                return;
            }
            catch (ArgumentOutOfRangeException)
            {
                e.Result = ConnectResult.NO_CONNECTION;
                return;
            }

            try
            {
                string uid;
                string connectedUid;
                char   position;
                byte[] hardwareVersion;
                byte[] firmwareVersion;
                int    deviceIdentifier;

                relay.GetIdentity(out uid, out connectedUid, out position,
                                  out hardwareVersion, out firmwareVersion, out deviceIdentifier);

                if (deviceIdentifier != BrickletIndustrialQuadRelay.DEVICE_IDENTIFIER)
                {
                    ipcon.Disconnect();
                    e.Result = ConnectResult.NO_DEVICE;
                    return;
                }
            }
            catch (TinkerforgeException)
            {
                try
                {
                    ipcon.Disconnect();
                }
                catch (NotConnectedException)
                {
                }

                e.Result = ConnectResult.NO_DEVICE;
                return;
            }

            e.Result = ConnectResult.SUCCESS;
        }
Esempio n. 41
0
 public void Connect()
 {
     _ipConnection.Connect(HOST, PORT);
 }
Esempio n. 42
0
        public void doSmth()
        {
            //Create IP Connection
            IPConnection ipcon = new IPConnection();

            // Connect to brickd
            ipcon.Connect(HOST, PORT);

            var BrickletLCD          = new BrickletLCD20x4(SECRET_LCD, ipcon);
            var BrickletAmbientLight = new BrickletAmbientLight(SECRET_AMBIENTLIGHT, ipcon);
            var BrickletCO2          = new BrickletCO2(SECRET_CO2, ipcon);
            var BrickletBarometer    = new BrickletBarometer(SECRET_BAROMETER, ipcon);
            var BrickletTemperature  = new BrickletTemperature(SECRET_TEMPERATURE, ipcon);

            int i = 100;

            var data = new Bricklet_Model();
            var tb   = new Thingsboard();


            while (true)
            {
                var co2value       = BrickletCO2.GetCO2Concentration();                          // unit ppm - parts per million
                var lightvalue     = BrickletAmbientLight.GetAnalogValue();                      // lcd
                var barometervalue = String.Format("{0:n}", BrickletBarometer.GetAirPressure()); // in mbar
                // var barometervalue = bV / 1000;

                double tempvalue = (Math.Round((double)BrickletTemperature.GetTemperature() * 100) / 10000) - 5; // in °c


                tb.LightValue  = lightvalue;
                tb.Barometer   = Convert.ToDouble(barometervalue) / 1000;
                tb.Temperature = tempvalue;
                tb.CO2         = co2value;
                //tb.LightValue = 100;
                //tb.Barometer = 99;
                //tb.Temperature = 98;
                //tb.CO2 = 97;
                c.PublishMessage(tb);

                /*
                 * var temperatur = new Temperatur();
                 * _context.Temperatur.Add(temperatur);
                 * _context.Entry(temperatur).CurrentValues.SetValues(new Temperatur { Datum = new DateTime(), Einheit = "Grad", Wert = CO2Value, idTemperatur = i++ });
                 * _context.SaveChanges();
                 */
                BrickletLCD.SetConfig(true, true);
                BrickletLCD.BacklightOn();
                Console.WriteLine(
                    " LightValue: " + lightvalue + " BarometerValue " +
                    barometervalue + "mbar " + " TempValue " + tempvalue.ToString() + "°C " + " CO2-Value: " + co2value);
                BrickletLCD.WriteLine(0, 0, "CO2 Value: " + co2value.ToString());
                BrickletLCD.WriteLine(1, 0, "LightValue: " + lightvalue.ToString());
                BrickletLCD.WriteLine(2, 0, "BarometerValue:" + barometervalue.ToString());
                BrickletLCD.WriteLine(3, 0, "Temperature " + tempvalue.ToString());

                Thread.Sleep(500);
            }

            ipcon.Disconnect();
        }
Esempio n. 43
0
        public void TestConnection()
        {
            IPConnection ipcon              = new IPConnection();                 // Create IP connection
            BrickMaster  master             = new BrickMaster(_uidMaster, ipcon); // Create device object
            BrickletIndustrialQuadRelay or1 = new BrickletIndustrialQuadRelay(_uidRelay1, ipcon);
            BrickletIndustrialQuadRelay or2 = new BrickletIndustrialQuadRelay(_uidRelay2, ipcon);
            BrickletTemperatureIR       tir = new BrickletTemperatureIR(_uidTemp, ipcon);

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

            // Get current stack voltage (unit is mV)
            int stackVoltage = master.GetStackVoltage();

            Console.WriteLine("Stack Voltage: " + stackVoltage / 1000.0 + " V");

            // Get current stack current (unit is mA)
            int stackCurrent = master.GetStackCurrent();

            Console.WriteLine("Stack Current: " + stackCurrent / 1000.0 + " A");

            short chipTemp = tir.GetAmbientTemperature();

            Console.WriteLine("Chibi master address: " + chipTemp / 10 + "°/C");

            int delay = 50;

            while (true)
            {
                ConsoleKeyInfo insertKey = Console.ReadKey();
                int            result    = insertKey.KeyChar;
                // UP
                if (result.Equals(32))
                {
                    or1.SetValue(1 << 0);
                    Thread.Sleep(delay);
                    or1.SetValue(1 << 0);
                    Thread.Sleep(delay);
                }
                // DOWN
                if (result.Equals(32))
                {
                    or1.SetValue(1 << 0);
                    Thread.Sleep(delay);
                    or1.SetValue(1 << 0);
                    Thread.Sleep(delay);
                }
                // LEFT
                if (result.Equals(97))
                {
                    or1.SetValue(1 << 0);
                    Thread.Sleep(delay);
                    or1.SetValue(1 << 0);
                    Thread.Sleep(delay);
                }
                // RIGHT
                if (result.Equals(32))
                {
                    or1.SetValue(1 << 0);
                    Thread.Sleep(delay);
                    or1.SetValue(1 << 0);
                    Thread.Sleep(delay);
                }
                // START
                if (result.Equals(115))
                {
                    or2.SetValue(1);
                    Thread.Sleep(delay);
                    or2.SetValue(0);
                    Thread.Sleep(delay);
                }
                // SELECT
                if (result.Equals(83))
                {
                    or2.SetValue(4);
                    Thread.Sleep(delay);
                    or2.SetValue(0);
                    Thread.Sleep(delay);
                }
                // A
                if (result.Equals(97))
                {
                    or2.SetValue(2);
                    Thread.Sleep(delay);
                    or2.SetValue(0);
                    Thread.Sleep(delay);
                }
                // B
                if (result.Equals(98))
                {
                    or2.SetValue(8);
                    Thread.Sleep(delay);
                    or2.SetValue(0);
                    Thread.Sleep(delay);
                }
                Console.WriteLine(result);
                // ESC for EXIT
                if (result.Equals(27))
                {
                    break;
                }
            }
            ipcon.Disconnect();
        }