Author Topic: Easy question  (Read 10525 times)

brent2009

  • Regular Poster
  • **
  • Posts: 40
    • View Profile
Easy question
« on: November 02, 2012, 01:11:43 am »
OK this should be an easy one but I've tried several different combinations and am not able to get it to work.

Using TestSerialPort works successfully for turning on my tv with the below command.
sudo ./TestSerialPort -p /dev/ttyS0 -t "ka 01 01\r"

...response back
a 01 OK01x

The linuxmce web interface test is a different story. I click A/V properties for my TV and click the Test code button for turning on my TV and nothing ever happens no matter what I seem to put here.

The default is below which doesn't work. Can anyone please tell me exactly what to put for turning on my TV based on the succssful test above? Once I get one command right I should be able to figure the rest out. (I've also tried <$"ka 01 01\r"$> which doesn't work)
SendCommand("ka","00",1)

Thanks alot!

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: Easy question
« Reply #1 on: November 02, 2012, 02:15:59 am »
Is the Com Port on PC properly specified, and is it set to /dev/ttyS0?

If so, follow the log of the Generic Serial Device for this device # when it starts up, look for any error messages.

-Thom

brent2009

  • Regular Poster
  • **
  • Posts: 40
    • View Profile
Re: Easy question
« Reply #2 on: November 02, 2012, 04:24:42 am »
Is the Com Port on PC properly specified, and is it set to /dev/ttyS0?

If so, follow the log of the Generic Serial Device for this device # when it starts up, look for any error messages.

-Thom

Yep and yep. I'm not sure where to look for this. Is it in one of the /var/log/pluto? If so I don't see anything that resembles what I'm supposed to be looking for.  Are you sure I'm not typing the string wrong in the web interface? Maybe it needs a different format from what I was using when I was using the Testserialport script. As long as that works I would think I'm just not using the correct format in the web interface.

Thanks.

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: Easy question
« Reply #3 on: November 02, 2012, 04:31:49 am »
If you click on the device in the web admin (advanced > configuration > devices), there is a link to follow the log.

-Thom

brent2009

  • Regular Poster
  • **
  • Posts: 40
    • View Profile
Re: Easy question
« Reply #4 on: November 02, 2012, 05:40:39 pm »
If you click on the device in the web admin (advanced > configuration > devices), there is a link to follow the log.

-Thom

Ok, I clicked follow log but it isn't generating anything new... The dates are from yesterday which I don't understand. Does it not log anything when you click Test code?

Here is some info if it helps:
 320:        SendCommand("ka","00",1)

 321:      end

 322:      log "returning true"

 323:      return true

 324:    else

 325:      # could not get volume, use a sane default and let the init function know that we could not turn the tv on

 326:      @volume = 10

 327:      return false

 328:    end

 329:     

 330:  else

 331:    return true

 332:  end

 333:end
 334:#### 548 ####################################################################
 335:def cmd_548(text, streamid, cmd=nil)
 336:@returnParamArray.clear
 337:SendKey("43")
 338:return @returnParamArray
 339:end
 340:#### 712 ####################################################################
 341:def cmd_712(cmd=nil)
 342:@returnParamArray.clear
 343:Command("xb","40")
 344:return @returnParamArray
 345:end
 346:#### 713 ####################################################################
 347:def cmd_713(cmd=nil)
 348:@returnParamArray.clear
 349:Command("xb"," 41")
 350:return @returnParamArray
 351:end
 352:#### 763 ####################################################################
 353:def cmd_763(cmd=nil)
 354:@returnParamArray.clear
 355:SendKey("5B")
 356:return @returnParamArray
 357:end
 358:#### 767 ####################################################################
 359:def cmd_767(cmd=nil)
 360:@returnParamArray.clear
 361:Command("xb","91")
 362:return @returnParamArray
 363:end
 364:#### 873 ####################################################################
 365:def cmd_873(cmd=nil)
 366:@returnParamArray.clear
 367:EmbeddedTuner("00")
 368:return @returnParamArray
 369:end
 370:#### 930 ####################################################################
 371:def cmd_930(cmd=nil)
 372:@returnParamArray.clear
 373:Command("xb","92")
 374:return @returnParamArray
 375:end
 376:#### 937 ####################################################################
 377:def cmd_937(cmd=nil)
 378:@returnParamArray.clear
 379:SendKey("AA")
 380:return @returnParamArray
 381:end
 382:#### 964 ####################################################################
 383:def cmd_964(cmd=nil)
 384:@returnParamArray.clear
 385:SendKey("00")
 386:return @returnParamArray
 387:end
 388:#### 965 ####################################################################
 389:def cmd_965(cmd=nil)
 390:@returnParamArray.clear
 391:SendKey("01")
 392:return @returnParamArray
 393:end
 394:#### 984 ####################################################################
 395:def cmd_984(cmd=nil)
 396:@returnParamArray.clear
 397:Command("xb","90")
 398:return @returnParamArray
 399:end
 400:#### 985 ####################################################################
 401:def cmd_985(cmd=nil)
 402:@returnParamArray.clear
 403:Command("xb","93")
 404:return @returnParamArray
 405:end
 406:#### 1086 ####################################################################
 407:def cmd_1086(cmd=nil)
 408:@returnParamArray.clear
 409:Command("xb","42")
 410:return @returnParamArray
 411:end
 412:#### START SETTERS ####################################################################
 413:def initialize()
 414:super
 415:@returnParamArray=Array.new
 416:end
 417:####  END  SETTERS ####################################################################
 418:end
