Jump to content

Problem getting a script to repeat itself


Recommended Posts

Hey Guys,

Haven't posted for awhile, but I ran into a new problem today while I was trying to make this script.

So I have a networked temperature monitor in my server room and I'm trying to download the graph that it creates and have it show up in a small GUI window. Now I've gotten it to download and display just fine, the issue happens when I try to get it to re-download the image, update the GUI and then do it again.

Here's what I have so far:

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

;Pre-Defined Variables
$hWGoose = "http://1.1.1.1/graph?width=500&height=200&time=900&refresh=0&dev=011BBCAB14000019&sen=1&sen=2&dev=2D0000008DFBC812&sen=1&sen=3" 

;--------------------------------------------------------------------------------------------

Local $hDownload = InetGet($hWGoose, @TempDir & "\test.png", 1, 1)
Do
    Sleep(100)
Until InetGetInfo($hDownload, 2) ;Check if the download is complete
InetClose($hDownload) ;Close the handle to release resources

;--------------------------------------------------------------------------------------------

Global $hGUI, $hImage, $hGraphic

;Create GUI
$hGUI = GUICreate("DFW WeatherGoose", 400, 200)
GUISetState()

;Load PNG image
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile(@TempDir & "\test.png")

;Draw PNG image
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)

;Loop until user exits
Do
   Local $hDownload = InetGet($hWGoose, @TempDir & "\test.png", 1, 1)
   Do
    Sleep(100)
   Until ((InetGetInfo($hDownload, 2)) Or (GUIGetMsg() = $GUI_EVENT_CLOSE)) ;Check if download is complete or exit GUI
   Local $nBytes = InetGetInfo($hDownload, 0)
   InetClose($hDownload) ;Close the handle to release resources
   
   _GDIPlus_Startup()
   $hImage = _GDIPlus_ImageLoadFromFile(@TempDir & "\test.png")


   $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
   _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

;Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

The problem seems to be under the Do, I've got this section and when I comment it out it works fine, just no looping like I want:

;Loop until user exits
Do
  ; Local $hDownload = InetGet($hWGoose, @TempDir & "\test.png", 1, 1)
   ;Do
    ;Sleep(100)
   ;Until ((InetGetInfo($hDownload, 2)) Or (GUIGetMsg() = $GUI_EVENT_CLOSE)) ;Check if download is complete or exit GUI
   ;Local $nBytes = InetGetInfo($hDownload, 0)
   ;InetClose($hDownload) ;Close the handle to release resources
   
   _GDIPlus_Startup()
   $hImage = _GDIPlus_ImageLoadFromFile(@TempDir & "\test.png")


   $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
   _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Ideally I want it to re-download the image and refresh the PNG every 60 seconds, but this is the only way I could think of looping the script. =

Any hints?

Edited by Jon
Link to comment
Share on other sites

Hi, i made it loop, but it's weird as it loops only 3 or 4 times, and then proceeds as if it has downloaded the image... :S

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

;Pre-Defined Variables
$hWGoose = "http://deadfix.com/wp-content/uploads/2012/09/pass.jpg"

;--------------------------------------------------------------------------------------------

;--------------------------------------------------------------------------------------------

Global $hGUI, $hImage, $hGraphic
Local $hDownload

;Create GUI
$hGUI = GUICreate("DFW WeatherGoose", 660, 800)
GUISetState()

;Load PNG image
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile(@TempDir & "\test.png")

;Draw PNG image
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)

;Loop until user exits
Do
   Function()
   Sleep(60000)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func Function()
    $hDownload = InetGet($hWGoose, @TempDir & "\test.png", 1, 1)
    Do
    Sleep(500)
    ConsoleWrite('Is it done?'&@CRLF)
    Until InetGetInfo($hDownload, 2) = True
    ConsoleWrite('Yes! Downloaded!'&@CRLF)
    InetClose($hDownload)
   _GDIPlus_Startup()
   $hImage = _GDIPlus_ImageLoadFromFile(@TempDir & "\test.png")
   $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
   _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
   ConsoleWrite($hImage&@CRLF)
