winforms - Visual C# Windows Form Textbox Not Auto-updating -


i'm attempting code application reads in values imu. i'm trying different values of attitude (i.e. direction) of imu 1 second when using getatr_click method. however, while calling get_attitude function, changes textbox values once on form. how make change each time? (i want see 10 different values flash on textbox).

here's code:

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; using system.threading; using system.timers; using vectornav.devices;  namespace windowsformsapplication1 { public partial class form1 : form {     public static vn100 vn100 = new vn100("com5", 9600);     // new vn100 on com5      private void get_attitude()         //gets current yaw, pitch, roll in degrees, , displays     {         var attitude = vn100.currentattitude;         yaw.text = convert.tostring(attitude.ypr.yawindegs);         pitch.text = convert.tostring(attitude.ypr.pitchindegs);         roll.text = convert.tostring(attitude.ypr.rollindegs);     }     public form1()         //connect vn100, set output ypr, output @ 10hz     {         initializecomponent();         vn100.connect();         vn100.setasyncdataoutputtype(vn100.asyncoutputtype.ypr, true);         vn100.setasyncdataoutputfreq(10, true);     }      private void form1_load(object sender, eventargs e)     {         get_attitude();     }      private void tare_click(object sender, eventargs e)     {         vn100.tare(true);         vn100.tare(true); //for reason doesn't display correct attitude     values w/out double tare         get_attitude();     }      private void getatr_click(object sender, eventargs e)     {         (int = 1; <= 10; i++)         {             while (vn100.currentattitude == null)                 thread.sleep(10);             get_attitude();         }     }      protected override void onformclosing(formclosingeventargs e)         //disconnect vn100 when box closed     {         vn100.disconnect();         base.onformclosing(e);     }      } } 

do want see 10 (possibly) different values displayed in textboxes during 1s, @ interval of 10ms, once call getattr_click()?

if yes, way it:

private void getatr_click(object sender, eventargs e) {     (int = 1; <= 10; i++)     {         while (vn100.currentattitude == null)             thread.sleep(10);         get_attitude();          thread.sleep(10);     } } 

in version, thread called getattr_click() method checks vn100.currentattutude @ 10ms intervals. once has non-null value, suspect remains non-null, meaning while() loop skipped in every for() iteration get_attitude() called 10 times in row (probably) fast see last values on screen.

thing is, keep ui unresponsive each 10ms during click, might consider calling getatr_click() asynchronously or other trivial solution.

edit: actually, knowing behaviour of vn100 component. in case unpredictable, thing can sure of displaying 10 different values @ no less 10ms distance in time, regardless if on ui thread or on different thread. related vn100.currentattitude behaviour...


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -