Page 3 of 3 FirstFirst 123
Results 21 to 25 of 25

Thread: Get variable values from serial plugin

  1. #21

    Default

    Thanks a lot - hope you had a great vacation, good to have you back though!

    I think we got one step further. I'm not sure if I'm doing this right, but when I run

    Onkyo.Responses.PW()

    I get:
    ...\Promixis\Girder5\/plugins/serial/Onkyo PR-SC886.lua:1039: bad argument #1 to `find' (string expected, got nil)
    stack traceback:
    [C]: in function `find'
    ...\Promixis\Girder5\/plugins/serial/Onkyo PR-SC886.lua:1039: in function `PW'
    [string "Interactive"]:1: in main chunk

    I guess I need to set up a macro to update all variables in the Responses table, such as:

    Onkyo.Responses.PW()
    Onkyo.Responses.MV()
    Onkyo.Responses.MU()

    etc.

    Is this correct?

  2. #22
    Join Date
    Jul 2007
    Location
    Netherlands
    Posts
    370

    Default

    That error is to be expected
    Code:
    PW = function (self, Settings, data)
    _, _,self.PowerMain = string.find (data,"!1PW(.-)$")
    print ("Power:",(self.PowerMain))
    NetRemote.SetVariable ('power', (self.PowerMain))
    end,
    If you call through 'Onkyo.Responses.PW()', the function arguments (self, Settings, data) are not provided and hence 'nil'. So the function 'string.find(...)' doesn't have anything to search through (as data == nil ). And you get the '(string expected, got nil)' error.

    The response functions should only be called from ReceiveResponse. So if you execute;
    Code:
    Onkyo:PowerOn()    -- turn on device
    Onkyo:PowerState() -- request current power state -> will trigger a response and hence execution of ReceiveResponse
    print ('PowerState = ' .. Onkyo.PowerMain)
    You ought to get the following output (at least, and maybe some more);
    Just raised an event 'Onkyo ...' (by ReceiveResponse)
    Calling: PW (by ReceiveResponse)
    Power: ... (by Responses.PW, ... being the value)
    Called : PW (by ReceiveResponse)
    PowerState = ... (by print statement mentioned above, ... being the value)
    One thing I noted though, in the response functions, the PW function is the only one having the '!1' prefix in the string.find statement, maybe you should have a look at that.

    The PW response function will store the received value in Onkyo.PowerMain (if all works well). There you can pick it up. If you execute the 3 commands mentioned above, what's the response you get?
    Using: Win7 MCE, Girder, xPL, RFXcom, HomeEasy

    http://www.thijsschreijer.nl

  3. #23

    Default

    I removed the "!1! from the PW function. I tried the print command below, and it gave the same error message.

    It seems like the PW function in the Responses table is not executed; I get none of the prints from within that function. I get none of the responses from here either:

    local cmd = string.sub(data, 1, 2)
    if cmd then
    local func = self.Responses[cmd]
    if func then
    print (" Calling: " .. cmd)
    func(self, self.Settings, data)
    print (" Called : " .. cmd)
    end
    else
    print (" cmd = nil")
    end

    This should print something regardles - right?





    The responses I get is:


    Onkyo:PowerOn()

    Serial: Onkyo PR-SC886 : Command queued: 50 57 52 30 31 PWR01 at postion 1
    Serial: Onkyo PR-SC886 : Simple Send: 21 31 50 57 52 30 31 0A !1PWR01.
    Just raised an event 'Onkyo ...'
    Serial: Onkyo PR-SC886 : Simple Receive: Data 21 31 50 57 52 30 31 !1PWR01 Code: 1


    Onkyo:PowerState()

    Serial: Onkyo PR-SC886 : Command queued: 50 57 52 51 53 54 4E PWRQSTN at postion 1
    Serial: Onkyo PR-SC886 : Simple Send: 21 31 50 57 52 51 53 54 4E 0A !1PWRQSTN.
    Just raised an event 'Onkyo ...'
    Serial: Onkyo PR-SC886 : Simple Receive: Data 21 31 50 57 52 30 31 !1PWR01 Code: 1


    print ('PowerState = ' .. Onkyo.PowerMain)

    [string "Interactive"]:1: attempt to concatenate field `PowerMain' (a nil value)
    stack traceback:
    [string "Interactive"]:1: in main chunk

  4. #24
    Join Date
    Jul 2007
    Location
    Netherlands
    Posts
    370

    Default

    ReceiveResponse does get executed, but it doesn't have a valid response;

    Change the following lines
    Code:
    print (" Just raised an event 'Onkyo ...'")
    local cmd = string.sub(data,1,2)
    to

    Code:
    print (" Just raised an event: Onkyo " .. data )
    local cmd = string.sub(data,1,2)
    print ("Reponse code: " .. cmd)
    and post the results again.

    My guess is that the cmd extraction from the response data is incorrect.
    Using: Win7 MCE, Girder, xPL, RFXcom, HomeEasy

    http://www.thijsschreijer.nl

  5. #25

    Default

    That's it - your absolutely right. I didn't really figure out the purpose of this function:

    Code:
    local cmd = string.sub(data, 1, 2)
        if cmd then
            local func = self.Responses[cmd]
            if func then
                  print ("    Calling: " .. cmd)
                  func(self, self.Settings, data)
                  print ("    Called : " .. cmd)
            end
    I now see that this is what determines which of the functions in the responses table that is executed. And the problem is therefore that "cmd" extracts the first two digits of the response. the Onkyo always starts the response with "!1", e.g. "!1PWR01". When I changed this to extract digits 3 and 4, everything works perfectly!

    I now get all the expected feedback and communication with Netremote.

    Onkyo:PowerState()

    Results:

    Serial: Onkyo PR-SC886 : Command queued: 50 57 52 30 30 PWR00 at postion 1
    Serial: Onkyo PR-SC886 : Simple Send: 21 31 50 57 52 30 30 0A !1PWR00.
    Just raised an event 'Onkyo ...'
    Calling: PW
    Power: R00
    Called : PW
    Serial: Onkyo PR-SC886 : Simple Receive: Data 21 31 50 57 52 30 30 !1PWR00 Code: 1



    print ('PowerState = ' .. Onkyo.PowerMain)

    Results:
    PowerState = R00 -- meaning "Off"


    Now the fun part begins with setting up Netremote with feedback. I need to do some more wtk with the Lua file as it's very generic. I'll post the reults here within a few days.

    Thanks a lot to Tieske8 for the help!
    Last edited by thunderstorm77; July 10th, 2011 at 03:45 PM.

Page 3 of 3 FirstFirst 123

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •