Shaoboy has asked for the wisdom of the Perl Monks concerning the following question:
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
Hope you can help me out! ps.:Sorry for my English$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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl/Tk vs Win32::SerialPort
by Anonymous Monk on Dec 10, 2013 at 03:25 UTC | |
|
Re: Perl/Tk vs Win32::SerialPort
by zentara (Cardinal) on Dec 10, 2013 at 14:34 UTC | |
|
Re: Perl/Tk vs Win32::SerialPort
by Shaoboy (Initiate) on Dec 10, 2013 at 16:53 UTC | |
by Shaoboy (Initiate) on Dec 10, 2013 at 17:50 UTC | |
by Shaoboy (Initiate) on Dec 10, 2013 at 20:25 UTC | |
by Anonymous Monk on Dec 10, 2013 at 22:40 UTC |