Jump to content

Help please with TCP/IP script to control Onkyo receiver


Recommended Posts

Hi,

I'm a newbie to this scripting, although I've done programing in the past many years ago (RPG/400). I'd like to create a script that controls an Onkyo TX-NR807 receiver that's connected to my LAN, so first off I'd like to turn it on and off. According to the manual, this is done by sending a command to it on port 60128. I've looked at the examples and the TCPSend script look a good place to start so I've modified it with my receiver's IP address of 192.168.1.6 and port 60128. The manual gives the power on command being !1PWR01[CR], however when I enter !1PWR01 into the box that appears, the receiver isn't switched on. I'm not sure if it has something to do with the [CR], but I'm not able to enter that via the keyboard.

I'd be grateful if someone could please give me a pointer on how I can get this to work.

Many thanks,

Dave.

Link to comment
Share on other sites

That may be a carraige return, try @CR.

I tried !1PWR01@CR without success

Why cant you enter [CR] via the keyboard? Im sure we both just did.

True, but is it getting to the Onkyo as part of the command structure? I'm not sure.
Link to comment
Share on other sites

Looks like this takes it's own special stuff on top of a regular TCP packet.

Yes, you're right. I need to send the data starting with ISCP followed by hex 00 00 00 10 plus some more hex and lastly the actual function code. What I've found using a packet sniffer is that the ISCP data is accepted ok, but the hex 00 00 00 10 is treated as ASCII and translated into hex.

How do I send plain hex?

Thanks.

Edited by wyerd
Link to comment
Share on other sites

Hex is a method to display data (like in the SciTE console pane), not encode it for transmission. The TCPSend() is given either string or binary data. What is called for and what did you pass? Since you haven't shared any code or a complete description of your method, we can't help much.

:blink:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hi PsaltyDS,

I've just modded the example code;

Opt('MustDeclareVars', 1)

;==============================================
;==============================================
;CLIENT! Start Me after starting the SERVER!!!!!!!!!!!!!!!
;==============================================
;==============================================

Example()

Func Example()
    ; Set Some reusable info
    ;--------------------------
    Local $ConnectedSocket, $szData
    ; Set $szIPADDRESS to wherever the SERVER is. We will change a PC name into an IP Address
;   Local $szServerPC = @ComputerName
;   Local $szIPADDRESS = TCPNameToIP($szServerPC)
    Local $szIPADDRESS = "192.168.1.6"
    Local $nPORT = 60128

    ; Start The TCP Services
    ;==============================================
    TCPStartup()

    ; Initialize a variable to represent a connection
    ;==============================================
    $ConnectedSocket = -1

    ;Attempt to connect to SERVER at its IP and PORT 33891
    ;=======================================================
    $ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT)

    ; If there is an error... show it
    If @error Then
        MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error)
        ; If there is no error loop an inputbox for data
        ;   to send to the SERVER.
    Else
        ;Loop forever asking for data to send to the SERVER
        While 1
            ; InputBox for data to transmit
            $szData = InputBox("Data for Server", @LF & @LF & "Enter data to transmit to the SERVER:")

            ; If they cancel the InputBox or leave it blank we exit our forever loop
            If @error Or $szData = "" Then ExitLoop

            ; We should have data in $szData... lets attempt to send it through our connected socket.
            TCPSend($ConnectedSocket, $szData)
            ; If the send failed with @error then the socket has disconnected
            ;----------------------------------------------------------------
            If @error Then ExitLoop
        WEnd
    EndIf

I'm sending ISCP000000100000000701000000!1PWR010D

This is cut from the manual. Sorry for the formatting, but it was originally in Excel format.

1.2. ISCP over Ethernet (eISCP)

*eISCP Packet Format

+0 +1 +2 +3

eISCP Header I S C P

Header Size

Data Size

Version Reserved

eISCP Data 1stChar 2ndChar 3rdChar 4thChar

5thChar ISCP Message

EndChar

eISCP Data(=ISCP Message)

1st 2nd 3rd-5th 6th- last

! 1 P W R 0 1 [EOF] [CR] [LF]

End Character

