c# - Associating serial data to a table -


i have serial connection acquires data micro connected j thermocouple. microprocessor sends numeric value 0 1023 proportional measured millivolts. data serial stored in variable "thm1" continuously updated. target calculate temperature reconverting received data , show same in textbox. output of thermocouple not linear , therefore cannot use equation, should read data table gives millivolt/temperture in steps of 5 degrees , integrate received value between 2 closest values.

lets assume 1023 correspond 16,881 mv. have therefore 1023 point each 1 0.01650 mv. receive serial 800 correspond 0,016550 x 800 = 13,2012 mv. looking @ table pyromation.com/downloads/data/emfj_c.pdf , first coloumn on left, value between 240 , 250 degree c. can make linear integration between 2 point. but, how can found 2 points? there better way using long series of if , if else?

please give examples.

you can linear extrapolation :-

public static decimal extrapolatefrom(int f, int s, decimal f1, decimal s2, int value) {                 return (s2-f1)/((s-(decimal)f)/(value-(decimal)f))+f1;          }  public static decimal extrapolatefrom(list<tuple<int, decimal>> table, int value) {     if(table.count < 2) throw  new exception("not enough values extrapolate from");     var result = table.select((x, i) => new { x, }).where(x => x.x.item1 >= value).select(x => x.i).tolist();     var index = result.any()? result.first() : table.count-1;     if (index < 1) index = 1;         return extrapolatefrom(table[index - 1].item1, table[index].item1, table[index - 1].item2,table[index].item2, value); }   private static void main(string[] args) {     var table = new list<tuple<int, decimal>> ()         {             new tuple<int, decimal>(0, 0.0m),             new tuple<int, decimal>(100, 5.0m),             new tuple<int, decimal>(200, 6.0m),             new tuple<int, decimal>(300, 9.0m),             new tuple<int, decimal>(500, 11.0m),         };       console.writeline(extrapolatefrom(table, 50));     console.writeline(extrapolatefrom(table, 400));     console.writeline(extrapolatefrom(table, 600)); } 

the extrapolatefrom takes table :-

  • checks make sure theres @ least 2 cutoffs extrapolate from
  • finds first cutoff in table greater value wanting convert
  • checks if have value greater the table specifies, in case use last 2 cutoffs
  • if have value less table specifies, in case use first 2 cutoffs
  • uses 2 table points linear extrapolation.

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -