Here are a couple of simple scripts to help get you going. The script below just shows a simple thread which can do the stepper control, without blocking the gui. The important point is that the main Tk thread, will not be able to update textvariables automatically from the thread. So you need a timer running, to check the shared vars, and set the textvariables to their values. And as a bonus, here is a link which should show you how to make graphic of the motor position. See Tk compass dial. You could make one with 2 arrows, one for setting the motor, and a second for displaying the feedback position.

Simple thread with feedback:

#!/usr/bin/perl use warnings; use strict; use Tk; use threads; use threads::shared; my $go : shared; my $die : shared; my $step_set : shared; my $feedback : shared; $go = 0; $die = 0; $step_set = 0; $feedback = 0; my $repeater; my $stepper = 0; my $feedback_display = 0; my $thread = threads->new(\&work); my $mw = MainWindow->new( -title => "Stepper Test" ); my $entry = $mw->Entry(-textvariable => \$stepper)->pack(); my $indicator = $mw->Label(-textvariable => \$feedback_display)->pack( +); $mw->Button(-text=>'Start Stepper', -command=> sub { $step_set = $stepper; $go = 1; # timer to read shared vars $repeater = $mw->repeat(10,sub{ $feedback_display = $feedback; if( $feedback_display == $stepper){ $go =0; } }); })->pack(); $mw->Button(-text=>'Exit', -command=> sub { $go = 0; $die = 1; # must return before joining $repeater->cancel; # JOIN ALL THREADS foreach my $thread (threads->list) { $thread->join; + } exit; })->pack(); MainLoop; sub work{ $|++; while(1){ if($die == 1){ return }; if ( $go == 1 ){ for(0..$step_set){ print "$_\n"; $feedback = $_; select(undef,undef,undef,.5); } }else { sleep 1 } } }

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re: How do I pass a reference to another program via @ARGV ??? by zentara
in thread How do I pass a reference to another program via @ARGV ??? by aplonis

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.