deadpickle has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use Win32::SerialPort; use Win32::GUI(); my $comport = 1; my @list; #my $comlist; ######################## # Main Loop ######################## my $main = Win32::GUI::Window->new( -name => 'Main', -text => 'Serial Ports', -width => 110, -height => 175, ); my $desk = Win32::GUI::GetDesktopWindow(); my $dw = Win32::GUI::Width($desk); my $dh = Win32::GUI::Height($desk); my $x = $dw / 4 * 3.25; my $y = $dh / 4 * 2.5; $main->Move($x, $y); my $icon = new Win32::GUI::Icon('serialport.ico'); my $ni = $main->AddNotifyIcon( -name => "NI", -icon => $icon, -tip => "SerialPort Finder" ); $main->AddLabel (-text => 'COM Ports Active:'); my $comfield = $main->AddRichEdit( -name => "comfield", -left => 5, -top => 20, -text => "", -width => 100, -height => 100, -readonly => 1 ); $main->AddTimer( "com_list", 1000); Win32::GUI::Dialog(); ######################## # Main Window Subs ######################## sub Main_Terminate { return -1; #$main->Disable(); #$main->Hide(); #return 1; } sub Main_Minimize { $main->Disable(); $main->Hide(); return 1; #return -1; } ######################## # System Tray Events ######################## sub NI_Click { &serial_finder; #&label_create; $main->Enable(); $main->Show(); return 1; } ######################## # Make labels for # found COM ports ######################## sub com_list_Timer { print "entered\n"; &com_list_create; } sub com_list_create { print "running\n"; foreach my $comlist (@list) { print $comlist,"\n"; $comfield->SetFocus(); $comfield->ReplaceSel("COM$comlist",1); $comfield->Select(999999,999999); } } ######################## sub serial_finder { my @list; $comport=1; do { my $port = new Win32::SerialPort("COM$comport"); if (defined ($port)) { push(@list,$comport); $port->close; } $comport++; } while ($comport < 20); foreach my $comlist (@list) { print $comlist,"\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32::GUI COM Port app
by BrowserUk (Patriarch) on Aug 06, 2008 at 00:28 UTC | |
by deadpickle (Pilgrim) on Aug 06, 2008 at 01:29 UTC | |
by BrowserUk (Patriarch) on Aug 06, 2008 at 02:01 UTC |