Recieve udp data
Answer
11/8/18 4:38 PM

Hello, 

I'm trying to understand the udp-example and read the data in Matlab. In the xdk-code I entered the IP of my computer and the port 55056. If I create a udp object in Matlab with these properties and try "fopen" and "fscanf", I don't get any values. 

Is this a problem with Matlab or am I doing something wrong with the xdk?

Kind regards,
Johannes

0 (0 Votes)
RE: Recieve udp data
Answer
11/9/18 3:49 PM as a reply to Johannes Kaiser.
Dear Johannes,

Please note that you would need to be in the same Wi-Fi network, that the XDK is able to reach your laptop when posing as UDP server.

In regards to your Matlab UDP object, could you please go more into detail, what the functions fopen and fscanf do? Are these manipulating received data or are the requesting data on the XDK side via UDP?

Additionally, please note that Matlab might require a certain sending format, which you need to implement on the XDK side to make the data transfer work.

Please let me know if this was helpful and feel free to ask if you have further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Recieve udp data
Answer
11/15/18 11:44 AM as a reply to Franjo Stjepandic.

Dear Franjo, 

I know, that I need to be in the same Wi-Fi network and I'm sure, I am.

If I create a UDP object with u=udp('RemoteHost', RemotePort), which is my PC's IP and the port 55056, I can connect the object to the host with fopen(u).

According to  mathworks homepage, " A = fscanf(obj) reads data from the instrument connected to obj, and returns it to A. The data is converted to text using the %c format."

I can check, if data is available with u.BytesAvailable, but this is always 0. I dont't know, why that happens. 

Is there an othe way to recieve, display and store the upd-Data from the xdk on my PC?

 

Kind regards,
Johannes

0 (0 Votes)
RE: Recieve udp data
Answer
11/19/18 2:14 PM as a reply to Johannes Kaiser.
Hello Johannes,

the fscanf function you mentioned reads data from a text file.

Since you have no .txt file with sensor data, there is of course an issue with MATLAB's fscanf function and therefore you receive the zero.

Regarding your current setup, you use an UDP client but require an UDP server instead.
Right now, MATLAB acts as the client, while the XDK is the server which simply sends data and does nothing afterwards.
To solve this issue, you need to change the behavior of your setting to an MATLAB server and on the other side to a XDK client.
In order to do this, you could use Python to set up a server and feed it with data. In addition, you would need to implement a logic to safe the data into a .txt/.csv file for the MATLAB fscanf function, in order to read it. Alternatively, you could use the csvread function to read a .csv file.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo
0 (0 Votes)
RE: Recieve udp data
Answer
11/19/18 4:12 PM as a reply to Franjo Stjepandic.

Hello Franjo

the fscanf function can not just read data from a text file but also from an instrument (see this link).

I also tried different settings for my udp object (e. g. like in this example, but with the port 55056).

How do I setup the XDK as a client or why can't I setup the XDK as a server?

 

Kind regards
Johannes

 

0 (0 Votes)
RE: Recieve udp data
Answer
11/20/18 4:26 PM as a reply to Johannes Kaiser.
Hello Johannes,

the XDK has been designed by Bosch as a slave device, not a master device.
Therefore there is no way to set up the XDK as server (master).

In addition to the XDK, could you tell me if you changed parts of the SendDataOverUdp example and if you did, would you provide me the code snippets?

Regarding the fscanf function, the mathworks page also explains this , that the function reads data from an open text file .

By following this link here , you can read, that this function is able to read ASCII data from a device and formats it as text.
The third statement here shows, that this function reads data from an instrument and formats it as text .

Since I am not an expert with MATLAB, could you explain me the differences between the definitions of the fscanf function?
I assume the biggest issue to be within the use of the right implementation of the function.

In addition, I found an example (you need to scroll down the linked page), which talks about the serial port on Windows. This could be another solution.
According to this example, you can use s = serial('COM1'); and fopen(s) to read incoming data on the COM1 port.
I assume, that you could use the same process with your XDK, as well.
To check to which COM port your XDK is connected via USB to, you can hover the connected XDK device within the XDK-Workbench.
If this does not work for you and your machine runs on Windows, you can also check the used COM port within the Device-Manager, by enabling the option to show hidden files and checking for the (COM & LPT) connector.

If you test this setup, please let me know about the result.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo
0 (0 Votes)