"""[EOF]"" or ""[EOF][CR]"" or ""[EOF][CR][LF]"" depend on model"

ISCP Message(Command+Parameter)

"Destination Unit type Character (""1"" for Receiver)"

Start Character

"Header Size is the size of eISCP Header. In order to extend header size in the future, it is necessary to take it into calculation. Now, it is 0x00000010. (**BIGENDIAN**)"

Data Size is the size of the eISCP Data. (**BIGENDIAN**)

"Version is ISCP version. Now, it is 0x01."

"Reserved is used extending it in the future. Now, it is 0x000000."

"Unit Type is the model category ID. The Receiver is ""1""."

Link to comment
Share on other sites

You might get some help from this post: AVForums: Onkyo (TX-NR 1007) Webinterface Programming

The message formatting in VB.net looks like this:

Dim sendBytes(command.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(command.Length + 3)
            sendBytes(12) = Chr(1)
            sendBytes(13) = Chr(0)
            sendBytes(14) = Chr(0)
            sendBytes(15) = Chr(0)
            sendBytes(16) = "!"  'Chr(33) 
            sendBytes(17) = "1"   'Chr(49)  ' 1 is for the Receiver
            Dim i As Int32
            For i = 0 To (command.Length - 1)
                sendBytes(18 + i) = command.Chars(i)
            Next
            sendBytes(command.Length + 18) = Chr(13)

Note there are null characters in the stream. So you want to convert it all to a binary before transmission (null terminates a string in AutoIt).

:blink:

My interpretation in AutoIt:

;  ISCP 00000010 00000007 01000000 !1PWR01 0D

Global $binISCP_Header = StringToBinary("ISCP")
Global $binISCP_HeaderSize = Binary("0x00000010") ; Header size = 16
Global $binISCP_DataSize =  Binary("0x00000007") ; Data size (command length) = 7 chars
Global $binISCP_Version = Binary("0x01000000") ; Version 1.0.0.0
Global $binISCP_Data = StringToBinary("!1PWR01") ; Command = !1PWR01
Global $binISCP_End = Binary("0x0D") ; @CR

Global $binISCP_Message = $binISCP_Header & _
        $binISCP_HeaderSize & _
        $binISCP_DataSize & _
        $binISCP_Version & _
        $binISCP_Data & _
        $binISCP_End


; ...


TCPSend($ConnectedSocket, $binISCP_Message) ; Send message over connected socket

Not tested, of course.

Changing the end of my code to this:

; TCPSend($ConnectedSocket, $binISCP_Message) ; Send message over connected socket
ConsoleWrite("$binISCP_Message = " & $binISCP_Message & @LF)

I get this out:

$binISCP_Message = 0x49534350000000100000000701000000213150575230310D

;)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

My interpretation in AutoIt:

;  ISCP 00000010 00000007 01000000 !1PWR01 0D

Global $binISCP_Header = StringToBinary("ISCP")
Global $binISCP_HeaderSize = Binary("0x00000010") ; Header size = 16
Global $binISCP_DataSize =  Binary("0x00000007") ; Data size (command length) = 7 chars
Global $binISCP_Version = Binary("0x01000000") ; Version 1.0.0.0
Global $binISCP_Data = StringToBinary("!1PWR01") ; Command = !1PWR01
Global $binISCP_End = Binary("0x0D") ; @CR

Global $binISCP_Message = $binISCP_Header & _
        $binISCP_HeaderSize & _
        $binISCP_DataSize & _
        $binISCP_Version & _
        $binISCP_Data & _
        $binISCP_End


; ...


TCPSend($ConnectedSocket, $binISCP_Message) ; Send message over connected socket

Not tested, of course.

FANTASTIC - it works!

Great stuff, I just now need to understand how your code works so I can write a script that can do more of the Onkyo functions.

Many thanks.

Link to comment
Share on other sites

Cool! :blink:

I have an Onkyo home theater receiver, but I don't think it's an Ethernet enabled one. Interesting option.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • 6 months later...

Is this ISCP part of the string required when hooked up directly via RS 232 too?

I am hooked up from Linux via PL2303 UBS <-> RS232 to an Onkyo 875

#!/bin/sh

stty 9600 cs8 ixoff -parenb crtscts -echo -F /dev/ttyUSB0

exec 3<>/dev/ttyUSB0

echo "!1PWRQSTN00" >&3
read response <&3
echo $response
But there is no response... Edited by gameboynumberone
Link to comment
Share on other sites

  • 1 month later...

Is this ISCP part of the string required when hooked up directly via RS 232 too?

I am hooked up from Linux via PL2303 UBS <-> RS232 to an Onkyo 875

#!/bin/sh

stty 9600 cs8 ixoff -parenb crtscts -echo -F /dev/ttyUSB0

exec 3<>/dev/ttyUSB0

echo "!1PWRQSTN00" >&3
read response <&3
echo $response
But there is no response...

You forgot the Cr at the end of the command Hex value: 0x0D or \r in a string so it should be:

echo "!1PWRQSTN00\r" >&3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...