Error when trying to interface Raspberry Pi 2 and serial devices: The 'serial' class does not support code generation.
2 views (last 30 days)
Show older comments
Hello,
I am having trouble creating code in Simulink to handle interfacing between my Raspberry Pi 2 and a serial device connected to pins 8 and 10. I have had no problem interfacing with this setup using the serialDev class. My goal is to build a MatLAB function block in Simulink that initializes the Raspberry Pi 2 serial port and read/write to it. The serialDev class doesn't seem like it works in Simulink so I attempted to use the serial class. Here is my code:
function y = GetParallaxParam()
%serial port parameters for Parallax
port = '/dev/ttyAMA0';
baudRate = 115200; %fastest allowed
dataBits = 8;
parity = 'none';
stopBits = 1;
%connect to serial port
Parallax = serial(port); %error Here!
Parallax.BaudRate = baudRate;
Parallax.DataBits = dataBits;
Parallax.StopBits = stopBits;
%default parity is none
fopen(Parallax);
y = Parallax;
Here is the error message:
The 'serial' class does not support code generation.
Function 'MATLAB Function' (#225.209.221), line 10, column 12:
"serial(port)"
Is my implementation of the serial class wrong? Or is there another strategy I need to follow?
Thank you,
Will
0 Comments
Answers (2)
Walter Roberson
on 23 Sep 2015
serial class has a lot of implications about callbacks and background processing and buffering and so on, which mostly cannot be expected to be supported on a generic system; remember that code generation has to target something that barely has a Standard C library.
3 Comments
See Also
Categories
Find more on Raspberry Pi Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!