Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Read COM-Port with MathScript

Solved!
Go to solution

Hello, everyone,

 

I'm trying to use MathScript to realize this code

s1=serial('COM3'); %from Matlab

but I can't find the right command in MathScript for COM-Port reading, someone know that?

 

yours

 

Adam

0 Kudos
Message 1 of 6
(4,415 Views)
You can't read a com port in Mathscipt. You didn't even try VISA like you said you would in your other thread.
0 Kudos
Message 2 of 6
(4,411 Views)

i have tried that, believe me, but i have problems with the datamatrix like i said, you can see it in the attachment, somehow i believe i have did it wrong with the fread command, because there is always error.

 

PS:

  fprintf(s1,'isready');                               % 'start' senden
   A=fscanf(s1,'%s')
   A=fscanf(s1,'%s')
   fprintf(s1,'rdatb %04X\n',points-1);                      % Auslesekommando
   pause(0.05);
   A=fscanf(s1,'%s');                                   % read echo
   A=fread(s1,2);
    B=fread(s1,[2 points]);                                % read datamatrix
    C=bitshift(B(1,:),8);
    y2=fliplr(C+B(2,:));

0 Kudos
Message 3 of 6
(4,409 Views)

I'm sorry but you have no data in any of your controls or indicators, no mention of what the error is, and a VI that is extremely badly written. You can fix the first problem by going to the edit menu and selecting Make Current Values Default, saving the VI, and attaching that. The last problem requires you to eliminate all local variables and the stacked sequence structure.

0 Kudos
Message 4 of 6
(4,397 Views)

actually all the data is given in the controls, and they are all made as the default values, and i also connected it with the hardware. And for the sequence structure, i have to do it this way, because i have to make the data flow run like that.

% --- OTDR-Parameter -----------------------------------------------------------   
   points=1008;                          % Anzahl Messpunkte (0 - 16000)
   delay=0;                           % Anzahl Wartepunkte (Start der Messung)
   int_averages=64;                  % Anzahl interne Mittelungen (0 - 255) Vorsicht über 64!
   resolution=0;                     % Abtastrate 0-10ns 1-20ns 2-40ns 3-60ns 4-80ns usw.
   pulsewidth=2;                     % Pulsbreite in 10ns (entspr. 1m in Faser)
   pulsepower=1;                     % Pulsenergie (0 - 255)
   apdgain=1;                         % APD-Verstärkung (0-aus, 1-max, 255-min)
   ampgain=1;                         % gewählte Verstärkerstufe (0,1,2,3)
% ------------------------------------------------------------------------------  


but thank you anyway, i will keep trying and let you know when i success, have a nice weekend.Smiley Happy

0 Kudos
Message 5 of 6
(4,392 Views)
Solution
Accepted by topic author Adamyuan

like Dennis said, it can't be used in MathScript, but see here

http://forums.ni.com/t5/Instrument-Control-GPIB-Serial/how-can-i-use-quot-fscanf-quot-and-quot-fread...

it might be help.

0 Kudos
Message 6 of 6
(4,314 Views)