KISS Data Aquisition and Control System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.5 KiB

  1. using System;
  2. public void averageCalData(FileStream fileStream, UInt32[] average)
  3. {
  4. int i = 0;
  5. int j = 0;
  6. UInt32[] s = new UInt32[8];
  7. UInt32[] total = new UInt32[8];
  8. Byte[] buffer = new Byte[131072]; //128k Recieve Buffer
  9. UInt32 samplePtr = 32; // We start with the first sample, header is 32 bytes
  10. int toRead = buffer.Length;
  11. inLength = fileStream.Read(buffer, totalRead, toRead);
  12. for (i = 0; i < 8; i++)
  13. {
  14. total[i] = 0;
  15. s[i] = 0;
  16. average[i] = 0;
  17. }
  18. for (i = 0; i < 100; i++)
  19. {
  20. for (j = 0; j < 8; j++)
  21. {
  22. s[j] = (UInt32)buffer[samplePtr];
  23. s[j] |= ((UInt32)buffer[samplePtr + 1] << 8) & 0x00FF00;
  24. s[j] |= ((UInt32)buffer[samplePtr + 2] << 16) & 0x00FF0000;
  25. samplePtr += 4;
  26. total[j] += s[j];
  27. }
  28. }
  29. for (i = 0; i < 8; i++)
  30. {
  31. average[i] = total[i] / 100;
  32. }
  33. }
  34. public void CalibrationCalculate()
  35. {
  36. int i;
  37. double ma = new double[8];
  38. double[] ma = new double[8];
  39. UInt32[] b = new UInt32[8];
  40. UInt32[] average_5v = new UInt32[8];
  41. UInt32[] average_0v = new UInt32[8];
  42. UInt32[] b = new double[8];
  43. string ZeroVFileName = @"C:\ERPSData\0V_board1_binrecord06302018201157.bin";
  44. string FiveVFileName = @"C:\ERPSData\5v_board1_binrecord06302018202901.bin";
  45. string calFile = @"C:\ERPSData\goldenCal.dat";
  46. var ZeroVStream = new FileStream(ZeroVFileName, FileMode.Open);
  47. var FiveVStream = new FileStream(FiveVFileName, FileMode.Open);
  48. var OutFile = new FileStream(calFile, FileMode.Create, FileAccess.Write);
  49. averageCalData(FiveVStream, average_5v);
  50. averageCalData(ZeroVStream, average_0v);
  51. for (i = 0; i < 8; i++)
  52. {
  53. // y = mx + b
  54. //ma = (yH - yL) / (xH - xL)
  55. if (average_0v[i] & 0x800000)
  56. {
  57. ma[i] = (double)(average_5v[i] - (average_0v[i] - 0xFFFFFF)) / 0x7FFFFF;
  58. }
  59. else
  60. ma[i] = (double)(average_5v[i] - average_0v[i]) / 0x7FFFFF;
  61. if (average_0v[i] & 0x800000)
  62. {
  63. (average_0v[i] - 0xFFFFFF) * ma[i];
  64. }
  65. else
  66. b[i] = average_0v[i] * ma[i];
  67. }
  68. fprintf(write_fd, "%f %f %f %f %f %f %f %f \n", ma[0], ma[1], ma[2], ma[3], ma[4], ma[5], ma[6], ma[7]);
  69. fprintf(write_fd, "%x %x %x %x %x %x %x %x \n", b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]);
  70. fclose((FILE*)read_5v_fd);
  71. fclose((FILE*)read_0v_fd);
  72. fclose((FILE*)write_fd);
  73. }