EndFunc

;Clean up resources
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

When i modify the link to something unavailable it will do what i described, if the link is accurate, it works right away...

Edited by Jon
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Hehehe, gotta take it to rehab.

anyway got another one that doesn't drink as much, and deletes the image in temp.

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

;Pre-Defined Variables
$hWGoose = "http://deadfix.com/wp-content/uploads/2012/09/pass.jpg"

;--------------------------------------------------------------------------------------------

;--------------------------------------------------------------------------------------------

Global $hGUI, $hImage, $hGraphic
Local $hDownload

;Create GUI
$hGUI = GUICreate("DFW WeatherGoose", 660, 800)
GUISetState()

Do
$hDownload = InetGet($hWGoose, @TempDir & "\test.png", 1, 1)
Do
Sleep(500)
Until InetGetInfo($hDownload, 2) = True
InetClose($hDownload)
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile(@TempDir & "\test.png")
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Edited by Jon
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Oh damn....thanks for checking me into Rehab guys. My script-fu isn't very powerful yet. I'm still pretty noobish.

NutStomper: I checked out your script and it worked, but I guess I was under the influence that DoUntil had to wrap around your script, so I'm a bit confused as to why it actually works.

careca: I'm going to mess with your script here in a bit and see how it works out. 

 

Edit: dang careca, your script is pretty slick! I like it!  :thumbsup:

Thanks for all the help today guys, not much of an active, but this is one of the better web communities I've worked with so kudos and what not :)

Looks like I need to read up on GDIPlus more.  :sweating:

Edit Edit: Just for grins this is what I was working on before NutStomper/careca helped sober up my script.

Global $hGUI, $hImage, $hGraphic

;Create GUI
$hGUI = GUICreate("DFW WeatherGoose", 400, 200)
GUISetState()

;Load PNG image
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile(@TempDir & "\test.png")

;Draw PNG image
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)

$hDownload = InetGet($hWGoose, @TempDir & "\test.png", 1, 1)

;Loop until user exits
Do
   
   IF InetGetInfo($hDownload, 2) then ;Check if download is complete or 
      InetClose($hDownload)
   
      _GDIPlus_Startup()
      $hImage = _GDIPlus_ImageLoadFromFile(@TempDir & "\test.png")


      $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
      _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
   
      Filedelete(@TempDir & "\test.png")
   
      $hDownload = InetGet($hWGoose, @TempDir & "\test.png", 1, 1)
      
      
   EndIf
   
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Edited by BrokenThumb
Link to comment
Share on other sites

Thanks for the updated script NutStomper.

This is what I've got so far, and it still works when minimized without the WM_PAINT section you have. (Though yours starts up much faster and the AdlibRegister section is pretty legit for getting it to repeat on a specific time clock) I've learned a ton in this thread already!

Can you take a look and tell me what you think of it? 

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>

;Pre-Defined Variables
$hWGoose = "http://1.1.1.1/graph?width=500&height=200&time=900&refresh=0&dev=011BBCAB14000019&sen=1&sen=2&dev=2D0000008DFBC812&sen=1&sen=3" 

;--------------------------------------------------------------------------------------------

;--------------------------------------------------------------------------------------------

Global $hGUI, $hImage, $hGraphic
Local $hDownload

;Create GUI
$hGUI = GUICreate("DFW WeatherGoose", 400, 200)
GUISetState()

$hDownload = InetGet($hWGoose, @TempDir & "\test.png", 1, 1)

;Loop until user exits
Do
   
   IF InetGetInfo($hDownload, 2) then ;Check if download is complete or 
      InetClose($hDownload)
   
      _GDIPlus_Startup()
      $hImage = _GDIPlus_ImageLoadFromFile(@TempDir & "\test.png")


      $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
      
      _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
      
      _GDIPlus_GraphicsDispose($hGraphic)
      
      _GDIPlus_ImageDispose($hImage)
      
      _GDIPlus_Shutdown()
   
      $hDownload = InetGet($hWGoose, @TempDir & "\test.png", 1, 1)
      
      
   EndIf
   
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Edited by Jon
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...