icinterface.fopen cannot bind

조회 수: 11 (최근 30일)
Nick
Nick 2014년 3월 7일
답변: Nick 2014년 3월 12일
I want to test a UDP module on a fpga board which should send data to a machine running Matlab through a ethernet cable.
I wrote the following script and test it between two machine running matlab, it works. In short, the script opens a udp object and print to screen each data it receives.
However, when I plug the ethernet cable to the machine and the board, running the script I got an error using icinterface.fopen: "it cannot bind" ( I presume it cannot assign the port or the ip address).
Assuming the worst scenario in which the udp module on the board does not work, I do not see why matlab should not be able to create a udp "listener". Udp do not require any syncronization or reply.
Any idea on what exaclty icinterface.fopen does? Why it cannot associate the port/address?
Here's the main script
ip_listener = '192.168.0.3'; % IP current machine
port_listener = hex2dec('6af0'); % port current machine
ip_source = '192.168.0.1'; % IP board
port_source =hex2dec('6aef'); % port board
nBytes = 5;
udp_listener = udp(ip_source, port_source, ...
'LocalPort', port_listener,'LocalHost', ip_listener);
udp_listener.BytesAvailableFcnCount = nBytes;
udp_listener.DatagramTerminateMode = 'off';
udp_listener.BytesAvailableFcnMode = 'byte';
udp_listener.BytesAvailableFcn = {'showBytes', nBytes};
fopen(udp_listener)
udp_listener.RecordDetail = 'compact';
udp_listener.RecordMode = 'append';
udp_listener.RecordName = [folder '\buffer_bytes.bin'];
record(udp_listener,'on') % save
% to close
% record(udp_listener,'off'); fclose(udp_listener)
which also requires this function
function showBytes(obj, event, n)
transpose(fread(obj,n))

채택된 답변

Nick
Nick 2014년 3월 12일
fopen requires the ethernet port to be physically connected via cable with a POWER ON machine. Doing so, the code runs.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by