Announcement

Collapse
No announcement yet.

Sony XBR6 requires Hex Data Commands via RS-232

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Sony XBR6 requires Hex Data Commands via RS-232

    I've been scouring the message board for clues on how to use HomeSeer's built-in scripting funtcion SendToComPort to send serial hex data strings to a sony XBR5 TV (such as 8C 00 00 02 00 8E = Power OFF), but I am only able to send the ascii equivalent. Not being a programmer is more than half my problem, I am sure. I have found many useful RS-232 Device Command scripts, but none I can use to control this particular TV.

    Surely, I am not the only one who needs to transmit raw hex data; maybe I am just the only one who does not understand how!

    I emailed the help desk, but was simply sent back to the forums. Thank you in advance for any helpful recommendations.


    Dan the Lan Man

    #2
    I quickly wrote something but have no idea if it actually works.

    Obviously you need to open the port you wish to use and set the port number in the script. It's written in VB.NET so your script name needs to end in .vb

    PHP Code:
    Sub Main(ByVal Parm As Object)
        
    Dim MyHexString As String
        MyHexString
    ="8C 00 00 02 00 8E"
        
    SendHex(MyHexString)
    end sub

    Sub SendHex
    (ByVal MyHexString As String)

    Dim HexS() As String
    Dim ComPort 
    As Integer 1
    Dim I 
    As Integer

    HexS 
    MyHexString.Split(" ")
    Dim data(HexS.length) As byte
    For 0 To HexS.length-1
        data
    (I)=CLng("&h" HexS(I))
        
    hs.sendtocomport (Comport,Chr(Data(I)))
    Next

    end sub 
    Jon

    Comment


      #3
      Sample VB Script

      Thank you Jon00, for your quick reply. Your code sample certainly fits into my conclusion that some character processing would be necessary. I will digest this and hopefully get time to test it today. More later....

      Dan the LAN Man

      Comment


        #4
        Jon00 - You are good at what you do. Your "untested" vb script for transmitting hex character strings works flawlessly! It is compact enough that I created a group of about 12 common commands for my Sony KDL-52XBR5, each in their own HS script file (since I do not yet know how to incorporate conditional tests for command line inputs). And eventually, I will figure out how to service the three byte response acknowledgment data, too.

        But for now... I am grateful for your quick work, as it has allowed me to move on with the higher level automation tasks at hand!

        Thank you! I'll look into your other posts and plug-ins, too!

        Dan the LAN Man

        Comment


          #5
          Thanks very much! You don't need to have lots of scripts if you use the optional parameters to tell the script what you want it to do i.e.

          PHP Code:
          Sub Main(ByVal Data As String
              
          Dim MyHexString As String 
              
          If Data "On" then
                   MyHexString
          ="8C 00 00 02 00 8E"
              
          elseif Data "Off" then
                   MyHexString
          ="XX XX XX XX XX XX"
              
          elseif Data ="Vol+" then
                   MyHexString
          ="XX XX XX XX XX XX"
              
          else
                  
          hs.writelog ("SonyXBR6","Sorry the command sent is not understood")
                  exit 
          sub
              end 
          if
              
          SendHex(MyHexString
          end sub 

          Sub SendHex
          (ByVal MyHexString As String

          Dim HexS() As String 
          Dim ComPort 
          As Integer 
          Dim I 
          As Integer 

          HexS 
          MyHexString.Split(" "
          Dim data(HexS.length) As byte 
          For 0 To HexS.length-
              data
          (I)=CLng("&h" HexS(I)) 
              
          hs.sendtocomport (Comport,Chr(Data(I))) 
          Next 

          end sub 
          Then you just call the script with optional parameters:

          ("Main","On")

          This will send the on command

          ("Main","Vol+")

          This will send the volume up command.

          You can add as many commands as you wish by just extending the elseif statements.

          Hope that helps.
          Jon

          Comment


            #6
            Broken script

            Jon00... I took too big a step and stumbled. The following intrepetation of your second example results in an error message "Running script Sony XBR5 Test.vb :method not found". I am concerned about the indentation levels (they appear different from the original in the sample below)

            Sub Main(ByVal Data As String)
            Dim MyHexString As String
            If Data = "POWER_ON" then
            MyHexString="8C 00 00 02 01 8F"
            elseif Data = "POWER_OFF" then
            MyHexString="8C 00 00 02 00 8E"
            elseif Data ="INPUT_TV" then
            MyHexString="8C 00 02 02 01 91"
            elseif Data ="INPOUT_CPNT1" then
            MyHexString="8C 00 02 03 03 01 95"
            elseif Data ="INPUT_HDMI1" then
            MyHexString="8C 00 02 03 04 01 96"
            elseif Data ="INPUT_HDMI2" then
            MyHexString="8C 00 02 03 04 02 97"
            elseif Data ="INPUT_HDMI3" then
            MyHexString="8C 00 02 03 04 03 98"
            elseif Data ="MUTE_ON" then
            MyHexString="8C 00 06 03 01 01 97"
            elseif Data ="MUTE_OFF" then
            MyHexString="8C 00 06 03 01 00 96"
            elseif Data ="SPKR_OFF" then
            MyHexString="8C 00 36 03 01 00 C6"
            elseif Data ="SPKR_ON" then
            MyHexString="8C 00 36 03 01 01 C7"
            elseif Data ="VOL_00" then
            MyHexString="8C 00 05 03 01 00 95"
            else
            hs.writelog ("SonyXBR6","Sorry the command sent is not understood")
            exit sub
            end if
            SendHex(MyHexString)
            end sub

            Sub SendHex(ByVal MyHexString As String)
            Dim HExS() As String
            Dim ComPort As Integer = 10
            Dim I As Integer
            HexS = MyHexString.Split(" ")
            Dim data(HexS.length) As byte
            For I = 0 To HexS.length-1
            data(I)=CLng("&h" & HexS(I))
            hs.sendtocomport (Comport,Chr(Data(I)))
            Next
            end sub

            Comment


              #7
              The call to the script is case sensitive.

              You probably used:

              "main","POWER_ON"

              You must use:

              "Main","POWER_ON"
              Jon

              Comment


                #8
                My Misuse of ALL CAPS

                Jon00 - RIGHT you are! I now see "Main" is not the same as "MAIN" (and let wondering why). I am so impressed with what you are able to do in vb in what seems to be "the wink of an eye" and with what you've been able to help me do in a day! Guess I will seek out a VB for Dummies and get started understanding these nuances. I am a hardware engineer and many years ago I had tons of fun with QuickBasic, but had assemby and C programmers around to keep me out of the ditch.
                I've already gotten so much from you, I am embarrased to ask: Is there a similarily "simple" vb way to fetch and act upon data received from the RS-232 port? Also, tell me... am I not looking hard enough in this forum for these answers? I did not find (understandable) hex outputting anywhere.
                Thank you so much!
                Dan the (humbled) LAN Man

                Comment


                  #9
                  I'm not sure where you are opening your Com port but if you want to read data, you have to tell Homeseer to call a script when data is being received.

                  To do this you open the com port similar to this:

                  e=hs.OpenComPortEx(10,"9600,n,8,1",0,"Test.vb","RData", vbCRLF)

                  This will run Test.vb and jump to the subroutine RData every time data is sent on port 10

                  If we now extend your script with a new subroutine called RData:

                  PHP Code:
                  Sub RData()
                  Dim ComPort As Integer 10
                  Dim MyData 
                  As String hs.GetComPortData(Comport)
                  hs.writelog("Comport data",MyData)
                  end sub 
                  You should then be able to see this data in the Homeseer log.
                  I'm also not sure what you intend to do with the data output and if you actually need it in hex or not.
                  Jon

                  Comment

                  Working...
                  X