LabVIEW Communications System Design Suite

cancel
Showing results for 
Search instead for 
Did you mean: 

Localhost UDP connection between LVCS and Matlab

Solved!
Go to solution

Dear all,

 

I have a question concerning the UDP connection between Matlab and LVCS. My idea is to exchange data between Matlab and Labview on the same computer.

So I found the "Simple UDP" sample project of LVCS 2.0 where periodically a datasample is generated randomly and transmitted to the remoteport 61557 of the localhost. In the project the 'Number to Fractional String for transmitting' is used for transmitting the data. The Receiver part of the sample project reads from the same port to receive the datasample.

 

Now, I am interested to read this simple data stream from Matlab (just as a first step), however, it doesn't work and I am not quite sure why. What I do in Matlab is the following (Matlab code)

 

clear variables;
u = udp('127.0.0.1',61557); % Setup UDP Object
fopen(u); %open to read from port
A = fread(u,1);  % read one element
fclose(u);

 

With this code, however, I get a timeout saying: 'Warning: Unsuccessful read:  The specified amount of data was not returned within the Timeout period.'

I am not quite sure why this happens, maybe you could help me here? I suppose that the formet that is used in LVCS is not the same as in Matlab? Maybe the Terminators are not the same?

 

Cheers,

steve0

0 Kudos
Message 1 of 5
(4,594 Views)

Hi Steve0,

 

I would make sure that you can read and write within each environment before talking between the two. That way you can sort out any syntax errors and ensure that you are actually able to pass data through the port you want.

 

Cheers!

Michael Bilyk
Former NI Software Engineer (IT)
0 Kudos
Message 2 of 5
(4,557 Views)

Hey AgentAstronaut,

 

I already did that. They for their own work properly without any problems. So within LVC I can write and read data and also within Matlab. But not between of them.

 

Best,

steve0

0 Kudos
Message 3 of 5
(4,504 Views)

Hm, can you try running both as an administator or turn off the firewall on your computer? Maybe there is something blocking them from communicating with each other.

 

When you set them up seperately, is their any change to the syntax or configuration you use? I imagine it is probably the same between the two applications but maybe there is a slight difference that can give some insight into the issue.

 

Cheers

Michael Bilyk
Former NI Software Engineer (IT)
0 Kudos
Message 4 of 5
(4,498 Views)
Solution
Accepted by topic author steve0

Hey

 

So concerning the problem I actually found the solution today. It was not the firewall but a simple configuration in Matlab seting up the UDP port. So for the Matlab side you have to change the udp object definition according to

 

u=udp('127.0.0.1', 'LocalPort', 61557);

 

so you have

 

u=udp('127.0.0.1', 'LocalPort', 61557);
fopen(u);

A=fread(u)

fclose(u);
delete(u);

 

That does the trick and you can read from the port. So obviously you have to tell Matlab that you are reading from the 'LocalPort' x, which I was not aware of.

 

For the transmitter side you have simply:

 

u=udp('127.0.0.1', 61557);

fopen(u);

fwrite(u,'1');

fclose(u);
delete(u);

 

Here you just set the transmiting port.

 

Concerning the data format: I used the simple UDP streaming project of Comms where a random number is generated as a double, transformed in a string (ASCII values) and transmitted. At the receiver you correspondingly get the UDP packet with the ASCII values that you have to transform back if you want the number.

 

I hope this helps somebody encountering the same problem.

 

Cheers

Message 5 of 5
(4,225 Views)