2013-02-01 22 views
0

嘿,我想要控制我的Onkyo接收器上的主音量。存在的問題是,它的工作,直到我達到第10卷。體積數字0-9正常工作(將音量從0提高到9)。但是,當我進入第10卷時,它顯示的音量爲。 第11卷= 17卷12 = 18,等等等等十六進制數字串口

Excel表單這樣說:

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

enter image description here

和串行命令是:

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 

這就是我所說的上述功能:

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) 

我尋找轉換器和我注意到,表示在十六進制。但即使發送,MVLA不會做任何事情。

我會錯過什麼?

UPDATE(和解決)

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

Call avReceiver.remoteCommands("MVL" & vol2) 

enter image description here

+0

請**使用調試器,因爲我問**。在'stream.Write'行設置一個斷點,當觸發斷點時,查看'sendBytes'的內容。看看正在發送給接收器的**實際內容**。 –

+0

@KenWhite我會使用調試器,但它調用Web服務來做到這一點。雖然我做了一個短暫的VB,它將發送WS,它會根據需要發送。 – StealthRT

回答

1

發送OA(零)。正文說它正在尋找十六進制00到十六進制64(十進制0到100)。請注意,十六進制值表示爲兩位數字,而不是一個。

如果你實際上是使用VB.NET作爲你的標籤指出的,那麼你做錯了。 :-)你應該使用類似於:

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

似乎還是說,當我發送** 10 **時,它仍然在接收器上顯示它的** 16 **? – StealthRT

+0

然後你編輯了錯誤的東西。 :-)我的代碼會發送'MVL0A',它是'MVL' +十進制('0A' hex)。如果您的接收器顯示「16」,您不會以某種方式發送「10」。放入一些'MessageBox'或其他方式來檢查你發送的數組(或使用調試器通過設置一個斷點來查看它)並查看數組中的實際字符。我已經回答了有關正確發送十六進制值的問題;我看不到你的代碼實際上發送了什麼,因爲我沒有你所有的代碼或接收器。如果顯示「16」,則必須實際發送「10」。 –

+0

0a確實顯示** 16 **,但它應該在接收器上顯示** 10 **和**不是16 **,因爲那就是我需要它顯示的** 10 ** ... – StealthRT

相關問題