Hello! I want to ask you a question.It's for you maybe easy.But ,As I'm a new learner of perl,it's too difficult.I'm writing a code ,which can read serialport message to a GUI window builded by Tk in Linux.While,I can't let the serialport message report in the Tk window,but in the Linux commond box. so,how can I modify it ,so that it can report in the Tk window. this is my code #!/usr/bin/perl -w # black magic taken from examples that came with the distribution BEGIN { $| = 1; print "varianlog loaded "; } END {print "not ok 1\n" unless $loaded;} use Device::SerialPort; use Tk; $loaded = 1; print "ok 1\n"; # end of black magic use strict; my $file = "/dev/ttyS0"; my $out; my $gotit; my $ob = Device::SerialPort->new($file) || die("Can't open $file: $!\n"); $ob->baudrate(9600) || die("can't set baudrate\n"); $ob->parity("none") || die("can't set parity\n"); $ob->databits(8) || die("can't set databits\n"); $ob->stopbits(1) || die("can't set stopbits\n"); $ob->handshake("none") || die("can't set handshake\n"); $ob->write_settings || die("settings failed\n"); $ob->are_match("\r"); $ob->lookclear; $out="hello word!" x 5; $ob->write($out) || die("writing to serial port failed: $!\n"); $ob->write_drain; $ob->error_msg(1); $ob->user_msg(1); my $mw=MainWindow->new; $mw->geometry("300x260"); $mw->title("GPS message"); my $scroll_text = $mw->Scrollbar(); my $test=$mw->Text( -yscrollcommand => 'set', $scroll_text, -background => 'black', -foreground => 'red' ) ; $test->insert('end',$gotit); $test->see('end'); $scroll_text->configure(-command => 'yview', $test); $scroll_text->pack(-side=>"right", -expand => "no", -fill => "y" ) ; $test->pack(-side => "left", -anchor => "w", -expand => "yes", -fill => "both" ) ; # $thr->detach(); $mw->MainLoop; while (1) { $gotit = $ob->read("10240"); print "$gotit"; #sleep 1; } #print("we have read: $gotit\r\n"); $ob->close || die("failed to close: $!\n"); undef $ob; }

In reply to Re^2: Perl Tk and Threads by dujun
in thread Perl Tk and Threads by Anonymous Monk

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.