Unfortunately, my Zaurus likes to go to sleep rather quickly. So when trying to copy over a new file that I just downloaded, more often than not the network connection is already gone. That's why I decided to have a little utility to monitor the status by pinging the Zaurus every second. Of course, it can be used to monitor any host (if it's not in your local network, you should set the timeout higher).

This is a bit of a hack, and only works because Win32::GUI has a "feature" that allows you to delete notifyicons by adding another icon with the same data. If anyone knows a more elegant solution, please do tell me about it. I'd also like to be able to embed the icons as data, rather reading them from external files. (You can download my somewhat boring icons if you like.)

#!/usr/bin/perl # 2003/03/15, 2003/04/02 crenz@web42.com # display icon indicating whether zaurus is alive # only works due to weird Win32::GUI behaviour -- a notifyicon # will be deleted if another one with the same text and id is # created use strict; use warnings; use vars qw(*Timer_Timer *DeadIcon_Click *DeadIcon_RightClick *AliveIcon_Click *AliveIcon_RightClick); use Win32::GUI; use Net::Ping; # or use Win32::PingICMP my $hostname = $ARGV[0] || 'zaurus'; # or use '192.168.3.2' my $timer_itvl = 1000; my $off = Win32::GUI::Icon->new("zaurus_off.ico"); my $on = Win32::GUI::Icon->new("zaurus_on.ico"); my $frame; my $isAlive = 0; my $iconID = 0; # low timeout, since we're in "local network" (USB connection) my $p = Net::Ping->new("icmp", .2); sub isAliveOrDead { $p->ping($hostname); # for testing: -r 'c:\projects\z.txt'; } sub sayDead { $frame->AddNotifyIcon( -icon => $off, -id => $iconID, -name => 'DeadIcon', -tip => "$hostname Is Dead"); $isAlive = 0; } sub sayAlive { $frame->AddNotifyIcon( -icon => $on, -id => $iconID, -name => 'AliveIcon', -tip => "$hostname Is Alive"); $isAlive = 1; } sub toggle { if ($isAlive) { sayAlive; $iconID++; sayDead; } else { sayDead; $iconID++; sayAlive; } } sub check { toggle if $isAlive != isAliveOrDead; } sub quit { -1; } $frame = Win32::GUI::Window->new( -name => 'Main', -title => 'ZaurusAlive', -width => 100, -height => 100); sayDead; check; $frame->AddTimer("Timer", $timer_itvl); *Timer_Timer = \✓ # force check on click; alternatively set to \&toggle for debugging *DeadIcon_Click = \✓ *AliveIcon_Click = \✓ *DeadIcon_RightClick = \&quit; *AliveIcon_RightClick = \&quit; # note that the frame is never shown -- we only want the icon Win32::GUI::Dialog;

In reply to Host status icon (Win32) by crenz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.