5

I'm writing a C# Program to display the Temperature of CPU/GPU from my PS3. There is a connect button. This works really good and it shows me the Temp. from my PS3's CPU/GPU.

Now I've implemented a "refresh" button, which starts a timer for all x Seconds to do this:

public void get_psdata()
        {
            //Get data from PS3
            cputemp = PS3.GetTemperatureCELL();
            gputemp = PS3.GetTemperatureRSX();
            psversion = PS3.GetFirmwareVersion();
            psversiontype = PS3.GetFirmwareType();

            //Set data into Var
            L_cputemp_show.Text = cputemp;
            L_gputemp_show.Text = gputemp;
            L_firmware_show.Text = psversion;
            L_type_show.Text = psversiontype;

            //Update Label
            L_cputemp_show.Refresh();
        }

So this "get_psdata" works only on the first time, when i press the connect button. (The connect button starts directly the "get_psdate" function, while the refresh button does a bit different, like you can see later...)

Here is the code to run the get_psdata:

//B_connect, Connect Button
        private void b_connect_Click(object sender, EventArgs e)
        {
            //Connect CCAPI to PS3 if Button clicked
            PS3.ConnectTarget(psip);

            //Check Connection
            if (PS3.SUCCESS(PS3.ConnectTarget(psip)))
            {
                //Show Status
                MessageBox.Show("Connected to: " + psip + "!");
                this.L_status_show.Text = "Connected!"; L_status_show.ForeColor = System.Drawing.Color.Green;

                //Call Function
                get_psdata();
            }
            else
            {
                //Show Status
                MessageBox.Show("Failed to Connect to: " + psip + "!");
                this.L_status_show.Text = "Not Connected!"; L_status_show.ForeColor = System.Drawing.Color.Red;
            }
        }

For testing, I added a Messagebox.Show to the "get_psdata" function to see if it runs all x Seconds... Yes it does and this is my timer:

        //Function to set refresh delay
        public void refresh_delay()
        {
            MessageBox.Show("Delay set to " + refresh_int + " Seconds!");
            refresh_int = refresh_int * 1000; //Change to Miliseconds
            init_timer();
        }
        //Timer
        public Timer timer1;
        public void init_timer()
        {
            timer1 = new Timer();
            timer1.Tick += new EventHandler(timer1_Tick);
            timer1.Interval = refresh_int; // in miliseconds
            timer1.Start();
        }
        public void timer1_Tick(object sender, EventArgs e)
        {
            get_psdata();
        }

And this is what starts my timer:

    //B_set, Set refresh time button
    private void B_set_Click(object sender, EventArgs e)
    {
        //Check refresh Value
        refresh_string = TB_refresh.Text;

        //Check empty
        if (refresh_string != "")
        {
            //Check minimum
            refresh_int = Convert.ToInt32(TB_refresh.Text);
            if (refresh_int < 5)
            {
                DialogResult confirm = MessageBox.Show("This is not the delay you are looking for! \r (I recommend to set it bigger then 5) \r Continue with " + refresh_int + " Seconds?", "Realy dude?", MessageBoxButtons.YesNo);
                if (confirm == DialogResult.Yes)
                {
                    //Call Function
                    refresh_delay();
                }
            }
            else
            {
                //Call Function
                refresh_delay();
            }
        }
        else
        {
            MessageBox.Show("Please set refresh delay!");
        }
    }

So I'm sure that the code will run all x Seconds but the label's are only updated when I hit the connect button, but not if I start the counter after connecting with the B_set button.

The Variables from "get_psdata" are not showing the updated value. They just show the result from the first "Get". Why aren't they show the latest result?

JK.
  • 21,477
  • 35
  • 135
  • 214
k304
  • 119
  • 2
  • 11
  • 2
    Could you please narrow down your question and highlight just a problematic part of your code? Thanks and regards, – Alexander Bell Dec 18 '14 at 21:36
  • @AlexBell Okey so my question is: How can I update my Variables from the get_psdata function? It just will not work. I dont know where the problem is, thats why I added a lot of code. The failure could be everyware...(?) – k304 Dec 18 '14 at 21:40
  • 1
    Not sure if this is WPF or WinForms, but my hunch is that the problem might be with trying to update the labels from a different thread (which the timer is using). You can try dispatching the updates to the main thread. – vesan Dec 18 '14 at 21:41
  • To follow up on vesan's comment. Suggest reading this: http://stackoverflow.com/questions/661561/how-to-update-the-gui-from-another-thread-in-c – Quintium Dec 18 '14 at 21:42
  • Only partially related, but one thing you could do is split your `get_psdata` function into two pieces. You don't need to get the firmware information over and over. You could move the other two parts into a `get_pstemps` function and only get the firmware info when first connecting. – Joe M Dec 18 '14 at 21:43
  • I can't test but what happens if you try to call PS3.ConnectTarget(psip) before each call of get_psdata? – Martin Konopka Dec 18 '14 at 21:48

1 Answers1

2

If I use your code in a fresh winforms screen, all works well. I did however use the following implementation for get_psdata.

public void get_psdata()
{
    var rnd = new Random();

    //Set data into Var
    L_cputemp_show.Text = rnd.Next().ToString();
    L_gputemp_show.Text = rnd.Next().ToString();
    L_firmware_show.Text = rnd.Next().ToString();
    L_type_show.Text = rnd.Next().ToString();

    //Update Label
    L_cputemp_show.Refresh();
}

With an interval of 1 second, this gives me new values on screen every second. Could you try this code please? If this works well, then the problem is with the PS3 object that doesn't refresh its internals perhaps?

Rémi
  • 3,867
  • 5
  • 28
  • 44
John
  • 3,627
  • 1
  • 12
  • 13
  • Oh I changed my code to your example and the text refreshes all x Seconds... Thank you. But what can I do now to get it working with my code? – k304 Dec 18 '14 at 21:59
  • It looks like the "PS3.GetTemperatureCELL" does not update the cputemp var by running it? – k304 Dec 18 '14 at 22:01
  • 1
    So it seems. Is there more information about the PS3 object? Type? Documentation? – John Dec 18 '14 at 22:07
  • There is a kind of documentation here: https://ps3lib.codeplex.com/ But I couldn't find any useful information about it yet... – k304 Dec 19 '14 at 06:57
  • Try to reconnect to the PS3 in `get_psdata` with `PS3.ConnectTarget(psip)`. It's dirty but it might work. Also, it seems you're connecting twice in the function `b_connect_Click`. – John Dec 19 '14 at 09:55
  • I will try it this weekend. But yea its kind of dirty... but maybe the only possible way... – k304 Dec 19 '14 at 19:53
  • So no succes. Added the ConnectTarget to get_psdata but it does not work. Is there any other possible reason?? – k304 Dec 19 '14 at 20:01
  • I poked around in the source code of the lib you mentioned. The only way i see it working, is by putting `PS3.ClearTargetInfo()` in the `get_psdata` function before getting the values. This will force the refresh when you try to get the values from the lib. – John Dec 20 '14 at 09:16
  • Oh thank you soo much! The PS3.ClearTargetInfo(); in the get_psdata worked an the Temps are getting updated now! A huge thanks! – k304 Dec 20 '14 at 10:05