Receiving remote data using dsp.UDPReceiver

7 visualizaciones (últimos 30 días)
Martin Rung
Martin Rung el 19 de Feb. de 2024
Respondida: Martin Rung el 23 de Feb. de 2024
I want to control a laboratory instrument via UDP - and receive its response. I can do it using functions from the 'Instrument Control Toolbox' ('udp' and 'udpport'). However, I would rather prefer to do it using the 'DSP System Toolbox' which is much more common among my colleagues.
The 'DSP System Toolbox' offers 'dsp.UDPSender' and 'dsp.UDPReceiver'. Sending using 'dsp.UDPSender' works fine, but I have not succeeded in receivng the response from the instrument via 'dsp.UDPReceiver': I receive only empty data.
This code example shows first the two working methods from 'Instrument Control Toolbox' - and then my attemp using 'DSP System Toolbox' in wich receiving fails:
% Sending via UDP a four byte message to a device at
% IP address "192.168.10.110", IP port 6667
% A two byte response (acknowledge) is returned from the device
msg = uint8([ 1 0 10 11 ]);
%% old method from Instrument Control Toolbox
disp('With udp:')
u = udp('192.168.10.110',6667);
fopen(u)
fwrite(u,msg)
rsp = fread(u,2)
fclose(u)
% The device receives (and reacts) correctly (to) the sent message
% The two byte response is received into rsp
%% new method from Instrument Control Toolbox
pause(1)
disp('With udpport:')
up = udpport;
write(up,msg,"uint8","192.168.10.110",6667);
rsp = read(up,2,"uint8")
clear up
% The device receives (and reacts) correctly (to) the sent message
% The two byte response is received into rsp
%% method from DSP System Toolbox
pause(1)
disp('With UDPSender/UDPReceiver:')
udps = dsp.UDPSender( 'RemoteIPPort',6667,'RemoteIPAddress','192.168.10.110');
udpr = dsp.UDPReceiver('LocalIPPort', 6667,'RemoteIPAddress','192.168.10.110');
setup(udpr)
% rsp = udpr()
udps(msg);
rsp = udpr()
% while isempty(rsp)
% rsp = udpr()
% end
release(udps);
release(udpr);
% The device receives (and reacts) correctly (to) the sent message
% However, the two byte response is NOT received into rsp
% (rsp is empty and remains empty also by subsequent "calls" of udpr)
Calling 'udpr()' before sending as well as repeatedly after (as in the comments in the code example) does not fetch any response.
An update/answer to previous question about 'dspUDPReceiver' claimed that a solution was to run matlab as administrator. It does not help in my case.
I have been suggested it could be a firewall ussue. So I had my IT support to open port 6667 for matlab (I am not authorized to do so myself). It did not help in my case.
Shouldn't 'dsp.UDPSender' and 'dsp.UDPReceiver' be capable of doing the job?
Thanks for any responses!
Martin

Respuesta aceptada

Martin Rung
Martin Rung el 23 de Feb. de 2024
Update:
My understanding now is that the device to control is a UDP server - and 'udp' and 'udpport' are UDP clients (so they can send commands to and receive responses from the device (UDP server)).
'dsp.UDPSender' is a UDP client and so it can send commands.
'dsp.UDPReceiver' is a UDP server and so it cannot receive responses.
Conclusion: 'dsp.UDPSender' and 'dsp.UDPReceiver' can not be used instead of 'udp' or 'udpport'.

Más respuestas (0)

Categorías

Más información sobre Instrument Control Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by