Author Topic: Ruby code in wiki tutorial for LG 42LB5D #355 Process Initialize breaks compile  (Read 2892 times)

sedgington

  • Veteran
  • ***
  • Posts: 82
    • View Profile
So that no one else has to suffer through figuring this out:

On this link http://wiki.linuxmce.org/index.php/LG_42LB5D
under "Add Ruby Snippets to Commands" you will find this code
----------------------------
#355 Process Initialize
   for iRetry in 0...4
          print "Initializing unit\n"
          conn_.Send("ke 01 01\r") # Send UnMute Command
          buf = conn_.Recv(30,200) # Expected Return # ke 01 01\r\ne 00 OK01x\r\n
          if !buf.nil? && buf.include?("OK")
            print "Initialized ok\n"
            print "Setting volume to 30%\n"
            cmd_313(15)
            SetDeviceDataInDB( device_.devid_, 158, "15" )
            # 158 = DEVICEDATA_Volume_Level_CONST
            return
          end
          print "Failed to initialize. Wait 1 secs and try again\n"
          sleep(1)
        end
#DisableDevice( device_.devid_, true )
#print "The device would not respond. Disabling it.\n"    
----------------------------
Unfortunately it will cause a compile error in 7.10 in the "follow log" on the "advanced" link of the A/V device and will not allow your template to run. The compile error will state that it found a "kend" and was expecting "$end".
If you delete this code snippet from the template--leaving #355 blank---and restart the router, it will compile with no problem and the "send command to device" Link on the "advanced link of the GSD device seems to work through rs232 .

Since this page has been copied as a tutorial for other LG TVs and a request was put in a couple of weeks ago to have the code included as a pnp device for 8.10
http://forum.linuxmce.org/index.php?topic=9729
many would assume that it has been tested and works. This is not true.
It is probably very easy to fix--looks to me like the definitions at the top of this snippet were not copied into the tutorial, but I know nothing about Ruby or I would attempt it.
BTW, otherwise this seems to be a good template for LG TVs with serial ports. Some of the command need to be changed for later models <$xb 01 90\r$> instead of <$kb 01 07\r$> for inputing HDMI 1 for example, but generally a good guide for adapting it to your TV.

If the author of the tutorial or someone who has access to this page on the wiki could fix the code it would be greatly appreciated.

sedgington

  • Veteran
  • ***
  • Posts: 82
    • View Profile
Re: Ruby code in wiki tutorial for LG 42LB5D #355 (Solved)
« Reply #1 on: March 23, 2010, 08:46:21 pm »
I took some time to delve into how Ruby works and found where the (my) error was in the script. You need to look up the device id number of your LG TV from the Wizard \ Devices \ AV Equipment in the upper left hand corner and replace the number "158" in all the scripts with this number (for example, in my case 310). This allows the script to process successfully.

jimbodude

  • Guru
  • ****
  • Posts: 372
    • View Profile
Please update the wiki documentation with your findings if you have not done so already.