leeton I am trying to use the UDP stuff on Bela, but it doesn't work.
You might try this with something like netcat on your remote PC just to see if you can get something to come out of Bela to troubleshoot the basic connectivity issues. This kind of thing can help separate the problems as either
Bela implementation or the MATLAB implementation.
leeton connecting Bela to Matlab via usb serial port
If the amount of data you are sending out of Bela is within USB serial data rates then this is a relatively simple way to this. Assuming what you mean is connecting a USB-to-serial converter to your computer and then connecting the serial to the serial pins on the Bela, then here is some code that communicates with a serial port:
https://github.com/transmogrifox/transmogriFX_bela/blob/master/src/usb_backpack.cpp
https://github.com/transmogrifox/transmogriFX_bela/blob/master/src/usb_backpack.h
Above code reads/writes a USB Serial LCD, but the process is the same setting up any kind of serial port in the Linux environment. I also have some code in which the Bela AuxiliaryTask is used to pass messages from the real-time thread out to the LCD, but it looks like I have not pushed that to github. I can add later if you need it.
Points of interest for basic serial communication are these:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <sys/types.h>
#include <termios.h>
#include <string.h> // needed for memset
// termios stuff
struct termios tio;
char tty_port[256]; //optional
int tty_fd;
Then setup stuff
display_20x4_lcd* make_20x4_lcd(display_20x4_lcd* d, char* port, bool new_lcd, float fs)
{
// "port" is an ASCII string with the port name, for example "/dev/ttyS0"
d = (display_20x4_lcd*) malloc(sizeof(display_20x4_lcd));
memset(&(d->tio),0,sizeof(struct termios));
d->tio.c_iflag=0;
d->tio.c_oflag=0;
d->tio.c_cflag=CS8|CREAD|CLOCAL; // 8n1, see termios.h for more information
d->tio.c_lflag=0;
d->tio.c_cc[VMIN]=1;
d->tio.c_cc[VTIME]=2;
int psz = strlen(port);
for(int i = 0; i < psz; i++)
{
d->tty_port[i] = port[i];
}
d->tty_fd = open(d->tty_port, O_RDWR | O_NONBLOCK);
cfsetospeed(&(d->tio),B115200); // 115200 baud
cfsetispeed(&(d->tio),B115200); // 115200 baud
tcsetattr(d->tty_fd,TCSANOW,&(d->tio));
.
.
.
}
Then to write data out the serial interface:
cmd[] = "some string";
len = strlen(cmd);
// This is a binary write, so you could just as well use an array of integers or floats
// but be careful you get the correct alignment. If low data rates and not a lot information
// text is easy to manage because you don't need to worry about endianness nor byte alignment
write(d->tty_fd, cmd, len); //write 'len' bytes of array cmd[] out to serial port tty_fd
And to read, if you need to
while (read(d->tty_fd,c,100) > 0)
{
// Do stuff with contents in array "c"
}
giuliomoro my understanding is that this is for Simulink only ?
May be true. I haven't done much with MATLAB since university. When something requires IO with the outside world then I use C or Python.