c# - Serial output in input Buffer? -


i bashing c# + wpf app send serial data nixie clock.

i having poor performance sending , receiving data using c# app don't have when sending/receiving via terminal program.

in c# app, serial output triggers datareceivedhandler. not echo when using terminal program.

private void datareceivedhandler(object sender, serialdatareceivedeventargs e) {     datetime amoment = datetime.now;       serialport aport = (serialport)sender;        // because updating ui thread other main thread.     this.dispatcher.invoke((action)(() =>     {          string indata = aport.readline();         string outdata = amoment.tostring("yyyy-mm-dd, hh':'mm':'ss.fff, ") + indata + environment.newline;           if (chkenabledatalog.ischecked == true)             file.appendalltext(@txtdatalogpath.text, outdata);          txtserialin.text = indata;         txtdatalogline.text = outdata;          txtserialouthistory.appendtext("<" + indata);          outdata = "";         indata = "";      })); } 

sometimes delay serial response can long - many seconds - using terminal app, response right away.

below screenshot c# app. "<" signifies data received thru datareceivedhandler. other lines outputs. valid response clock "hours?" "hours:nn" nn integer 1::23.

also below, can see terminal program displaying data serial requests expected.

http://imgur.com/a/bjxev

enter image description here

read data first in current thread, call invoke update ui

private void datareceivedhandler(object sender, serialdatareceivedeventargs e) { datetime amoment = datetime.now;

serialport aport = (serialport)sender; string indata = aport.readline(); <<<-- read data before invoke.   // because updating ui thread other main thread. this.dispatcher.invoke((action)((indata ) => {      string outdata = amoment.tostring("yyyy-mm-dd, hh':'mm':'ss.fff, ") + indata + environment.newline;       if (chkenabledatalog.ischecked == true)         file.appendalltext(@txtdatalogpath.text, outdata);      txtserialin.text = indata;     txtdatalogline.text = outdata;      txtserialouthistory.appendtext("<" + indata);      outdata = "";     indata = "";  })); 

}


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -