in reply to Perl/Tk vs Win32::SerialPort
The basic idea, is to set a textvariable $input which automatically gets updated from the repeater.
use warnings; use strict; use Tk; use Device::SerialPort; #my $serial_port = "/dev/ttyS0"; my $serial_port = new Device::SerialPort ("/dev/ttyS0") || die "can't open COM1\n"; #Setup Perl/Tk my $mw = MainWindow->new(); $mw->title("Scale"); #Close button my $button = $mw->Button( -text => 'Close', -command => sub {$mw->destroy} # exit is better here )->pack( -pady => 20, -side => 'bottom' ); my $title_label = $mw->Label( -text => "Weigh-Tronix" )->pack( -side => 'left'); my $input = '---------------'; my $display_label = $mw->Label( -textvariable => \$input, -width=>15, #keep the width stable at 15 )->pack( -side => 'left'); # every 10 millisecs update from port $mw->repeat(10, sub{ # $input = $port->input; #or maybe better if(defined $port->input){ $input = $port->input } }); MainLoop; __END__
|
|---|