Results 1 to 4 of 4

Thread: Going crazy here - please help me getting some values from the Windows registry!

  1. #1
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,477

    Default Going crazy here - please help me getting some values from the Windows registry!

    I am very close to a working setup of choosing web radio channels and turning on and off amps from the webserver. The only thing I still need is the ability to get the currently playing channel from the Windows system registry and into a table. I have a similar system running for temperature control in the house, but I was unable to modify it for use in this (probably because it's slightly different in the layers). The system registry is in this format:

    Code:
    [HKEY_CURRENT_USER\Software\Automatisering\Lydogbilde\Radiokanal]
    
    [HKEY_CURRENT_USER\Software\Automatisering\Lydogbilde\Radiokanal\1]
    "Radiokanal"="2"
    
    [HKEY_CURRENT_USER\Software\Automatisering\Lydogbilde\Radiokanal\10]
    "Radiokanal"="0"
    
    [HKEY_CURRENT_USER\Software\Automatisering\Lydogbilde\Radiokanal\11]
    "Radiokanal"="1"
    So each zone has it's own subkey under the key Software\Automatisering\Lydogbilde\Radiokanal, numbered from 1-20. It's the value "Radiokanal" (radio channel) that I want to put into a table with "true" for the channel that's running and "false" for the other 9 channels in the system. I can create an empty table with all entries like this:

    Code:
    LydogBilde = LydogBilde or {}
    LydogBilde.Radiokanal = LydogBilde.Radiokanal or {}
    LydogBilde.SettRadiokanal = LydogBilde.SettRadiokanal or {}
    LydogBilde.Nettside = LydogBilde.Nettside or {}
    LydogBilde.Nettside.Radiokanal = LydogBilde.Nettside.Radiokanal or {} 
    
    
    local max_n = table.getn(LydogBilde.SoneID)
    local n
    local kanal
    
    local kanal_lookup = {
    [0] = "0",
    [1] = "1",
    [2] = "2",
    [3] = "3",
    [4] = "4",
    [5] = "5",
    [6] = "6",
    [7] = "7",
    [8] = "8",
    [9] = "9",
    }
    
    for n = 1,max_n,1 do
        for kanal = 0,9,1 do
            local kanal_string = kanal_lookup[kanal]
            LydogBilde.Nettside.Radiokanal[kanal_string] = LydogBilde.Nettside.Radiokanal[kanal_string] or {}
            LydogBilde.Nettside.Radiokanal[kanal_string][n] = "false"
        end
    end
    This gives me a table that looks like this and has ten nested tables, one for each channel showing if it's playing in zone 1-20 (only the two first channels are here for illustration):

    Code:
    { -- #0
       ["1"] = { -- #1
          [1] = "false",
          [2] = "false",
          [3] = "false",
          [4] = "false",
          [5] = "false",
          [6] = "false",
          [7] = "false",
          [8] = "false",
          [9] = "false",
          [10] = "false",
          [11] = "false",
          [12] = "false",
          [13] = "false",
          [14] = "false",
          [15] = "false",
          [16] = "false",
          [17] = "false",
          [18] = "false",
          [19] = "false",
          [20] = "false",
       } -- #1,
       ["0"] = { -- #2
          [1] = "false",
          [2] = "false",
          [3] = "false",
          [4] = "true",
          [5] = "false",
          [6] = "false",
          [7] = "false",
          [8] = "false",
          [9] = "false",
          [10] = "false",
          [11] = "false",
          [12] = "false",
          [13] = "false",
          [14] = "false",
          [15] = "false",
          [16] = "false",
          [17] = "false",
          [18] = "false",
          [19] = "false",
          [20] = "false",
       } -- #2,
    But can anybody please help me with how to convert the channel numbers in the registry showing what's playing in each zone to this table? If it's unclear I can upload a sample of code that does just about the same thing for my heat setup, but which I can't manage to modify. This is the code I'm trying with, that doesn't work:

    Code:
    local max_n = table.getn(LydogBilde.SoneID)
    local n
    local kanal
    
    local kanal_lookup = {
    [0] = "0",
    [1] = "1",
    [2] = "2",
    [3] = "3",
    [4] = "4",
    [5] = "5",
    [6] = "6",
    [7] = "7",
    [8] = "8",
    [9] = "9",
    }
    
    LydogBilde.Nettside.Radiokanal ={
    [1] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\1', 0):Read('Radiokanal')),
    [2] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\2', 0):Read('Radiokanal')),
    [3] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\3', 0):Read('Radiokanal')),
    [4] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\4', 0):Read('Radiokanal')),
    [5] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\5', 0):Read('Radiokanal')),
    [6] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\6', 0):Read('Radiokanal')),
    [7] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\7', 0):Read('Radiokanal')),
    [8] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\8', 0):Read('Radiokanal')),
    [9] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\9', 0):Read('Radiokanal')),
    [10] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\10', 0):Read('Radiokanal')),
    [11] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\11', 0):Read('Radiokanal')),
    [12] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\12', 0):Read('Radiokanal')),
    [13] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\13', 0):Read('Radiokanal')),
    [14] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\14', 0):Read('Radiokanal')),
    [15] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\15', 0):Read('Radiokanal')),
    [16] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\16', 0):Read('Radiokanal')),
    [17] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\17', 0):Read('Radiokanal')),
    [18] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\18', 0):Read('Radiokanal')),
    [19] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\19', 0):Read('Radiokanal')),
    [20] = tonumber(win.CreateRegistry('HKEY_CURRENT_USER', 'Software\\Automatisering\\LydogBilde\\Radiokanal\\20', 0):Read('Radiokanal')),
    }
    
    local kanal_string = kanal_lookup[kanal]
    print(kanal_lookup[kanal])
    
    for n = 1,max_n,1 do
        for kanal = 0,9,1 do
            local kanal_string = kanal_lookup[kanal]
            LydogBilde.Nettside.Radiokanal[kanal_string] = LydogBilde.Nettside.Radiokanal[kanal_string]
            LydogBilde.Nettside.Radiokanal[kanal_string][n] = true
        end
    end
    I have spent several hours today trying to get it to work, and now it's 11 P.M. and I need to quit for my own sanity's sake. I don't think I can get any further anyway, I've been running around in circles the last couple of hours. I need it to be the registry (like the working heat system) because I have more than one program that accesses the data from there. So please help me out of my misery! I will of course be ready tomorrow morning to explain anything that's unclear or upload any parts of the system that you would like to see if necessary.
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

  2. #2
    Join Date
    Sep 2008
    Posts
    150

    Default

    If you are trying to change a string number to an actual number for later comparison, I've previously multiplied the string number by 1. Ie "3"*1 equals the number 3. I've found looking in the lua variables handy as it says whether its a number or not.
    Perhaps try that?
    Jon.

  3. #3
    Join Date
    Jul 2001
    Location
    Risør - Norway
    Posts
    5,477

    Default

    Hi, Jon! Well, not exactly. I know who do do that. I'm trying to do something similar to what mostly you (with the web page and the buttons) and a bit Ron (mainly the registry stuff) helped me with before. The code I'm working with is Ron's if I remember correctly. The problem is the nested tables. Main table is, as you can see 0-9 (which will be expanded with more radio channels at a later date) , and under that there's one entry for each zone, where false means that this channel isn't playing in that zone (so red button) and true means that it is (so green button - still using the same buttons you had!). The basic setup is in other words very close to your temperature web page, and it's built on that, mostly with search replace and adding and removing some columns. So I'm trying to get from a flat table in the registry, with 20 zones and the one channel playing in each of those zones to the nested table with 9 (later more) channels and which zones they are playing in. Is that anywhere near comprehensible? I was close to banging my head against the wall yesterday!

    I have made a package with the GML stripped down to one startup script for the stuff that's needed in the background, and then scripts to get the needed tables. One script to create the source (which I can easily convert to picking it out of the registry) and one to create the "offending" problem table that I want to convert the source to, but the problem table is only filled with "false" for every setting. So what I need is to convert the source table to the problem table. If you don't need all the stuff, here's the source table:

    Code:
    LydogBilde.Nettside.Sourcetable = {
    [1] = 1,
    [2] = 2,
    [3] = 3,
    [4] = 4,
    [5] = 5,
    [6] = 6,
    [7] = 7,
    [8] = 7,
    [9] = 9,
    [10] = 10,
    [11] = 11,
    [12] = 12,
    [13] = 0,
    [14] = 5,
    [15] = 5,
    [16] = 6,
    [17] = 7,
    [18] = 7,
    [19] = 9,
    [20] = 5,
    }
    Here's code that makes the table with the correct format, but only "false" as the data



    HOLY CR@P!!!!!! IT'S A MIRACLE!!!!!

    Sorry, had to shout that out!
    I have actually managed it! I was working on putting together a package with only the stuff you or anybody needed to solve this stuff, when I by accident managed to solve it myself by creating the table first and then using a second set of almost the same code to populate it. I have now restarted Girder twice just to be sure, and I am right. It is solved! So now I can get to the final stuff (which should be a piece of cake compared to this) and have it running this weekend.
    Tor - managing director of the Cinema Inferno home theater and multi-zone sound system with Girder running the show in the back, NetRemote as the GUI and Media Center 17, PowerDVD and ZoomPlayer as playback software
    Hobsyssel mastiffs: http://www.hobsyssel.no

  4. #4
    Join Date
    Sep 2008
    Posts
    150

    Default

    Glad to hear its sorted. Jon.

Posting Permissions

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