Hi everybody,

I'm trying to send the sensor data to my computer since I want to plot it in a real-time application developed in Matlab.

I've already checked the example "StreamSensorDataOverUsb" shown in the Workbench 3.4.0. However, I'm not sure if this is the best way to do so since I also want the XDK to read and write to the serial port.

On the other hand, I guess my best alternative is to use the UART example that is in the Workbench. This includes fuctions to read and write to the serial port, but when running it- I haven't modified this at all- , I got an error in either in the Workbench or in Matlab. The reason is the serial port is being used by either of the softwares.

I found several comments here related to UART communication: https://xdk.bosch-connectivity.com/ko_KR/community/-/message_boards/message/358180

How can I address this problem?

Is there another option to address what I plan to do?

Thanks in advance!

0 (0 Votes)
RE: Serial communication to Matlab (UART or USB))
Answer
10/1/18 3:01 PM as a reply to Bruno Rodriguez.
Hello Bruno,

welcome to the XDK community!

In regards to connecting the XDK to Matlab, it depends which kinds on interfaces are available on the Matlab side for USB and UART and also how the respective sending format should look on the XDK side.

In regards to USB, if you are sending data over USB, then the XDK-Workbench blocks the used COM port and gathers the incoming data. In that regard, you simply need to disable this blocking in the XDK-Workbench, by clicking on the COM button in the XDK Devices View .

Writing to the COM port should be possible, but please note, for writing customized commands to the XDK, the handling of these needs to be implemented in the XDK application. Otherwise, the commands will not be recognized by the XDK.

It might require an additional application, such as a python script, which acts as a gateway and forwards the incoming data from the XDK to Matlab with the required configuration.

In regards to UART, could you go more into detail about how you connected the XDK over UART with your notebook/personal computer?

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: Serial communication to Matlab (UART or USB))
Answer
10/1/18 4:04 PM as a reply to Franjo Stjepandic.

Hi Franjo,

Thanks for your reply.

With regard to USB, can I read the serial port and print on it at the same time?

I guess you've seen that Arduino can print data on the serial port and this can be read at the same time by another software, e.g. Matlab. This is what I want.

With respect to  the UART example, I saw the following fuctions:

ExtensionUartExample_Read and ExtensionUartExample_Write. Can I use these functions to read/write in the serial port?  I want to send data, let's say, as '%d, %d,%d'.

Thanks

 

0 (0 Votes)
RE: Serial communication to Matlab (UART or USB))
Answer
10/4/18 7:07 AM as a reply to Bruno Rodriguez.
Hello Bruno,

yes, the methodology at serial communication via USB is basically the same for the XDK like it is with the Arduino.

Of course one device can not write and read the serial port at the same time, but with two devices, one device can send and the other one can read.

The USB (Universal Serial Bus) guide gives a great explanation and a deeper view into the serial communication with the XDK, using USB.

To access this guide, a free registration as knowledge base user is required. Follow up this step by a click on the top menu button KNOWLEDGE BASE . On the left menu, choose Protocols and USB .

The guide itself shows several methods to send data via USB, using the serial communication.

If you choose UART, I would rather choose the function SendUartResponseData , instead of ExtensionUartExample_Write to send your data. This saves a few lines of code, due to the retcode handling within the function, instead of a returning retcode, which is supposed to be checked outside the function.

Both functions require the same write buffer. If this buffer is created correct, the sending process should work.

I am sure, you will choose the method (USB/UART), which fits best for you.

If I had the choice, I would start with USB serial communication, especially if you have experiences with similar scenarios using Arduino.

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

Kind regards,
Franjo
+1 (1 Vote)
RE: Serial communication to Matlab (UART or USB))
Answer
10/11/18 3:20 PM as a reply to Franjo Stjepandic.

Hi Franjo,

Thanks a lot for your useful pieces of advices.

I'll have a look at what you said and let you know if it works.  Sorry for the late reply.

Ragards,

 

 

0 (0 Votes)
RE: Serial communication to Matlab (UART or USB))
Answer
10/12/18 2:46 PM as a reply to Bruno Rodriguez.
Hello Bruno,

you are welcome.
I wish you the best progress with your project.

If you have any questions, feel free to ask.

Kind regards,
Franjo
0 (0 Votes)
RE: Serial communication to Matlab (UART or USB))
Answer
12/11/18 9:42 AM as a reply to Franjo Stjepandic.

Hi Bruno,

i wanna simulink XDK acceleration data with MATLAB in real-Time like you. and i have some problem in this way....... i'll be really happy to have contact with you to simulink that.

 

Best regards

Sepehr

0 (0 Votes)