Control Remote Mains Switches using Visual Basic .NET

For this project we are assuming, that you have a Visual Basic .NET development environment set up and that you have a rudimentary understanding of the Visual Basic .NET language.

If you are totally new to Visual Basic .NET itself you should start here. If you are new to the Tinkerforge API, you should start here.

We are also assuming that you have the remote control connected to an Industrial Quad Relay Bricklet as described here.

Goals

The goal of this little project is to give an idea how the relays of the Industrial Quad Relay Bricklet have to be switched to turn the mains switches on/off.

The following code uses SetMonoflop() to trigger a button press on the remote control. A monoflop will set a new state (relay open or close) and hold it for a given time (1.5s in the example code). After this time the previous state is restored. This approach simulates a button click that takes 1.5s (1500ms).

According to the hardware setup section the inputs of the remote control should be connected as follows:

Signal Relay
A 0
B 1
ON 2
OFF 3

To trigger the switch "A ON" of the remote control the relays 0 and 2 of the Industrial Quad Relay Bricklet have to be closed. This is represented by the selection mask (1 << 0) | (1 << 2).

So the monoflop function should be called with this selection mask and a time of 1500ms to simulate a button press of "A ON". See the following source code for a minimal example.

Source Code

Download

Imports Tinkerforge

Module ExampleSimple
    Const HOST As String = "localhost"
    Const PORT As Integer = 4223
    Const UID As String = "ctG" ' Change to your UID
    Const VALUE_A_ON  As Integer = (1 << 0) Or (1 << 2) ' Pin 0 and 2 high
    Const VALUE_A_OFF As Integer = (1 << 0) Or (1 << 3) ' Pin 0 and 3 high
    Const VALUE_B_ON  As Integer = (1 << 1) Or (1 << 2) ' Pin 1 and 2 high
    Const VALUE_B_OFF As Integer = (1 << 1) Or (1 << 3) ' Pin 1 and 3 high

    Sub Main()
        Dim ipcon As New IPConnection() ' Create IP connection
        Dim iqr As 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()
    End Sub
End Module