Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 25

Thread: Get variable values from serial plugin

  1. #11
    Join Date
    Jul 2007
    Location
    Netherlands
    Posts
    370

    Default

    Try this one (copy paste error)

    and about the missing (); just testing your lua skills
    Last edited by Tieske8; June 13th, 2011 at 04:19 PM. Reason: removed attachment
    Using: Win7 MCE, Girder, xPL, RFXcom, HomeEasy

    http://www.thijsschreijer.nl

  2. #12

    Default

    Variable inspector attached.

    I get:

    Serial: Onkyo-Ts-Sr-804 : Command queued: 50 57 51 53 54 4E PWQSTN at postion 1
    Serial: Onkyo-Ts-Sr-804 : Simple Send: 50 57 51 53 54 4E 0D PWQSTN.
    ONKYO plugin received some data:
    Data received: nil
    Code received: 16384
    Serial: Onkyo-Ts-Sr-804 : Simple Receive: Data Code: 0
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Variable Inspector v3.jpg 
Views:	146 
Size:	86.6 KB 
ID:	6252  

  3. #13
    Join Date
    Jul 2007
    Location
    Netherlands
    Posts
    370

    Default

    another one...

    What I did so far;
    • table handling responses was only setup after the first response (didn't make sense)
    • updated all commands ? to QSTN
    • added error notification
    please try a number of commands after each other;
    • Onkyo:PowerOn()
    • Onkyo:PowerOff()
    • Onkyo:PowerState()
    The variable inspector doesn't show the local variables, but they are there. It won't show the responses table but if you enter;
    table.print(Onkyo.Responses)
    You'll get a nice list.
    But the variables won't be there until they have been requested at least once.

    The code returned in your previous post; 16384, means 'no reponse timeout'. This version should now clearly spell out any codes returned.

    PS. the responses are incorrect, but does the device react to the commands?
    Attached Files Attached Files
    Using: Win7 MCE, Girder, xPL, RFXcom, HomeEasy

    http://www.thijsschreijer.nl

  4. #14

    Default

    Thanks again for this awesome help!

    I changed the Lua file and ran the commands you suggested:

    Onkyo:PowerOn()

    Response:
    Serial: Onkyo-Ts-Sr-804 : Command queued: 50 57 4F 4E PWON at postion 1
    Serial: Onkyo-Ts-Sr-804 : Simple Send: 50 57 4F 4E 0D PWON.
    Onkyo-Ts-Sr-804 had a communications error;
    Codes returned (40 00): NORESPONSETIMEOUT
    Serial: Onkyo-Ts-Sr-804 : Simple Receive: Data Code: 0


    Onkyo:PowerOff()

    Response:
    Serial: Onkyo-Ts-Sr-804 : Command queued: 50 57 53 54 41 4E 44 42 59 PWSTANDBY at postion 1
    Serial: Onkyo-Ts-Sr-804 : Simple Send: 50 57 53 54 41 4E 44 42 59 0D PWSTANDBY.
    Onkyo-Ts-Sr-804 had a communications error;
    Codes returned (40 00): NORESPONSETIMEOUT
    Serial: Onkyo-Ts-Sr-804 : Simple Receive: Data Code: 0


    Onkyo:PowerState()

    Response:
    Serial: Onkyo-Ts-Sr-804 : Command queued: 50 57 51 53 54 4E PWQSTN at postion 1
    Serial: Onkyo-Ts-Sr-804 : Simple Send: 50 57 51 53 54 4E 0D PWQSTN.
    Onkyo-Ts-Sr-804 had a communications error;
    Codes returned (40 00): NORESPONSETIMEOUT
    Serial: Onkyo-Ts-Sr-804 : Simple Receive: Data Code: 0


    table.print(Onkyo.Responses)

    Response:
    { -- #0
    ["PW"] = function,
    ["TF"] = function,
    ["MU"] = function,
    ["MV"] = function,
    ["SR"] = function,
    ["TM"] = function,
    ["MS"] = function,
    ["CV"] = function,
    ["Z2"] = function,
    ["SI"] = function,
    ["Z1"] = function,
    } -- #0

  5. #15
    Join Date
    Jul 2007
    Location
    Netherlands
    Posts
    370

    Default

    The no response timeout is pretty obvious. Question is what is causing it.
    I just ran into a similar problem myself with my new LG TV, which I couldn't get connected. It turned out I had the X10 CM11 driver still accessing (and hence blocking) the COM port. So can you make sure that the com port is free and used only by the Onkyo driver? Check the component manager as well as the plugins in the config screen.

    A sure way to do this is to install a com port monitor and start Girder and see whether the port gets accessed, disable all serial stuff until Girder starts without com port access. Then reenable only the Onkyo.

    Another thing to try is accessing it using a terminal app, use it to connect to the Onkyo and manually send commands. If this works as expected, then you know your hardware is fine and it is for sure a Girder problem.

    finally try using the serial action to send a command instead of the plugin commands
    Using: Win7 MCE, Girder, xPL, RFXcom, HomeEasy

    http://www.thijsschreijer.nl

  6. #16

    Default

    Thanks - I'll try to look at it some more. I believe there was a small error in the Lua; Instead of PWQSTN it might have to be PWRQSTN with "!1" in front of it. However, the error is still there.



    Onkyo:PowerState()


    Serial: Onkyo-Ts-Sr-804 : Command queued: 21 31 50 57 52 51 53 54 4E !1PWRQSTN at postion 1
    Serial: Onkyo-Ts-Sr-804 : Simple Send: 21 31 50 57 52 51 53 54 4E 0D !1PWRQSTN.
    Onkyo-Ts-Sr-804 had a communications error;
    Codes returned (40 00): NORESPONSETIMEOUT
    Serial: Onkyo-Ts-Sr-804 : Simple Receive: Data Code: 0
    Serial: Onkyo-Ts-Sr-804 : Simple Receive: Data 21 31 50 57 52 30 31 1A !1PWR01. Code: 8192
    Serial: Onkyo-Ts-Sr-804 : ERROR: Incomplete response to last command


    I included a screenshot of the RS232 terminal application, and it seems to communicate fine. When I send !1PWRQSTN I get !1PWR01 back (meaning "On").
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Termite screenshot.jpg 
Views:	145 
Size:	21.4 KB 
ID:	6255  
    Last edited by thunderstorm77; June 14th, 2011 at 03:16 PM.

  7. #17
    Join Date
    Jul 2007
    Location
    Netherlands
    Posts
    370

    Default

    That probably means getting deeper into the code, how the commands are being built upon sending and how commands are being processed upon receiving.
    I'll be on holiday for a couple of weeks, so no more time to look into this until early July.
    Using: Win7 MCE, Girder, xPL, RFXcom, HomeEasy

    http://www.thijsschreijer.nl

  8. #18

    Default

    I believe part of the problem is solved. I did what you said and installed a trial version of a com port sniffer and the terminal app you suggested. I used these to send the command !1PWRQSTN and realized that I get slightly different responses/no responses when changing the End Character - CR/LF. When I used LF, I got the correct response. So I changed the Lua script from:

    ReceiveTerminator = serial.hextobyte ('0D'),
    SendTerminator = serial.hextobyte ('0D'),

    To:

    ReceiveTerminator = serial.hextobyte ('1A'),
    SendTerminator = serial.hextobyte ('0A'),

    For simplicity I added:

    SendStartByte = "!1",

    So that there's no need to include the "!1" in every command.


    Then, when running Onkyo:PowerState() I get:

    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 30 !1PWR00 Code: 1



    I received some occational errors regarding timeout, so I changed these values as well:

    IncompleteResponseTimeout = 200,
    NoResponseTimeout = 200,

    From 200 to 500 ms. Then it seems to be working fine.

    Now, with this accomplished, I'm still not able to get this:


    Serial: Onkyo PR-SC886 : Simple Receive: Data 21 31 50 57 52 30 30 !1PWR00 Code: 1


    ...into a variable so I can display its value. I have tried everything, hope someone can help me on this last bit!

    I believe the Lua code taking care of the response is:

    Responses = {
    PW = function(Settings, data)
    _, _, self.PowerMain = string.find (data,"PW(.-)$")
    print ("Power:",(self.PowerMain))
    NetRemote.SendLabel ('power', (self.PowerMain))
    end,

    (more code below)

    What does the "Code 1" in the response mean?

    I have attached the latest Lua file.
    Attached Files Attached Files
    Last edited by thunderstorm77; June 25th, 2011 at 12:20 PM. Reason: Update

  9. #19

    Default

    OK, I'm making some progress with Lua I'm actually starting to like Lua, since it's not so difficult as it looks initially. It really helped using a Lua editor instead of Notepad, since reserved words are highlighted.

    Now I'm able to get the response from Onkyo into a variable, and I can print it's value and send to Netremote. I interpret this as an indicator that all communication and settings work well. These have not changed since the last post.

    One small obstacle remains. In the Lua code below, the response is stored in the variable "data". Right after the 'gir.Triggerevent' line, I'm able to display the correct content of the response in "data".

    However, the value in "data" is "nil" when moving on to the "Responses" table (The "PW", "MV" functions etc.). I moved the code in "PW" and "MV" up to right after 'gir.Triggerevent' and it works great and is passed to NetRemote, except that only the last value in "data" is stored, so that everything is "nil" other than the latest value (i.e. 'power' becomes "nil" when asking for the volume level).

    Any ideas??


    Lua code:



    ReceiveResponse = function ( self, data, code )

    if math.band (code,serial.RXCHAR) and data then
    gir.TriggerEvent ('Onkyo:'..data,18)
    --print (" Just raised an event 'Onkyo ...'")
    local cmd = string.sub(data, 1, 2)
    if cmd then
    local func = self.Responses[cmd]
    if func then
    --print (" Calling: " .. cmd)
    func(self.Settings, data)
    --print (" Called : " .. cmd)
    end
    else
    --print (" cmd = nil")
    end
    else
    -- some error occured, go print it
    print (self.Name .. " had a communications error;")
    print (self:GetError(data, code))
    end

    if math.band (code,serial.ERR) then
    gir.LogMessage(self.Name, 'Communication Error',3)
    end

    if math.band (code, serial.NORESPONSETIMEOUT) > 0 then
    code = serial.zerobits (code,serial.NORESPONSETIMEOUT)
    end -- tells G4 not to report communication errors\timeouts in the Lua Console

    serial.Classes.Queued.ReceiveResponse (self,data,code)
    end, --Should this "End" really be here??

    Responses = {
    PW = function(Settings, data)
    _, _, self.PowerMain = string.find (data,"PW(.-)$")
    print ("Power:",(self.PowerMain))
    NetRemote.SendLabel ('power', (self.PowerMain))
    end,

    MV = function(Settings, data)
    _, _, self.RawVolume = string.find (data,"MV(.-)$")
    self.Volume = OnkyoVolumeTodb(self.RawVolume)
    print ("Main Volume:",(self.Volume))
    NetRemote.SendLabel ('OnkyoMainVolume', self.Volume)
    NetRemote.SendLabel ('OnkyoRawVolume', self.RawVolume)
    end,
    Last edited by thunderstorm77; June 30th, 2011 at 09:37 AM.

  10. #20
    Join Date
    Jul 2007
    Location
    Netherlands
    Posts
    370

    Default

    in the response functions, the 'self' variable is undefined. That might cause the nil effect on data. Try the attached one.
    Attached Files Attached Files
    Using: Win7 MCE, Girder, xPL, RFXcom, HomeEasy

    http://www.thijsschreijer.nl

Page 2 of 3 FirstFirst 123 LastLast

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
  •