private static string UID = "XYZ"; // Change XYZ to the UID of your Industrial Quad Relay Bricklet

    #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

        // Turn relays alternating on/off 10 times with 100 ms delay
        for(int i = 0; i < 10; i++)
        {
            Thread.Sleep(100);
            iqr.SetValue(1 << 0);
            Thread.Sleep(100);
            iqr.SetValue(1 << 1);
            Thread.Sleep(100);
            iqr.SetValue(1 << 2);
            Thread.Sleep(100);
            iqr.SetValue(1 << 3);
        }

        Console.WriteLine("Press enter to exit");
        Console.ReadLine();
        ipcon.Disconnect();
    }
Exemplo n.º 2
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();
    }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
0
    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;
                }
            }
        }
    }