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')); } } }

In reply to Serial Port by PilotinControl

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.