c# - Turning Textbox Red with a timer when serial port stops outputting data -


i building gui reads in serial data textbox. if there problem , instrument stops working, want textbox turn red. trying timer, timer read data every 30 seconds, if there no data, timer turn textbox red. however, nothing happens when unplug instrument. how can turn textbox red when instrument stops working?

here relevant code:

        private void timer1_tick(object sender, eventargs e)     {         datetime timenow = datetime.now;         timespan span = gpslastdatatime - timenow;         timespan = convert.todouble(span.totalseconds);          if (timespan > 30)         {             textbox1.backcolor = color.red;          }     } 

i assume "gpslastdatatime" set whenever data comes in?

as is, "timespan" value going negative.

switch order of subtraction line:

timespan span = timenow - gpslastdatatime; 

by way, in 1 line this:

timespan = (datetime.now - gpslastdatatime).totalseconds; 

Comments

Popular posts from this blog

xslt - Substring before throwing error -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -