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
Post a Comment