use strict; use warnings; use Tk; use Win32::SerialPort; require Tk::Balloon; my $port = Win32::SerialPort->new("COM7") or die "Open Port Failed. $!\n"; $port->is_rs232; # SET UP THE SERIAL PORT 9600, 81N ON THE USB FTDI DRIVER $port->initialize(); $port->baudrate(9600); $port->databits(8); $port->parity("none"); $port->stopbits(1); $port->write_settings || undef $port; sleep(3); my $mw = MainWindow->new(); $mw->geometry('1020x550+180+600'); $mw->configure(-title => 'TEST'); my $balloon = $mw->Balloon(); my $buffer3 = $mw->Frame; $buffer3->pack(-side => 'left', -padx => 31, -anchor => 'nw'); my $frame3 = $mw->Frame; $frame3->pack(-side => 'left', -anchor => 'nw'); my $sig4 = $frame3->Button(-activebackground => 'red', -activeforeground => 'black', -text, 'TEST ALL ASPECTS', -anchor => 'w', -command => sub{print STDOUT " Test All Aspects\n"; &testall_aspects}); $sig4->pack(-side => 'top', -fill => 'both', -anchor => 'w'); $sig4->configure(-background => "gray", -foreground => "black"); $balloon->attach($sig4, -balloonmsg => "Test All Aspects"); MainLoop; sub testall_aspects { no warnings 'uninitialized'; $signalblock100->configure(-image => $mw->Photo(-file => 'testall-yellow-signal.gif')); $sig1->configure(-background => "green", -foreground => "black"); my $testall = "t"; # THIS CODE GETS SENT TO THE ARDUINO $port->write($testall); $port->lookclear; while(1) { my $data = $port->lookfor(); if ($data) { print STDOUT "$time Signal Driver Message Received: (" . $data . ")\n"; } if ($data =~ /ON/) { print STDOUT "Message Received: (" . $data . ")\n"; return; } if ($data =~ /OF/) { print STDOUT "Message Received: (" . $data . ")\n"; $signalblock100->configure(-image => $mw->Photo(-file => 'noaspect-yellow-signal.gif')); } } }