PilotinControl has asked for the wisdom of the Perl Monks concerning the following question:
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')); } } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Serial Port
by RichardK (Parson) on Aug 13, 2015 at 10:03 UTC | |
by PilotinControl (Pilgrim) on Aug 13, 2015 at 15:59 UTC | |
by RichardK (Parson) on Aug 13, 2015 at 16:23 UTC | |
by PilotinControl (Pilgrim) on Aug 13, 2015 at 18:35 UTC |