K8090/VM8090 How to query relay status?

Hi guys,

I’ve seen this question many times in the forum, I read almost all of the posts covering that question but never found any complete answer so here is the question again :
How, in VB.net, can I query the the board to get the relays status ?

The guides available to download don’t really give any answer. As far as I can see I’ll have to use something like K8090.SendCommand(Velleman.Kits.K8090Command.QueryRelayStatus)
But how can I read the result of this query ? I tried something stupid like TextBox1.Text = K8090.SendCommand(Velleman.Kits.K8090Command.QueryRelayStatus) but this gives me an error.

Please please please, I would like a answer with a piece of code showing how to do it and NOT answers like “download the guide”, “look at the samples codes provided” or “what is the rest of your code”.
This is what everyone expect from a professional support service, a clear answer.

Thank you.
Vince.

You will need to start from the Sample02 project that is installed along with the demo. Notice that this is a Windows Forms Application, because a Console Application will not work.

On line 14 you will find the K8090_CommandReceived function, which is called any time anything is received from the K8090. This is where you will want to intercept the RelayStatus command. Here is some code that does exactly that, with comments explaining each line.

    Private Sub K8090_CommandReceived(ByVal o As System.Object, _
        ByVal args As Velleman.Kits.CommandEventArgs) Handles K8090.CommandReceived

        ' We are looking for the RelayStatus command
        '
        If (args.cmd = Velleman.Kits.K8090Command.RelayStatus) Then

            ' According to the protocol, param1 contains
            ' the current relay status. Each bit in this
            ' value represents the state of a relay.
            '
            ' You will need to examine the bits in param1 to
            ' know which relays are on
            '
            ' Here, I will only check if relay 1 is ON:
            '
            If ((args.param1 And &H1) = &H1) Then
                ' Relay 1 is ON
            Else
                ' Relay 1 is OFF
            End If

        End If
    End Sub

If you want to explicitly ask the K8090 to send you the RelayStatus, then you can do it like this:

        ' We want to know the relay status, so we will ask the K8090 to send it:
        K8090.SendCommand(Velleman.Kits.K8090Command.QueryRelayStatus)

This function does not return anything since, remember, everything comes in via the K8090_CommandReceived function.