How to receive an array of data from Matlab over usb ?

Technical questions regarding the XTC tools and programming with XMOS.
tom3
Member++
Posts: 16
Joined: Mon Jun 19, 2023 9:32 pm

How to receive an array of data from Matlab over usb ?

Post by tom3 »

Hello

I want to send an array of data (float ) from Matlab over USB.

I already implemented a virtual serial port using the AN00124: USB CDC Class as Virtual Serial Port. It´s working and the virtual port is created. But unfortunately, i don´t know how to send or recieve data over usb and stores them . Note that i managed to send Data from Matlab, the problem is that i don´t know how the procedure to receive them on the xmos.

Has anyone faced the sames issues and can maybe help me ?

Thanks

Regards
Tom


User avatar
Ross
XCore Expert
Posts: 968
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

In that application note the function app_virtual_com() simply loops back anything sent from the host back to the host. So I guess you need to modify this function to handle the data as you wish. I guess modifying it to interpret the data as floats and simply printing them would be a good start?
tom3
Member++
Posts: 16
Joined: Mon Jun 19, 2023 9:32 pm

Post by tom3 »

Hello

Thank you for your answer

Do yo have any idea about how i can do that ? Sorry, i'm not the biggest expert on the subject.
User avatar
Ross
XCore Expert
Posts: 968
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

I would modify the code to build up an array of chars size 4 then use the XC reinterpret cast to reinterpret that array as a float. This example code should help you:

Code: Select all

#include <stdio.h>

int main()
{
    // 0.6 in float
    char test[] = {0x9A, 0x99, 0x19, 0x3F};

    // Re-interpret char array as float
    float x = (test, float);

    printf("%f\n", x);
}
To build:

Code: Select all

$ xcc test.xc -target=XCORE-AI-EXPLORER
To run on the sim:

Code: Select all

$ xsim a.xe
tom3
Member++
Posts: 16
Joined: Mon Jun 19, 2023 9:32 pm

Post by tom3 »

Thank

I'll try and contact you again if i'm having troubles. If you don't mind of course
User avatar
Ross
XCore Expert
Posts: 968
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

Tom, you sent me an email, please post it here. I don't reply to direct messages in general.