Good Afternoon Monks!
My question relates to the Win32-SerialPort module and an Arduino and here is my question and code below:
1.) Sending Data to and from the Arduino is not an issue.
2.) When data is received from the Arduino and is read by the Perl script the first action takes place which lights up the LEDs on the Arduino Board and shades a button on my Perl/Tk script.
3.) The problem is when the lights on the Arduino go off it sends a command via the serial port and the Perl Script is suppose to read that data and the button is no longer shaded.
However, this is not being done. I have confirmed the command gets sent by the Arduino and I can verify this by using the Arduinos serial monitor. I believe the problem lies when trying to read the data from when the lights go off and that is where I am stuck. Thanks in advance!
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', -activeforegrou
+nd => '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-yell
+ow-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-yel
+low-signal.gif'));
}
}
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.