UDP writing/reading data?
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I am currently working on such a system:
- Windows PC with MATLAB/Simulink;
- Real-Time Linux system, where the compiled model of Simulink is uploaded and running every time;
- 5DOF robotic arm.
Between Windows PC and RTL there is an Ethernet cable, which allows communication through UDP protocol.
I am able to read the data from the robot on the Windows PC, using the following settings:
rhost = '10.1.64.97'; %this is RTL IP address
rport = 26000; %this port is on RTL
localPort = 1597; %this port is on WIN
echoudp('on', rport);
u = udp(rhost, rport, 'LocalPort', 'localPort');
fopen(u)
A = fread(u, 19, 'double'); % this is because I have 152 bytes I have to read, so 19 * 8 = 152
But now I would like to write the data, from the Windows PC to the robot (or to the RTL system first), and I don't know which ports to use as remote or local, nor which IP address I should use as rhost. Since I will use the function fwrite, I am guessing it could be something like this:
rhost = '10.1.64.97'; %this is RTL IP address
rport = 4012; %this port is on RTL
localPort = 2103; %this port is on WIN
echoudp('on', rport);
u = udp(rhost, rport, 'LocalPort', 'localPort');
fopen(u)
Data = zeros(25,1); % I need to send 200 bytes; 25 * 8 = 200
fwrite(u, Data, 'double');
However, this doesn't work, because if I close the u object and try to read out the data, it won't match (I added some constants to check if they eventually become zero, as I would expect them to).
Do you have any suggestions, or perhaps maybe just a good explanation WHAT is the remote host/port and what is the local host/port in my case??
Thank you!!
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!