RS232 MatLab Interface

3 ビュー (過去 30 日間)
Steve
Steve 2012 年 1 月 19 日
I have a project where I need to input data from a microcontroller via RS232 and display to a graph. To test the connectivity, I am trying to use Hyperterminal on a PC connected to another PC running MatLab.
I am able to view the characters in MatLab from Hyperterminal, however, they only appear once the fscanf() function times out. My project entails a continuously updating graph so I will need to display this data as soon as it hits the buffer. Is there anyway that I can continuously read data with RS232?
Any help is appreciated as I have been trying to figure this one out for a few days.
Thank you,
Steve

回答 (4 件)

Walter Roberson
Walter Roberson 2012 年 1 月 19 日
If your data is continuous and not line structured, you should more likely be using fread() rather than fscanf() (but there can be reasons for using fscanf(), if you are careful.)

Steve
Steve 2012 年 1 月 21 日
The BytesAvailableFcn worked to bring in the data, however MatLab did not show the information until the timeout. I need to be able to update graphs continuously to show real time data from sensors. Since I am so unfamiliar with this type of programming in MatLab I am unsure if this will work for my application.
Here is the code that I have been working with:
s = serial('COM1');
>> set(s,'BaudRate', 115200);
>> s.ReadAsyncMode='continuous';
>> s.BytesAvailableFcnCount = 1;
>> s.BytesAvailableFcnMode = 'byte';
>> fopen(s);
>> Output = fread(s)
I also tried using 'terminator' instead of 'byte' but this was unsuccesful as well.
Any thoughts?
Thank you
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 1 月 21 日
fread() without an argument asks for all the data until the object's InputBufferSize has been reached. Specify the number of bytes to read in the fread() call.

サインインしてコメントする。


Steve
Steve 2012 年 1 月 21 日
PS this is the message returned along with the data:
Warning: The specified amount of data was not returned within the Timeout period.

Manikandan
Manikandan 2013 年 8 月 11 日
i,m trying the same but i use simulink to show signal via scope, the output is not an exact data and it is not updating data regularly, first i tried interconnection of 2 PC via rs232. let me say if any suggestion to overcome this problem..
Reg, R.Manikandan,M.E.,(Ph.D)., AP / Department of EEE, The Kavery Engineering College, Mecheri (po), Salem(dt), pin:636453 Tamil Nadu, India. Cell: 9944270473 Email: electricmani@yahoo.co.in
  1 件のコメント
Walter Roberson
Walter Roberson 2013 年 8 月 11 日
Please create a new Question for this. The operations for Simulink are notably different.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by