What library or function should I use to interface using an RS-232 port (connected via 232 to USB adapter) which is attached to an Arduino Uno as a shield?
4 次查看(过去 30 天)
显示 更早的评论
Hi there.
So I've been using an Arduino Uno to imitate serial interfacing between my MATLAB code and a device that is going to be connected to the MATLAB code in the future. It was decided that interface between the two was going to be an RS-232 and hence I bought an RS-232 sheild to attatch onto my Arduino and ran some test code and it was responsive so I know it is functional.
My issue is I don't know how I'm supposed to be changing my MATLAB code to accomodate the RS-232 port; which I'm attaching to my computer using a DB9 to USB adapter, instead of the regular USB serial port I was using beforehand.
close all
clc
device=serialport("COM4", 9600);
configureTerminator(device, "CR/LF");
flush(device);
A=double.empty;
for c=1:20
outputData=readSineWaveData(device);
A=cat(1,A, outputData);
end
This code is based off a package I found from an example on MATHWORKS, the readSineWave() function does most of the reading and packaging and is iterated 20 times to get the package size I'm looking for.
My question is is there something I need to add, in terms of add-ons, fucntions, libraries, to get data from that RS-232 port?
For MATLAB to recoginize the Arduino I had to download the "MATLAB support for Arduino Hardware" addon and every time I connect the Arduino (without the sheild) via the serial USB connection I get:
Arduino Uno detected.
This device is ready for use with MATLAB Support Package for Arduino Hardware. Get started with examples and other documentation.
How can I change this code for that to happen with this RS-232 Port (Shield) attatched.
0 个评论
回答(1 个)
Adit Kirtani
2023-4-18
Hi Mohammed,
Since your RS-232 shield is working and your Arduino can read incoming data, I would suggest the RS-232 blockset to you. Here’s a link to the documentation page:
Using these blocks, you can Serial Write via RS-232 and your Arduino, ensuring it is setup correctly, will treat it as incoming serial data.
Essentially, you will have two scripts/models. One script will be your deployed code on the Arduino, which simply uses the RS-232 shield to read incoming data, and a second model which uses the RS-232 blocks to communicate with the Arduino.
I hope this helps,
Adit Kirtani.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Arduino Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!