StealthRT
StealthRT

Reputation: 10552

Hexadecimal from number over serial port

Hey all i am trying to control the master volume on my Onkyo Receiver. Problem being is that it works until i get to volume 10. Volume numbers 0-9 work just fine (raises volume from 0 to 9). However, when i go to volume 10 it displays the volume as being 16. Volume 11=17, Volume 12=18, etc etc.

The excel sheet says this:

"00"-"64"   Volume Level 0 - 100 ( In hexadecimal representation)

enter image description here

And the serial command is:

Public Function remoteCommands(ByVal theCommand As String) As Boolean
    Dim Stream As NetworkStream
    Dim Client As New TcpClient()
    Dim streamw As StreamWriter
    Dim i As Int32
    On Error GoTo blah

    Client.Connect(main.avIP, 60128)
    Stream = Client.GetStream()
    Dim returndata As String = ""

    If Client.Connected And Stream.CanWrite Then
        streamw = New StreamWriter(Stream)
        Dim sendBytes(theCommand.Length + 18) As Char

        sendBytes(0) = "I"
        sendBytes(1) = "S"
        sendBytes(2) = "C"
        sendBytes(3) = "P"
        sendBytes(4) = Chr(0)
        sendBytes(5) = Chr(0)
        sendBytes(6) = Chr(0)
        sendBytes(7) = Chr(16)
        sendBytes(8) = Chr(0)
        sendBytes(9) = Chr(0)
        sendBytes(10) = Chr(0)
        sendBytes(11) = Chr(theCommand.Length + 3)
        sendBytes(12) = Chr(1)
        sendBytes(13) = Chr(0)
        sendBytes(14) = Chr(0)
        sendBytes(15) = Chr(0)
        sendBytes(16) = "!"
        sendBytes(17) = "1"

        For i = 0 To (theCommand.Length - 1)
            sendBytes(18 + i) = theCommand.Chars(i)
        Next

        sendBytes(theCommand.Length + 18) = Chr(13) '&HD
        streamw.Write(sendBytes)

        Dim bytes(Client.ReceiveBufferSize) As Byte
        Stream.Read(bytes, 0, CInt(Client.ReceiveBufferSize))
        returndata = Encoding.ASCII.GetString(bytes)

        streamw.Flush()
    Else
        MsgBox("error: Stream.Canwrite failed")
    End If
    Client.Close()
End Function

And this is how i call the function above:

Dim vol As String = Trim(lanSent(1).Replace("AVVOL", ""))

If Len(vol) = 1 Then
   vol = "0" + vol
Else
   Select Case vol
      Case 10
        vol = "a"
      Case 11
        vol = "b"
   End Select
End If

Call avReceiver.remoteCommands("MVL" & vol)

I was looking for converters and i noticed that 10 represented A in Hexadecimal. But even sending that MVLA doesn't do anything.

What would i be missing?

UPDATE (and solved)

Dim vol As Integer = Trim(lanSent(1).Replace("AVVOL", ""))
Dim vol2 = vol.ToString("X2")

Call avReceiver.remoteCommands("MVL" & vol2)

enter image description here

Upvotes: 0

Views: 780

Answers (1)

Ken White
Ken White

Reputation: 125749

Send OA (zero A). The text says it's looking for hex 00 to hex 64 (decimal 0 to 100). Note that the hex values are expressed as two digits, not one.

If you're actually using VB.NET as your tag indicates, you're doing it wrong. :-) You should be using something like:

newvol = 10;
vol = newvol.ToString("X2")    `Converts to 2-digit hex string
Call avReceiver.remoteCommands("MVL" & vol)

Upvotes: 1

Related Questions