Hi Monks!

I'm currently working on a project for one of my university class. It's a temperature logger between 2 microcontroller through RF. The MASTER device sends its temp to the SLAVE device which tags a timestamp to it and sends this datastream to the PC through Serialport. Each sec I send a stream like this: Temperature: tempval Time: hh:mm:ss

Now i have to write the PC-side application, but the problem is that we had only few lesson in Perl programming and we mainly focused to the basics and Perl/tk.

The main goal is to make graphs from the data what i get from the serialport. I want to bound the port opening/closing to buttons, but when i do this it's starting read the previously chosen port and then the GUI freeze out. I know it's because i use a while()-loop for reading the serialport which run up against Mainloop();. I read about 'threads' and 'repeat' and that they can solve my problem, but it's not clear how to use them,and how can i pass data from a thread to the Tk where i could use it for displaying/editing etc.

sub opening_port { print "Connecting to $ports[$portname]..."."\n"; $serial->baudrate(9600) || die "Bad baudrate"; $serial->parity('none') || die "Bad parity"; $serial->databits(8) || die "Bad databits"; $serial->stopbits(1) || die "Bad stopbits"; #$serial->buffers(4096,4096) || die "Buffer error"; $serial->handshake("none") || die "Bad handshake method"; $serial->write_settings; #print $serial."\n"; while($port_opened) { my @array; my $string; my $i=0; do { $string=$serial->read(1); if((ord($string) >= 0x09 && ord($string) <=0x7A) || $string eq '\t' + || $string eq '\n') { $array[$i]=$string; $i++; } }while($string ne "\n" ); $i=0; $string = join( '' , @array ) ; chomp($string); my @values = split('\t',$string); print $values[3]; } close($serial); }

Open - button runs the

sub open_port { if($listbox1->curselection) { $portname=$listbox1->index($listbox1->curselection()); $port_opened=1; &port_init; } else { &portwarning; }

In port_init subroutine i just checking the os system and calling the required SerilPort modul and sub opening_port

Buttons for the serailport routine

$btn1=$mw->Button(-text=>"Open",-width=>5,-height=>2,-command=>\&open_ +port) ->place(-relx=>0.05,-rely=>0.25); $btn2=$mw->Button(-text=>"Close",-width=>5,-height=>2,-command=>\&clos +e_port) ->place(-relx=>0.15,-rely=>0.25);
Hope you can help me out! ps.:Sorry for my English

In reply to Perl/Tk vs Win32::SerialPort by Shaoboy

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.