当前位置: 首页>>代码示例>>C#>>正文


C# IPConnection类代码示例

本文整理汇总了C#中IPConnection的典型用法代码示例。如果您正苦于以下问题:C# IPConnection类的具体用法?C# IPConnection怎么用?C# IPConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IPConnection类属于命名空间,在下文中一共展示了IPConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    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();
    }
开发者ID:Tinkerforge,项目名称:servo-brick,代码行数:32,代码来源:ExampleCallback.cs

示例2: EnumerateCB

    // 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("");
    }
开发者ID:noxer,项目名称:generators,代码行数:26,代码来源:ExampleEnumerate.cs

示例3: Main

    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();
    }
开发者ID:Tinkerforge,项目名称:multi-touch-bricklet,代码行数:40,代码来源:ExampleSimple.cs

示例4: Main

    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();
    }
开发者ID:Tinkerforge,项目名称:industrial-digital-out-4-bricklet,代码行数:32,代码来源:ExampleSimple.cs

示例5: EnumerateCB

    // 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);
            }
        }
    }
开发者ID:flyeven,项目名称:doc,代码行数:31,代码来源:ExampleRugged.cs

示例6: Main

    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();
    }
开发者ID:Tinkerforge,项目名称:tilt-bricklet,代码行数:34,代码来源:ExampleSimple.cs

示例7: Main

    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();
    }
开发者ID:Tinkerforge,项目名称:can-bricklet,代码行数:27,代码来源:ExampleLoopback.cs

示例8: ConnectedCB

 // 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();
 }
开发者ID:flyeven,项目名称:doc,代码行数:8,代码来源:ExampleRugged.cs

示例9: ConnectedCB

    // 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();
    }
开发者ID:noxer,项目名称:generators,代码行数:29,代码来源:ExampleAuthenticate.cs

示例10: EnumerateCB

    // 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);
    }
开发者ID:noxer,项目名称:generators,代码行数:8,代码来源:ExampleAuthenticate.cs

示例11: EnumerateCB

    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;
                }
            }
        }
    }
开发者ID:bojanb,项目名称:hardware-hacking,代码行数:25,代码来源:SmokeDetector.cs

示例12: Main

    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();
    }
开发者ID:Tinkerforge,项目名称:real-time-clock-bricklet,代码行数:36,代码来源:ExampleSimple.cs

示例13: DualButtonInput

    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);
    }
开发者ID:Tinkerforge,项目名称:blinkenlights,代码行数:55,代码来源:KeyPress.cs

示例14: Main

    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();
    }
开发者ID:bojanb,项目名称:hardware-hacking,代码行数:18,代码来源:RemoteSwitch.cs

示例15: Main

    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();
    }
开发者ID:Tinkerforge,项目名称:piezo-buzzer-bricklet,代码行数:21,代码来源:ExampleBeep.cs


注:本文中的IPConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。