420:01   11/01/12 17:43:46.468      Error while calling method: Cannot call class method: cmd_355
error: undefined local variable or method `conn_' for #, line: 257
backtrace:
   in: (eval): 257
   from (eval):257:in `SendCommand'
   from (eval):309:in `InitVolume'
   from (eval):215:in `cmd_355'
 <0xb4722b70>
05   11/01/12 17:54:02.692      Got a reload command from 0  <0xb5123b70>
05   11/01/12 17:54:02.969      void ClientSocket::Disconnect() on this socket: 0x8ce35f0 (m_Socket: 8) <0xb6f276d0>
Return code: 2
2   11/01/12 17:54:03   37 (spawning-device)   Device requests restart... count=1/50 dev=37
2   11/01/12 17:54:03   37 (spawning-device)   Device was disabled or removed. Stopping and marking as not running.

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5549
  • DOES work for LinuxMCE.
    • View Profile
Re: Easy question
« Reply #5 on: November 02, 2012, 07:26:58 pm »
the top most part of the log is missing. This is the most important. An important indicator is that conn_ isn't defined. The only way this can happen is if GSD can't find the serial port or TCP port in question.

-Thom

brent2009

  • Regular Poster
  • **
  • Posts: 40
    • View Profile
Re: Easy question
« Reply #6 on: November 03, 2012, 02:25:23 am »
Well I sort of made progress. My logs weren't refreshing and it was because the device somehow got disabled. Now I got the log updated and it isn't showing that above error anymore... Here is the updated log. Any other ideas?

