Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

153 wiersze
4.0KB

  1. classdef Channel
  2. %CHANNEL Summary of this class goes here
  3. % Detailed explanation goes here
  4. properties (Hidden, Access = private)
  5. scope
  6. channelnumber
  7. end
  8. properties (Dependent)
  9. state
  10. coupling
  11. bandwidth
  12. scale
  13. offset
  14. probe
  15. label
  16. type
  17. end
  18. methods
  19. function ch = Channel(scope,channelnumber)
  20. ch.channelnumber = channelnumber;
  21. ch.scope = scope;
  22. end
  23. function s = get.state(ch)
  24. s = ch.CHAN('state?');
  25. end
  26. function out = get.coupling(ch)
  27. out = ch.CHAN('coup?');
  28. end
  29. function out = get.bandwidth(ch)
  30. out = ch.CHAN('band?');
  31. end
  32. function out = get.offset(ch)
  33. out = ch.CHAN('offs?');
  34. end
  35. function out = get.scale(ch)
  36. out = ch.CHAN('scal?');
  37. end
  38. function out = get.label(ch)
  39. out = ch.CHAN('lab?');
  40. end
  41. function out = get.type(ch)
  42. out = ch.CHAN('type?');
  43. end
  44. function ch = set.state(ch,in)
  45. ch.CHAN('state',in);
  46. end
  47. function ch = set.coupling(ch,in)
  48. ch.CHAN('coup',in);
  49. end
  50. function ch = set.bandwidth(ch,in)
  51. ch.CHAN('band',in);
  52. end
  53. function ch = set.offset(ch,in)
  54. ch.CHAN('offs',in);
  55. end
  56. function ch = set.scale(ch,in)
  57. ch.CHAN('scal',in);
  58. end
  59. function ch = set.label(ch,in)
  60. ch.CHAN('lab',in);
  61. end
  62. function ch = set.type(ch,in)
  63. ch.CHAN('type',in);
  64. end
  65. function out = frequency(ch)
  66. out = str2double(ch.MEAS('freq'));
  67. end
  68. function out = peak2peak(ch)
  69. out = str2double(ch.MEAS('peak'));
  70. end
  71. function out = period(ch)
  72. out = str2double(ch.MEAS('per'));
  73. end
  74. function out = amplitude(ch)
  75. out = str2double(ch.MEAS('ampl'));
  76. end
  77. function out = mean(ch)
  78. out = str2double(ch.MEAS('mean'));
  79. end
  80. function out = rms(ch)
  81. out = str2double(ch.MEAS('rms'));
  82. end
  83. function out = phase(ch)
  84. out = str2double(ch.MEAS('phas'));
  85. end
  86. function data = waveform(ch,window)
  87. ch.scope.single;
  88. if nargin < 2
  89. window = 'DEF';
  90. end
  91. ch.scope.setWaveformSettings(window,'REAL')
  92. data = ch.getWaveform;
  93. end
  94. function data = getWaveform(ch)
  95. header = str2num(ch.CHAN('DATA:HEAD?'));
  96. data.length = header(3);
  97. data.start = header(1);
  98. data.stop = header(2);
  99. data.sampletime = str2double(ch.CHAN('DATA:XINC?'));
  100. ch.scope.opc;
  101. ch.scope.write_unsafe(['CHAN',num2str(ch.channelnumber),':DATA?']);
  102. data.data = ch.scope.readWaveform(data.length);
  103. end
  104. end
  105. methods (Hidden, Access = private)
  106. function c = CHAN(ch,string,in)
  107. if nargin == 2
  108. if strcmp(string(end),'?')
  109. c = ch.scope.query(['CHAN',num2str(ch.channelnumber),':',string]);
  110. else
  111. ch.scope.write(['CHAN',num2str(ch.channelnumber),':',string]);
  112. end
  113. else
  114. ch.scope.write(['CHAN',num2str(ch.channelnumber),':',string,' ',in]);
  115. end
  116. end
  117. function c = MEAS(ch,string)
  118. c = ch.scope.query(['MEAS',num2str(ch.channelnumber),':RES:ACT?',string]);
  119. end
  120. % function c = CHANsend(ch,string,in)
  121. % c = ['CHAN',num2str(ch.channelnumber),':',string,' ',in];
  122. % end
  123. end
  124. end