Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

154 рядки
4.1KB

  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)
  87. ch.scope.clear;
  88. ch.CHAN('TYPE HRES');
  89. ch.scope.write('FORM REAL');
  90. ch.scope.write('FORM:BORD MSBF');
  91. ch.CHAN('DATA:POIN DMAX');
  92. ch.scope.single;
  93. header = str2num(ch.CHAN('DATA:HEAD?'));
  94. data.length = header(3);
  95. data.start = header(1);
  96. data.stop = header(2);
  97. data.sampletime = ch.CHAN('DATA:XINC?');
  98. ch.scope.opc;
  99. ch.scope.write_unsafe(['CHAN',num2str(ch.channelnumber),':DATA?']);
  100. prefixstring = fscanf(ch.scope.tcp,'%c',2);
  101. prefixlength = str2double(prefixstring(2));
  102. datalength = fscanf(ch.scope.tcp,'%c',prefixlength);
  103. data.wave = fread(ch.scope.tcp,data.length,'float');
  104. flushinput(ch.scope.tcp);
  105. end
  106. end
  107. methods (Hidden, Access = private)
  108. function c = CHAN(ch,string,in)
  109. if nargin == 2
  110. if strcmp(string(end),'?')
  111. c = ch.scope.query(['CHAN',num2str(ch.channelnumber),':',string]);
  112. else
  113. ch.scope.write(['CHAN',num2str(ch.channelnumber),':',string]);
  114. end
  115. else
  116. ch.scope.write(['CHAN',num2str(ch.channelnumber),':',string,' ',in]);
  117. end
  118. end
  119. function c = MEAS(ch,string)
  120. c = ch.scope.query(['MEAS',num2str(ch.channelnumber),':RES:ACT?',string]);
  121. end
  122. % function c = CHANsend(ch,string,in)
  123. % c = ['CHAN',num2str(ch.channelnumber),':',string,' ',in];
  124. % end
  125. end
  126. end