========== NEW LOG SECTION ==========
1       11/02/12 20:12:31       37 (spawning-device)    ^[[1;00mStarting... 1^[[1;00m
1       11/02/12 20:12:31       37 (spawning-device)    ^[[1;00mFound /usr/pluto/bin/Generic_Serial_Device^[[1;00m
05      11/02/12 20:12:31.964           ^[[33;1mCreating child 38^[[0m <0xb6fab6d0>
05      11/02/12 20:12:31.964           ^[[33;1mNote: Device manager has attached a device of type 2125 that this has no custom event handler for.  It will not fire events.^[[0m <0xb6fab6d0>
05      11/02/12 20:12:31.964           ^[[33;1mNote: Device manager has attached a device of type 2125 that this has no custom handler for.  This is normal for IR.^[[0m <0xb6fab6d0>
05      11/02/12 20:12:31.964           ^[[33;1mCreating child 39^[[0m <0xb6fab6d0>
05      11/02/12 20:12:31.964           ^[[33;1mNote: Device manager has attached a device of type 2166 that this has no custom event handler for.  It will not fire events.^[[0m <0xb6fab6d0>
05      11/02/12 20:12:31.964           ^[[33;1mNote: Device manager has attached a device of type 2166 that this has no custom handler for.  This is normal for IR.^[[0m <0xb6fab6d0>
RCODE:
   0:require 'Ruby_Generic_Serial_Device'
   1:class Command < Ruby_Generic_Serial_Device::RubyCommandWrapper
   2:end
   3:class Device_37 < Ruby_Generic_Serial_Device::RubySerialIOWrapper
   4:#### 89 ####################################################################
   5:def cmd_89(repeat_command, cmd=nil)
   6:@returnParamArray.clear
   7:print "raising volume from ", @volume, "\n"^M
   8:cmd_313(@volume+1)
   9:return @returnParamArray
  10:end
  11:#### 90 ####################################################################
  12:def cmd_90(repeat_command, cmd=nil)
  13:@returnParamArray.clear
  14:print "lowering volume from ", @volume, "\n"^M
  15:cmd_313(@volume-1)^M
  16:
  17:return @returnParamArray
  18:end
  19:#### 97 ####################################################################
  20:def cmd_97(cmd=nil)
  21:@returnParamArray.clear
  22:if(@mute)^M
  23:  SendCommand("ke 01 00",10000,4)^M
  24:else^M
  25:  SendCommand("ke 01 01",10000,4)^M
  26:end^M
  27:@mute=!@mute
  28:return @returnParamArray
  29:end
  30:#### 154 ####################################################################
  31:def cmd_154(cmd=nil)
  32:@returnParamArray.clear
  33:SendCommand("kb 01 60",1000,4)
  34:return @returnParamArray
  35:end
  36:#### 166 ####################################################################
  37:def cmd_166(cmd=nil)
  38:@returnParamArray.clear
  39:SendCommand("kb 01 01",1000,4)
  40:return @returnParamArray
  41:end
  42:#### 192 ####################################################################
  43:def cmd_192(pk_pipe, pk_device_pipes, cmd=nil)
  44:@returnParamArray.clear
  45:SendCommand("ka 01 01",10000,4)
  46:return @returnParamArray
  47:end
  48:#### 193 ####################################################################
  49:def cmd_193(pk_pipe, cmd=nil)
  50:@returnParamArray.clear
  51:SendCommand("ka 01 00",1000,2)
  52:return @returnParamArray
  53:end
  54:#### 313 ####################################################################
  55:def cmd_313(level, cmd=nil)
  56:@returnParamArray.clear
  57:@volume=level.to_i()^M
  58:ilevel = (@volume * 0.64).to_i^M
  59:print "setting volume to ", ilevel , "\n"^M
  60:^M
  61:if ilevel <10^M
  62:  SendCommand("kf 01 0" + ilevel.to_s,1000,4) ^M
  63:else^M
  64:  SendCommand("kf 01 " + ilevel.to_s,1000,4) ^M
  65:end^M
  66:SetDeviceDataInDB( device_.devid_, 158, ilevel .to_s) # 158 = DEVICEDATA_Volume_Level_CONST^M
  67:print "volume and corresponding device data set\n"^M
  68:
  69:return @returnParamArray
  70:end
  71:#### 316 ####################################################################
  72:def cmd_316(cmd=nil)
  73:@returnParamArray.clear
  74:SendCommand("kb 01 02",1000,4)
  75:return @returnParamArray
  76:end
  77:#### 317 ####################################################################
  78:def cmd_317(cmd=nil)
  79:@returnParamArray.clear
  80:SendCommand("kb 01 21",1000,4)
  81:return @returnParamArray
  82:end
  83:#### 355 ####################################################################
  84:def cmd_355(cmd=nil)
  85:@returnParamArray.clear
  86:# Initialize --- Date: 28.02.2008^M
  87:# the docs are wrong.  they say responses are terminated with a \r.  In reality some sets do, others don't.^M
  88:# some sets won't respond to ka 01 ff when the tv is off.  others do.^M
  89:@mute = false;^M
  90:^M
  91:# unfortunately we have to turn the device on if it's off to know that it's alive or else it won't respond to anything^M
  92:@input=-1^M
  93:for iRetry in 0...4^M
  94:    print "Initializing unit\n"^M
  95:    conn_.Send("ka 01 ff\r") ^M
  96:    # wait 2 seconds for the status command, which won't work if the tv is off^M
  97:    buf = conn_.RecvDelimited("x", 2000)^M
  98:    if( !buf.nil? && !buf.index("01 OK").nil? )^M
  99:        print "Initialized ok - tv is on\n"^M
 100:           volume_level = GetCurrentDeviceData( device_.devid_, 207 ) # 59 = DEVICEDATA_Initial_Volume_CONST^M
 101:           if( !volume_level.empty? && volume_level!="ERR Parameter not found" )^M
 102:                   print "Setting volume to ", volume_level, "\n"^M
 103:                   cmd_313(volume_level)^M
 104:                   SetDeviceDataInDB( device_.devid_, 158, volume_level ) # 158 = DEVICEDATA_Volume_Level_CONST^M
 105:           end^M
 106:        return^M
 107:    end^M
 108:    print "TV is either off or not connected\n"^M
 109:   ^M
 110:   # try turning it on^M
 111:    conn_.Send("ka 01 01\r") ^M
 112:^M
 113:    # wait 10 seconds for the TV to respond^M
 114:    buf = conn_.RecvDelimited("x", 10000)^M
 115:    if( !buf.nil? && !buf.index("01 OK").nil? )^M
 116:        print "Initialized ok - tv was off\n"^M
 117:        # wait 1 second and turn it off again so it returns to it's prior state^M
 118:        sleep(1)^M
 119:           volume_level = GetCurrentDeviceData( device_.devid_, 207 ) # 59 = DEVICEDATA_Initial_Volume_CONST^M
 120:           if( !volume_level.empty? && volume_level!="ERR Parameter not found" )^M
 121:                   print "Setting volume to ", volume_level, "\n"^M
 122:                   cmd_313(volume_level)^M
 123:                   SetDeviceDataInDB( device_.devid_, 158, volume_level ) # 158 = DEVICEDATA_Volume_Level_CONST^M
 124:           end^M
 125:       conn_.Send("ka 01 00\r") ^M
 126:        return^M
 127:    end^M
 128:^M
 129:    print "TV is not connected\n"^M
 130:^M
 131:    sleep(1)^M
 132:end^M
 133:^M
 134:#DisableDevice( device_.devid_, true )^M
 135:print "The device wouldn't respond. Disabling it.\n"^M
 136:
 137:return @returnParamArray
 138:end
 139:#### 361 ####################################################################
 140:def cmd_361(cmd=nil)
 141:@returnParamArray.clear
 142:SendCommand("kb 01 90",1000,4)
 143:return @returnParamArray
 144:end
 145:#### PRIVATE METHODS ####################################################################
 146:# Private - Date: 28.02.2008^M
 147:# the docs are wrong.  they say responses are terminated with a \r.  In reality some sets do, others don't.^M
 148:^M
 149:def SendCommand(command,timeout,retransmit)^M
 150:   for i in 0...retransmit^M
 151:           conn_.Send(command + "\r")^M
 152:           # wait up to 8 seconds since it may be very slow if this is an 'on' command^M
 153:           ^M
 154:       buf = conn_.RecvDelimited("x", timeout)^M
 155:       ^M
 156:       if( !buf.nil? && (!buf.index("01 OK").nil? || !buf.index("01 NG").nil?))^M
 157:                   print "Received good reply in less than ", timeout, "ms: ", buf, "\n"^M
 158:                   return^M
 159:           else^M
 160:                   buf = conn_.Recv(1000,1000);^M
 161:                   print "Flushed buffer: ", buf, "invalid resonse in ", timeout, "seconds\n"^M
 162:           end^M
 163:   end^M
 164:end
 165:#### 712 ####################################################################
 166:def cmd_712(cmd=nil)
 167:@returnParamArray.clear
 168:SendCommand("kb 01 05",1000,4)
 169:return @returnParamArray
 170:end
 171:#### 767 ####################################################################
 172:def cmd_767(cmd=nil)
 173:@returnParamArray.clear
 174:SendCommand("kb 01 91",1000,4)
 175:return @returnParamArray
 176:end
 177:#### 873 ####################################################################
178:def cmd_873(cmd=nil)
 179:@returnParamArray.clear
 180:SendCommand("kb 01 00",1000,4)
 181:return @returnParamArray
 182:end
 183:#### 930 ####################################################################
 184:def cmd_930(cmd=nil)
 185:@returnParamArray.clear
 186:SendCommand("kb 01 92",1000,4)
 187:return @returnParamArray
 188:end
 189:#### START SETTERS ####################################################################
 190:def initialize()
 191:super
 192:@returnParamArray=Array.new
 193:end
 194:####  END  SETTERS ####################################################################
 195:end
197:

brent2009

  • Regular Poster
  • **
  • Posts: 40
    • View Profile
Re: Easy question
« Reply #7 on: November 03, 2012, 02:41:15 am »
also When I try this:

log('Sending Menu Command')
<$"ka 01 00r"$>


and then click test code it doesn't add that to the follow log. :(


iberium

  • Veteran
  • ***
  • Posts: 84
    • View Profile
    • Innovative Sight & Sound
Re: Easy question
« Reply #8 on: November 04, 2012, 02:42:49 pm »
The device will become disabled if it can't start.  It sounds like you are missing some parameters on the device page.  Make sure you have all of the com settings correct.

brent2009

  • Regular Poster
  • **
  • Posts: 40
    • View Profile
Re: Easy question
« Reply #9 on: November 04, 2012, 05:17:47 pm »
The device will become disabled if it can't start.  It sounds like you are missing some parameters on the device page.  Make sure you have all of the com settings correct.

Ok, I am past the device becoming disabled part now. I am 100% sure linuxmce com port settings are correct and that communication appears to be working. I have been using a com port directly connected to my PC. I have spent countless hours now trying to get this to work.  I decided to buy what I am eventually going to need anyway... a serial to network hub... I have some more info and I am now even more confident that I have configuring the com settings correctly because I can see when data is sent to the hub and that linuxmce is connected to it successfully via a web interface:

Port 1 status: open
from ip address: 192.168.80.1
Baud settings: 9600 8/N/1 (these settings are not set by the serial hub either.. .they are received from linuxmce)


Now that I know communciation is wokring... AND i actually knew this in the first place anyway when I used TestSerialPort (sudo ./TestSerialPort -p /dev/ttyS0 -t "ka 01 01\r") how in the heck can I get the web interface to work and send "ka 01 01\r" (since I know this is the string that works with TestserialPort)

I am still very confused on why "test command" is not logging anything to the follow log and still very confused on what to use for the code. I really believe the code I am using is not correct for my tv since testserialport works. Am i supposed to be using sendcommand or command? What do i need to enter in the code in order for linuxmce web test command to send strictly this string for the tv on command "ka 01 01\r".  I believe this is really what I need answered. thank you.

SendCommand("ka","00",1) ???
Command("ka","00",1) ??
<$"ka 01 01\r"$> ??
« Last Edit: November 04, 2012, 05:19:37 pm by brent2009 »

brent2009

  • Regular Poster
  • **
  • Posts: 40
    • View Profile
Re: Easy question
« Reply #10 on: November 05, 2012, 12:45:39 am »
I am now getting this stuff at the end of the log upon restart.

05   11/04/12 17:40:44.573      #### Pre-Process Queue = 1 <0xb5206b70>
05   11/04/12 17:40:44.582      _QueueProc Pre - 192 : 0 <0xb7009b70>
05   11/04/12 17:40:44.582      GSD-Sleep Pre 192 : 0 <0xb7009b70>
05   11/04/12 17:40:44.582      Process Queue = 1 <0xb7009b70>
05   11/04/12 17:40:44.582      Parameter:  <0xb4805b70>
05   11/04/12 17:40:44.582      Parameter:  <0xb4805b70>
05   11/04/12 17:40:44.610      GSDMessageTranslator isCmdImplemented = false <0xb5206b70>
05   11/04/12 17:40:44.648      GSDMessageTranslator isCmdImplemented = false <0xb5206b70>
05   11/04/12 17:40:44.648      #### Pre-Process Queue = 1 <0xb5206b70>
05   11/04/12 17:41:06.007      _QueueProc Post - 192 : 4000 <0xb7009b70>
05   11/04/12 17:41:06.007      _QueueProc Pre - 984 : 0 <0xb7009b70>
05   11/04/12 17:41:06.007      GSD-Sleep Pre 984 : 0 <0xb7009b70>
05   11/04/12 17:41:06.007      Process Queue = 1 <0xb7009b70>
05   11/04/12 17:41:26.004      _QueueProc Post - 984 : 2000 <0xb7009b70>


I haven't changed anything besides trying different templates but still unable to get the test codes buttons to do anything or effect my tv at all. What is the deal?

Thanks.
« Last Edit: November 05, 2012, 02:28:55 am by brent2009 »

brent2009

  • Regular Poster
  • **
  • Posts: 40
    • View Profile
Re: Easy question
« Reply #11 on: November 05, 2012, 03:13:58 am »
In summary from above:


Works 100%
-LinuxMCE 100% successfully opens and establishes RS232 connection to my LG TV.
-sudo ./TestSerialPort -p /dev/ttyS0 -t "ka 01 01\r"

Does not work at all-
-Doesn't appear to send any commands using "test command" in A/V properties, nothing appears in the "follow log", even with ruby snippets including the log command

brent2009

  • Regular Poster
  • **
  • Posts: 40
    • View Profile
Re: Easy question
« Reply #12 on: November 05, 2012, 03:50:09 am »
Here is some more info. I tried changing one of my lines and I am getting these messages. any ideas what these mean?

Failed loading code: Error loading code:
error: (eval):196: compile error
(eval):45: syntax error, unexpected tIDENTIFIER, expecting kEND
log('Sending ON Command')conn_.Send("ka 01 01\r")
                              ^
(eval):52: syntax error, unexpected tIDENTIFIER, expecting kEND
log('Sending OFF Command')conn_.Send("ka 01 00\r")
                               ^, line: 196

iberium

  • Veteran
  • ***
  • Posts: 84
    • View Profile
    • Innovative Sight & Sound
Re: Easy question
« Reply #13 on: November 05, 2012, 01:06:57 pm »
I don't think it will log it until the device is started.  This will only happen once you have restarted the router.  While you are test sending commands, it is not responding to states or other events from the router.  I use the <$""$> format in my drivers.  The only time I have used sendcommand is when I am making ir drivers using a gsd so that I can create ir macros. 

brent2009

  • Regular Poster
  • **
  • Posts: 40
    • View Profile
Re: Easy question
« Reply #14 on: November 06, 2012, 01:16:55 am »
That is basically what I have been trying:

log('Sending Menu Command')
<$"ka 01 01\r"$>

And the device is definitely started as shown by the log without any errors. Below means that the driver is working correctly right? Are there any other logs I can view to help with troubleshooting this?

Thanks.

/var/log/pluto/39_Generic_Serial_Device.log

05   11/05/12 8:00:37.053      Going to rotate logs... <0xb57b4b90>
05   11/05/12 18:14:51.780      Got a reload command from 0  <0xb57b4b90>
05   11/05/12 18:14:57.276      void ClientSocket::Disconnect() on this socket: 0x933b630 (m_Socket: 8) <0xb6fb88d0>
Return code: 2
2   11/05/12 18:14:57   39 (spawning-device)   Device requests restart... count=1/50 dev=39
Mon Nov  5 18:14:57 CST 2012 Restart
========== NEW LOG SECTION ==========
1   11/05/12 18:15:05   39 (spawning-device)   Starting... 1
1   11/05/12 18:15:05   39 (spawning-device)   Found /usr/pluto/bin/Generic_Serial_Device
05   11/05/12 18:15:05.439      Creating child 40 <0xb71458d0>
05   11/05/12 18:15:05.439      Note: Device manager has attached a device of type 2125 that this has no custom event handler for.  It will not fire events. <0xb71458d0>
05   11/05/12 18:15:05.439      Note: Device manager has attached a device of type 2125 that this has no custom handler for.  This is normal for IR. <0xb71458d0>
05   11/05/12 18:15:05.439      Creating child 41 <0xb71458d0>
05   11/05/12 18:15:05.439      Note: Device manager has attached a device of type 2166 that this has no custom event handler for.  It will not fire events. <0xb71458d0>
05   11/05/12 18:15:05.439      Note: Device manager has attached a device of type 2166 that this has no custom handler for.  This is normal for IR. <0xb71458d0>
RCODE:
   0:require 'Ruby_Generic_Serial_Device'
   1:class Command < Ruby_Generic_Serial_Device::RubyCommandWrapper
   2:end
   3:class Device_39 < Ruby_Generic_Serial_Device::RubySerialIOWrapper
   4:#### 89 ####################################################################
   5:def cmd_89(repeat_command, cmd=nil)
   6:@returnParamArray.clear
   7:print "raising volume from ", @volume, "\n"
   8:cmd_313(@volume+1)
   9:return @returnParamArray
  10:end
  11:#### 90 ####################################################################
  12:def cmd_90(repeat_command, cmd=nil)
  13:@returnParamArray.clear
  14:print "lowering volume from ", @volume, "\n"
  15:cmd_313(@volume-1)
  16:
  17:return @returnParamArray
  18:end
  19:#### 97 ####################################################################
  20:def cmd_97(cmd=nil)
  21:@returnParamArray.clear
  22:if(@mute)
  23:  SendCommand("ke 01 00",10000,4)
  24:else
  25:  SendCommand("ke 01 01",10000,4)
  26:end
  27:@mute=!@mute
  28:return @returnParamArray
  29:end
  30:#### 154 ####################################################################
  31:def cmd_154(cmd=nil)
  32:@returnParamArray.clear
  33:SendCommand("kb 01 60",1000,4)
  34:return @returnParamArray
  35:end
  36:#### 166 ####################################################################
  37:def cmd_166(cmd=nil)
  38:@returnParamArray.clear
  39:SendCommand("kb 01 01",1000,4)
  40:return @returnParamArray
  41:end
  42:#### 192 ####################################################################
  43:def cmd_192(pk_pipe, pk_device_pipes, cmd=nil)
  44:@returnParamArray.clear
  45:conn_.Send("ka 01 00")
  46:
  47:return @returnParamArray
  48:end
  49:#### 193 ####################################################################
  50:def cmd_193(pk_pipe, cmd=nil)
  51:@returnParamArray.clear
  52:conn_.Send("ka 01 01\r")
  53:
  54:return @returnParamArray
  55:end
  56:#### 313 ####################################################################
  57:def cmd_313(level, cmd=nil)
  58:@returnParamArray.clear
  59:@volume=level.to_i()
  60:ilevel = (@volume * 0.64).to_i
  61:print "setting volume to ", ilevel , "\n"
  62:
  63:if ilevel <10
  64:  SendCommand("kf 01 0" + ilevel.to_s,1000,4)
  65:else
  66:  SendCommand("kf 01 " + ilevel.to_s,1000,4)
  67:end
  68:SetDeviceDataInDB( device_.devid_, 158, ilevel .to_s) # 158 = DEVICEDATA_Volume_Level_CONST
  69:print "volume and corresponding device data set\n"
  70:
  71:return @returnParamArray
  72:end
  73:#### 316 ####################################################################
  74:def cmd_316(cmd=nil)
  75:@returnParamArray.clear
  76:SendCommand("kb 01 02",1000,4)
  77:return @returnParamArray
  78:end
  79:#### 317 ####################################################################
  80:def cmd_317(cmd=nil)
  81:@returnParamArray.clear
  82:SendCommand("kb 01 21",1000,4)
  83:return @returnParamArray
  84:end
  85:#### 355 ####################################################################
  86:def cmd_355(cmd=nil)
  87:@returnParamArray.clear
  88:# Initialize --- Date: 28.02.2008
  89:# the docs are wrong.  they say responses are terminated with a \r.  In reality some sets do, others don't.
  90:# some sets won't respond to ka 01 ff when the tv is off.  others do.
  91:@mute = false;
  92:
  93:# unfortunately we have to turn the device on if it's off to know that it's alive or else it won't respond to anything
  94:@input=-1
  95:for iRetry in 0...4
  96:    print "Initializing unit\n"
  97:    conn_.Send("ka 01 ff\r")
  98:    # wait 2 seconds for the status command, which won't work if the tv is off
  99:    buf = conn_.RecvDelimited("x", 2000)
 100:    if( !buf.nil? && !buf.index("01 OK").nil? )
 101:        print "Initialized ok - tv is on\n"
 102:      volume_level = GetCurrentDeviceData( device_.devid_, 207 ) # 59 = DEVICEDATA_Initial_Volume_CONST
 103:      if( !volume_level.empty? && volume_level!="ERR Parameter not found" )
 104:         print "Setting volume to ", volume_level, "\n"
 105:         cmd_313(volume_level)
 106:         SetDeviceDataInDB( device_.devid_, 39, volume_level ) # 39 = DEVICEDATA_Volume_Level_CONST
 107:      end
 108:        return
 109:    end
 110:    print "TV is either off or not connected\n"
 111:   
 112:   # try turning it on
 113:    conn_.Send("ka 01 01\r")
 114:
 115:    # wait 10 seconds for the TV to respond
 116:    buf = conn_.RecvDelimited("x", 10000)
 117:    if( !buf.nil? && !buf.index("01 OK").nil? )
 118:        print "Initialized ok - tv was off\n"
 119:        # wait 1 second and turn it off again so it returns to it's prior state
 120:        sleep(1)
 121:      volume_level = GetCurrentDeviceData( device_.devid_, 207 ) # 59 = DEVICEDATA_Initial_Volume_CONST
 122:      if( !volume_level.empty? && volume_level!="ERR Parameter not found" )
 123:         print "Setting volume to ", volume_level, "\n"
 124:         cmd_313(volume_level)
 125:         SetDeviceDataInDB( device_.devid_, 39, volume_level ) # 39 = DEVICEDATA_Volume_Level_CONST
 126:      end
 127:       conn_.Send("ka 01 00\r")
 128:        return
 129:    end
 130:
 131:    print "TV is not connected\n"
 132:
 133:    sleep(1)
 134:end
 135:
 136:#DisableDevice( device_.devid_, true )
 137:print "The device wouldn't respond. Disabling it.\n"
 138:return @returnParamArray
 139:end
 140:#### 361 ####################################################################
 141:def cmd_361(cmd=nil)
 142:@returnParamArray.clear
 143:SendCommand("kb 01 90",1000,4)
 144:return @returnParamArray
 145:end
 146:#### PRIVATE METHODS ####################################################################
 147:# Private - Date: 28.02.2008
 148:# the docs are wrong.  they say responses are terminated with a \r.  In reality some sets do, others don't.
 149:
 150:def SendCommand(command,timeout,retransmit)
 151:   for i in 0...retransmit
 152:      conn_.Send(command + "\r")
 153:      # wait up to 8 seconds since it may be very slow if this is an 'on' command
 154:      
 155:       buf = conn_.RecvDelimited("x", timeout)
 156:       
 157:       if( !buf.nil? && (!buf.index("01 OK").nil? || !buf.index("01 NG").nil?))
 158:         print "Received good reply in less than ", timeout, "ms: ", buf, "\n"
 159:         return
 160:      else
 161:         buf = conn_.Recv(1000,1000);
 162:         print "Flushed buffer: ", buf, "invalid resonse in ", timeout, "seconds\n"
 163:      end
 164:   end
 165:end
 166:#### 712 ####################################################################
 167:def cmd_712(cmd=nil)
 168:@returnParamArray.clear
 169:SendCommand("kb 01 05",1000,4)
 170:return @returnParamArray
 171:end
 172:#### 767 ####################################################################
 173:def cmd_767(cmd=nil)
 174:@returnParamArray.clear
 175:SendCommand("kb 01 91",1000,4)
 176:return @returnParamArray
 177:end
 178:#### 873 ####################################################################
 179:def cmd_873(cmd=nil)
 180:@returnParamArray.clear
 181:SendCommand("kb 01 00",1000,4)
 182:return @returnParamArray
 183:end
 184:#### 930 ####################################################################
 185:def cmd_930(cmd=nil)
 186:@returnParamArray.clear
 187:SendCommand("kb 01 92",1000,4)
 188:return @returnParamArray
 189:end
 190:#### START SETTERS ####################################################################
 191:def initialize()
 192:super
 193:@returnParamArray=Array.new
 194:end
 195:####  END  SETTERS ####################################################################
 196:end
« Last Edit: November 06, 2012, 01:31:59 am by brent2009 »