LinuxMCE Forums
May 21, 2013, 07:11:43 am GMT-1 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Rule #1 - Be Patient - Rule #2 - Don't ask when, if you don't contribute - Rule #3 - You have coding skills - LinuxMCE's small brother is available: http://www.agocontrol.com
 
   Home   Help Search Chat Login Register  
Pages: [1]
  Print  
Author Topic: Help with Ruby Code  (Read 1381 times)
gadget
Veteran
***
Posts: 136


View Profile
« on: June 21, 2009, 05:35:38 am »

I am trying to create a device template for an Infocus IN74 projecter which is contolled via a serial cable.
I have adapted the Denon ruby code but it doesn't compile correctly.
There is also an error that Paritybit/Stopbit 8N1 NOT supported.

The commands to switch the device on/off are (PWR1) and (PWR0) inclusive of the brackets. Not sure if the brackets would be a problem.


Code:
1 06/21/09 14:11:02 88 (spawning-device) Starting... 1
1 06/21/09 14:11:02 88 (spawning-device) Found /usr/pluto/bin/Generic_Serial_Device
01 06/21/09 14:11:02.877 Paritybit/Stopbit 8N1 NOT supported. <0xb600bb90>
RCODE:
   0:require 'Ruby_Generic_Serial_Device'
   1:class Command < Ruby_Generic_Serial_Device::RubyCommandWrapper
   2:end
   3:class Device_88 < Ruby_Generic_Serial_Device::RubySerialIOWrapper
   4:#### 192 ####################################################################
   5:def cmd_192(pk_pipe, pk_device_pipes, cmd=nil)
   6:@returnParamArray.clear
   7:conn_.Send("\(PWR1\)")
   8:
   9:return @returnParamArray
  10:end
  11:#### 193 ####################################################################
  12:def cmd_193(pk_pipe, cmd=nil)
  13:@returnParamArray.clear
  14:conn_.Send("\(PWR0\)")
  15:
  16:return @returnParamArray
  17:end
  18:#### 355 ####################################################################
  19:def cmd_355(cmd=nil)
  20:@returnParamArray.clear
  21:# Initialize --- Date: 22.06.2009
  22:
  23:initok=false
  24:
  25:
  26:# It doesn't respond to anything but power on when it's off.  Before turning it on and off
  27:# See if it responds to something it normally would while it's on
  28:
  29:for iRetry in 0...4
  30:    print "Initializing unit\n"
  31: conn_.Send("(PWR?)")
  32:    buf = conn_.Recv(200, 1000)
  33:    if( !buf.nil? && !buf.index("(PWR1)" ).nil? )
  34:        print "Initialized ok\n"
  35: initok=true
  36: break
  37: else
  38: print "Query to device responds On Already \n"
  39: end
  40:end
  41:
  42:if initok==false
  43: for iRetry in 0...4
  44: print "Initializing unit\n"
  45: conn_.Send("(PWR1)")
  46: sleep(3);
  47: conn_.Send("(PWR?)")
  48: buf = conn_.Recv(200, 4000)
  49: if( !buf.nil? && (!buf.index("(PWR1)").nil? )
  50: print "Initialized ok from off state\n"
  51: initok=true
  52: break
  53: else
  54: print "Failed to initialize\n"
  55: end
  56: print "Failed to initialize.  Wait 1 secs and try again\n"
  57: sleep(1)
  58: end
  59:end
  60:
  61:if initok==false
  62: DisableDevice( device_.devid_, true )
  63: print "The device wouldn't respond. Disabling it.\n"
  64: return
  65:end
  66:
  67:print "Initialized ok, doing log\n"
  68:
  69:$logFile = File.new("/var/log/pluto/InfocusIN74.log", "w")
  70:return @returnParamArray
  71:end
  72:#### START SETTERS ####################################################################
  73:def initialize()
  74:super
  75:@returnParamArray=Array.new
  76:end
  77:####  END  SETTERS ####################################################################
  78:end
 80:01 06/21/09 14:11:02.881 Failed loading code: Error loading code:
error: (eval):78: compile error
(eval):53: syntax error, unexpected kELSE, expecting ')'
(eval):55: syntax error, unexpected kEND, expecting ')'
(eval):58: syntax error, unexpected kEND, expecting ')'
(eval):71: syntax error, unexpected kEND, expecting ')'
(eval):78: syntax error, unexpected kEND, expecting ')', line: 78
Logged
colinjones
Alumni
LinuxMCE God
*
Posts: 3003


View Profile
« Reply #1 on: June 21, 2009, 06:21:50 am »

You've missed a close bracket on line 49

Should be

if( !buf.nil? && (!buf.index("(PWR1)").nil? ))

to close that evaluation. The problem is it reads the rest of the code as part of that evaluation trying to find the close for the first bracket, doesn't find it, so cannot continue.
Also, I'm not at all familiar with Ruby, but you may have to escape the '(' and ')' in that string

if( !buf.nil? && (!buf.index("\(PWR1\)").nil? )) same for line 33....

in fact if line 33 is working, then you can probably remove a bracket from line 49, thus:

if( !buf.nil? && !buf.index("(PWR1)").nil? )

Note, still the question mark on the escaping issue.
« Last Edit: June 21, 2009, 06:24:35 am by colinjones » Logged
gadget
Veteran
***
Posts: 136


View Profile
« Reply #2 on: June 21, 2009, 07:03:16 am »

Thanks for the quick response.

The missing close bracket has fixed the error, thank you.

I have fixed the partity error by changing from 8N1 -> N81.

gadget
Logged
gadget
Veteran
***
Posts: 136


View Profile
« Reply #3 on: June 21, 2009, 12:24:23 pm »

I am now getting this error in the log

Failed Opening serial port: ttyS_54_0. <0xb4efdb90>
IOPool::handleStartup Open() failed <0xb4efdb90>

This is the serial port of the GC100 which is device 54.
How can i check what is causing this error.

gadget
Logged
ddamron
Alumni
wants to work for LinuxMCE
*
Posts: 962



View Profile WWW
« Reply #4 on: June 22, 2009, 04:10:54 pm »

Sorry, I don't have a GC100, I cannot test it.
I would, however, suggest that you use the Process Incoming Data routine rather than transmitting, waiting, then receiving in the same module.

basically, Ruby isn't threaded, so the faster you can return control, the better.
I'd use a global variable to track the command sent, and then when you receive data from process incoming data, you can compare the response to the command.

HTH,

Dan
Logged

The only intuitive interface is the nipple.  After that it's all learned.
My other computer is your windows box.
I'm out of my mind.  Back in 5 minutes.
Q:  What's Red and smells like blue paint?

A:  Red Paint.
gadget
Veteran
***
Posts: 136


View Profile
« Reply #5 on: June 23, 2009, 03:16:36 am »

I couldn't work out what the problem was, but have since deleted and re-created the device and am no longer getting the error.

Thanks
Logged
tschak909
LinuxMCE God
****
Posts: 5101

DOES work for LinuxMCE.


View Profile
« Reply #6 on: June 23, 2009, 06:31:24 am »

Please try not to re-create a device template!

Device Templates can not easily be deleted, and it makes check-in much more difficult.

-Thom
Logged
gadget
Veteran
***
Posts: 136


View Profile
« Reply #7 on: June 23, 2009, 02:40:00 pm »

I only deleted the AV-device and re-added it in from the same device template. I am in the process of creating some device templates for some of my equipment so will not delete them.
Hope to have a few to check in soon.

gadget
Logged
gadget
Veteran
***
Posts: 136


View Profile
« Reply #8 on: July 14, 2009, 01:10:12 pm »

My device has stopped working now and I get the following error when the device initializes or when  i do a Messagesend.
Code:
========== NEW LOG SECTION ==========
1 07/14/09 22:03:52 107 (spawning-device) Starting... 1
1 07/14/09 22:03:52 107 (spawning-device) Found /usr/pluto/bin/Generic_Serial_Device
01 07/14/09 22:03:54.346 GSD Port is not specified. Instantiating non-IO Wrapper. <0xb60ddb90>
RCODE:
   0:require 'Ruby_Generic_Serial_Device'
   1:class Command < Ruby_Generic_Serial_Device::RubyCommandWrapper
   2:end
   3:class Device_107 < Ruby_Generic_Serial_Device::RubySerialWrapper
   4:#### 192 ####################################################################
   5:def cmd_192(pk_pipe, pk_device_pipes, cmd=nil)
   6:@returnParamArray.clear
   7:conn_.Send("(PWR1)")
   8:
   9:return @returnParamArray
  10:end
  11:#### 193 ####################################################################
  12:def cmd_193(pk_pipe, cmd=nil)
  13:@returnParamArray.clear
  14:conn_.Send("(PWR0)")
  15:
  16:return @returnParamArray
  17:end
  18:#### 355 ####################################################################
  19:def cmd_355(cmd=nil)
  20:@returnParamArray.clear
  21:# Initialize --- Date: 22.06.2009
  22:
  23:initok=false
  24:
  25:
  26:# It doesn't respond to anything but power on when it's off.  Before turning it on and off
  27:# See if it responds to something it normally would while it's on
  28:
  29:for iRetry in 0...4
  30: print "Initializing unit\n"
  31: conn_.Send("(PWR?)")
  32: buf = conn_.Recv(200, 1000)
  33: if( !buf.nil? && !buf.index("(PWR1)" ).nil? )
  34:        print "Initialized ok\n"
  35: initok=true
  36: break
  37: else
  38: print "Query to device responds On Already \n"
  39: end
  40:end
  41:
  42:# if initok==false
  43:# for iRetry in 0...4
  44:# print "Initializing unit\n"
  45:# conn_.Send("(PWR1)")
  46:# sleep(3);
  47:# conn_.Send("(PWR?)")
  48:# buf = conn_.Recv(200, 4000)
  49:# if( !buf.nil? && (!buf.index("(PWR1)").nil? ))
  50:# print "Initialized ok from off state\n"
  51:# initok=true
  52:# break
  53:# else
  54:# print "Failed to initialize\n"
  55:# end
  56:# print "Failed to initialize.  Wait 1 secs and try again\n"
  57:# sleep(1)
  58:# end
  59:#end
  60:
  61:if initok==false
  62: # DisableDevice( device_.devid_, true )
  63: print "The device wouldn't respond. Disabling it.\n"
  64: return
  65:end
  66:
  67:print "Initialized ok, doing log\n"
  68:
  69:$logFile = File.new("/var/log/pluto/InfocusIN74.log", "w")
  70:return @returnParamArray
  71:end
  72:#### START SETTERS ####################################################################
  73:def initialize()
  74:super
  75:@returnParamArray=Array.new
  76:end
  77:####  END  SETTERS ####################################################################
  78:end
 80:01 07/14/09 22:03:54.412 Error while calling method: Cannot call class method: cmd_355
error: undefined local variable or method `conn_' for #, line: 31
backtrace:
in: (eval): 31
from (eval):31:in `cmd_355'
from (eval):29:in `each'
from (eval):29:in `cmd_355'

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!