%This script help to communicate with NP30 Iskra and read data from it
%remotely. Typical settings are:
%       baudrate 9600 %Is setted by P7 parameter
%       1 stop bit
%       no parity
%       8 data bits
%       harware control none

%Open serial port:
serialOne=serial('COM10', 'BaudRate', 9600);
fopen(serialOne);
%Transactions begins by sending 2 or 8 ansii character to NP30. Both of
%them give same data, but in different order.
fprintf(serialOne,2)%
s=fscanf(serialOne);%Number of datum point
s2=fscanf(serialOne);%position; measurment unit; mode of measurment; halfing function
s3=fscanf(serialOne);
s4=fscanf(serialOne);
disp([s  s2  s3 s4])

%8 request give save data, but in other way
% fprintf(serialOne,8)
% fscanf(serialOne);
% s5=fscanf(serialOne);%
% disp(s5)

%Convert XYZ position to numbers
%%%%%%%%
Xstr=strsplit(s2);
Xpos=cell2mat(Xstr(4))
Ystr=strsplit(s3);
Ypos=cell2mat(Ystr(4))
Zstr=strsplit(s4);
Zpos=cell2mat(Zstr(4))
%%%%%%%%

%Close communication
fclose(serialOne);
delete(serialOne);
clear serialOne