嘿,我想要控制我的Onkyo接收器上的主音量。存在的問題是,它的工作,直到我達到第10卷。體積數字0-9正常工作(將音量從0提高到9)。但是,當我進入第10卷時,它顯示的音量爲。 第11卷= 17,卷12 = 18,等等等等十六進制數字串口
Excel表單這樣說:
"00"-"64" Volume Level 0 - 100 (In hexadecimal representation)
和串行命令是:
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)
請**使用調試器,因爲我問**。在'stream.Write'行設置一個斷點,當觸發斷點時,查看'sendBytes'的內容。看看正在發送給接收器的**實際內容**。 –
@KenWhite我會使用調試器,但它調用Web服務來做到這一點。雖然我做了一個短暫的VB,它將發送WS,它會根據需要發送。 – StealthRT