-
Notifications
You must be signed in to change notification settings - Fork 0
/
zeromq_demo_rev1.m
210 lines (199 loc) · 5.54 KB
/
zeromq_demo_rev1.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
clear all
more off
%% measumrement parameters (in mm) :
dy=0.060
dx=0.0005
xmin=4
xmax=6
ymin=-2.25
ymax=-2.15
% measurement parameters (in mm) : Melvin
%dy=0.001
%dx=0.00025
%xmin=1.39
%xmax=1.42
%ymin=0.94
%ymax=1.01
%%% measurement parameters (in mm) : CMUT Sylvain
%dy=0.1
%dx=0.005
%xmin=-1.5
%xmax=9
%ymin=-7.5
%ymax=-4.5
%% measurement parameters (in mm) : SEAS10
%dy=0.010
%dx=0.00025
%xmin=-1.8
%xmax=0.2
%ymin=-4.0
%ymax=-3.6
%%ymax=-4.5 % antires
%% measurement parameters (in mm) : Vectron 868 MHz
%dy=0.010
%dx=0.00025
%xmin=-8.7
%xmax=-6.6
%ymin=-6.75
%ymax=-6.5
% nothing to edit below this line
rtl=0
b210=1
ONT=0 % demande a la table si elle est arrivee a son but (On Target ?)
total_length=50;
table_delay=0.015; % in second(s)
pkg load zeromq
pkg load instrument-control
if (exist("serial") != 3)
disp("No Serial Support");
endif
s1 = serial("/dev/ttyUSB0"); % Open the port
pause(.1); % Optional wait for device to wake up
set(s1, 'baudrate', 115200); % communication speed
set(s1, 'bytesize', 8); % 5, 6, 7 or 8
set(s1, 'parity', 'n'); % 'n' or 'y'
set(s1, 'stopbits', 1); % 1 or 2
set(s1, 'timeout', 123); % 12.3 Seconds as an example here
% system('./read9600 *IDN?')
% sock = zmq_socket(ZMQ_PULL);
vector=zeros(total_length,1); % case of SUB socket: register all services
p=1;
m=1;
srl_write(s1,"SVO 1 1\n"); pause(0.1);
srl_write(s1,"SVO 2 1\n"); pause(0.1);
%srl_write(s1,"FRF 1\n");pause(0.5); % MUST BE "..." to interpret \n
%srl_write(s1,"FRF 2\n");pause(1.5); % penser a mettre un delai suffisant
printf("done\n");
number=(ymax-ymin)/dy*(xmax-xmin)/dx;
if (rtl==1)
disp(['Expected duration: ',num2str(100e-3*number)]);
else
if (ONT==0)
disp(['Expected duration: ',num2str(25e-3*number)]);
else
disp(['Expected duration: ',num2str(48e-3*number)]);
end
end
% recherche grossiere de la position du dispo
% y=-3.9; chaine=['MOV 1 ',num2str(y),"\n"];srl_write(s1,chaine); % system(chaine)
% x=2.5; chaine=['MOV 2 ',num2str(x),"\n"];srl_write(s1,chaine); % system(chaine)
% pause(0.5)
debut=time;
tic
for y=ymin:2*dy:ymax
chaine=['MOV 1 ',num2str(y),"\n"];srl_write(s1,chaine);
%pause(table_delay)
if (ONT==0) pause(table_delay);end
% for x=xmax:-dx:xmin
for x=xmin:dx:xmax
chaine=['MOV 2 ',num2str(x),"\n"];srl_write(s1,chaine);
%pause(table_delay)
if (ONT==1)
do
chaine=["ONT?\n"];srl_write(s1,chaine);
[chaine,count]=srl_read(s1,9);
until ((chaine(3)=='1') && (chaine(8)=='1'));
else
pause(table_delay);
end
if (b210==1)
sock1 = zmq_socket(ZMQ_SUB); % socket-connect-opt-close = 130 us
zmq_connect (sock1,"tcp://127.0.0.1:5555");
zmq_setsockopt(sock1, ZMQ_SUBSCRIBE, "");
recv=zmq_recv(sock1, total_length*8*2, 0); % *2: interleaved channels
value=typecast(recv,"single complex"); % char -> float
mesure1(m,p)=mean(value(1:length(value)/2));
mesure2(m,p)=mean(value(length(value)/2+1:end));
zmq_close (sock1);
end
if (rtl==1)
sock1 = zmq_socket(ZMQ_SUB); % socket-connect-opt-close = 130 us
zmq_connect (sock1,"tcp://127.0.0.1:6555");
zmq_setsockopt(sock1, ZMQ_SUBSCRIBE, "");
recv=zmq_recv(sock1, total_length*8*2, 0);
value=typecast(recv,"single complex"); % char -> float
mesure_rtl1(m,p)=mean(value(1:length(value)/2));
mesure_rtl2(m,p)=mean(value(length(value)/2+1:end));
zmq_close (sock1);
end
p=p+1;
end
toc
% repeat the same sequence but backward
m=m+1
p=p-1
chaine=['MOV 1 ',num2str(y+dy),"\n"];srl_write(s1,chaine);
% pause(table_delay)
if (ONT==0) pause(table_delay);end
for x=xmax:-dx:xmin
chaine=['MOV 2 ',num2str(x),"\n"];srl_write(s1,chaine);
% pause(table_delay)
if (ONT==1)
do
chaine=["ONT?\n"];srl_write(s1,chaine);
[chaine,count]=srl_read(s1,9);
until ((chaine(3)=='1') && (chaine(8)=='1'));
else
pause(table_delay);
end
if (b210==1)
sock1 = zmq_socket(ZMQ_SUB); % socket-connect-opt-close = 130 us
zmq_connect (sock1,"tcp://127.0.0.1:5555");
zmq_setsockopt(sock1, ZMQ_SUBSCRIBE, "");
recv=zmq_recv(sock1, total_length*8*2, 0); % *2: interleaved channels
value=typecast(recv,"single complex"); % char -> float
mesure1(m,p)=mean(value(1:length(value)/2));
mesure2(m,p)=mean(value(length(value)/2+1:end));
zmq_close (sock1);
end
if (rtl==1)
sock1 = zmq_socket(ZMQ_SUB); % socket-connect-opt-close = 130 us
zmq_connect (sock1,"tcp://127.0.0.1:6555");
zmq_setsockopt(sock1, ZMQ_SUBSCRIBE, "");
recv=zmq_recv(sock1, total_length*8*2, 0);
value=typecast(recv,"single complex"); % char -> float
mesure_rtl1(m,p)=mean(value(1:length(value)/2));
mesure_rtl2(m,p)=mean(value(length(value)/2+1:end));
zmq_close (sock1);
end
p=p-1;
end
p=p+1
m=m+1
if (b210==1)
subplot(221)
imagesc(20*log10(abs(mesure2)));colorbar
title('amplitude')
subplot(223)
imagesc(angle(mesure2));colorbar
title('phase')
subplot(222)
imagesc(20*log10(real(mesure1)));colorbar
title('sideband')
subplot(224)
imagesc(20*log10(imag(mesure1)));colorbar
title('carrier')
end
pause(table_delay)
% if (rtl==1)
% imagesc(real(mesure_rtl2))
% end
end
toc
fin=time;
clear s1 sock1
save tout.mat
(fin-debut)/number
subplot(221)
imagesc(20*log10(abs(mesure2)));colorbar
title('amplitude')
subplot(223)
imagesc(angle(mesure2));colorbar
title('phase')
subplot(222)
imagesc(20*log10(real(mesure1)));colorbar
title('sideband')
subplot(224)
imagesc(20*log10(imag(mesure1)));colorbar
title('carrier')
print -depsc tout.eps