4.78261

4.8 | 23 ratings Rate this file 52 Downloads (last 30 days) File Size: 117 KB File ID: #5060

RS232 Blockset

by

 

02 Jun 2004 (Updated )

This blockset allows Simulink to communicate with remote devices using RS232 interface.

| Watch this File

File Information
Description

RS232 Blockset is a block library that allows to a simulation model to communicate directly and in real time (using, for example, the RT Blockset also published in MATLAB Central) with a remote device.

Actually, it's possible to use a simple communication protocol based on formatted string (in which simulation data is used to compose the message) using a ANSI C printf-like formatting standard.

12 blocks are actually available:

Initialization:
- RS232_Setup: Initialize and close the serial communication. The settings of the serial communication are selectable using the block panel
Unbuffered Formatted Communication:
- RS232_Read_Format: Reads from the serial port a formatted string (function analogue to the standard-C sscanf function).
- RS232_Write_Format: writes to the serial port a formatted string (function analogue to the standard-C sprintf function).
- RS232_Write_String: writes to the serial port the string indicated as block parameter.
- RS232_Read_Fix_Format: Read fix formatted string from a buffer. This block has been generated specifically to read Flight Simulator's formatted data string.
Buffered Formatted Communication:
- RS232_Create_Buffer: Initialize and allocate an input communication buffer.
- RS232_Read_Buffer: Reads bytes from the serial port, add them to the input buffer and looks into the buffer for a formatted string (function analogue to the standard-C sscanf function), leaving into the buffer all the bytes that doesn't correspond to the searched string (except the ones that are before the found string).
- RS232_Wait_Buffer_Synch: Looks for messages headers into the buffer and returns the "code" of first message in the buffer. Read data from the serial port and add it to the buffer, but doesn't remove any byte from it.
Bynary Formatted Communication:
- RS232_Write_Binary: Write a binary formatted data to the serial output.
Binary Buffered Formatted Communication:
- RS232_Read_Binary_Buffer: This block reads bytes from the serial port, add them to the input buffer and gets, starting at the start of the buffer, formatted data (the format is declared in the format string argument), leaving into the buffer all the bytes that exceeds the read operation.
- RS232_Peek_Binary_Buffer: This block peeks bytes from the serial port, add them to the input buffer and gets, starting at the start of the buffer, formatted data (the format is declared in the format string argument), leaving unmodified the buffer (no bytes are removed from the buffer, eventually some data are added in the case that new data is in the input port).
The interface of this function is the same respect to the RS232_Read_Binary_Buffer block, except that after the read is complete, the read portion of data is NOT removed from the buffer.
- RS232_Synch_Binary_Buffer: Looks for data header into the buffer and returns "1" at the output flag when the header is found.

The library blocks allow to write a simple string, to read and write a formatted string, to buffer strings and read multiple string types, to read and write a fix formatted string and to read and write a binary formatted strings. Some more blockset will be available in the new version, specialized for read and write to the RS232 port using the NMEA protocol or the TAIP (Trimble ASCII) protocol.
The RTW and xPC release of this blockset will be also available in the next future.

Required Products Simulink
MATLAB release MATLAB 6.5 (R13)
Other requirements RT Blockset is useful to communicate in real-time
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (38)
01 Jul 2013 Anisha

Hi, I'm using the serial port to get data into xPC but I don't think I'm using the right RS232 blocks. How can I get the 18 char hexadecimal string into xPC target?

It works fine in Matlab, and i am using version 2009b.

21 Jun 2011 Krystian

On R2007b an attempt to include the RS 232 Synch Binary Buffer
generates following error message:

"jar:file:/C:/Matlab2007b/java/jar/toolbox/dastudio.jar!/com/mathworks/toolbox/dastudio/diagView/resources/nag_red.gif Model error Unknown Simulink Block 'built-in/readBinBuffer2' already has a built-in parameter 'mask'. Hence a mask parameter of the same name cannot be added."

I am sure it worked fine with R13.
Any hints how to get it running?

06 Apr 2011 Tanmay

Sir could you please tell me where exactly should I save this toolbox so that becomes funtional?

23 Nov 2010 Unex HosseinNia

I am using srial port to communicate matlab and a robot so that I need to send following command to robot see the output from the robot where all are in Hexadecimal format:
FAFB045A3b2003BC
FAFB04043b010044
FAFB040b3bd2001C
FAFB04151B010035
Could you please help if I can do it through serial port with matlab. Already I have done those with hyper terminal but I need to connect with matlab. I would appreciate if you could answer me. Meanwhile, I use matlab 2010a which Is not compatible with your block, I guess. I would also wondering if you could answer to my questions kindly?
Best,

02 Sep 2009 Julius

Hello Leonard, I am working on a project to display ECG, SpO2 and CO2 waveforms on the PC using Matlab. I am using RS232 to interface with my PC. Do you have any advice for me on how do i set up a GUI that i able to read the data from RS232 and then display the waveforms on Matlab? thanks for the help.
Julius

27 Nov 2008 Carlos Gomez

Hello Leonardo.
I have some problems to open the port, could you send me, some examples or how I can install the blockset and the .dll in matlab.

14 Oct 2008 Hadi Aliakbarian

Yaap. That is what I need too, but how to use it? please provide us a readme.

11 Oct 2008 Carolina Avendaño

Hi, Leonardo, I'm trying to use this blockset, but I've some problems to do it. how can I install or upload this blockset in Simulink... Can you upload more information? please... Thanks...

01 Oct 2008 Daniel Martin

Great help! may I ask you a question? how are the block coded? are they coded in C and then introduced in Simulink? or are they coded in a Simulink Embedded function?

I need to code a complex serial interface in Simulink Embedded functions and I don´t know how to share the serial port object between several blocks. You use a handler in/out. How did you do it (in case you did it in an Embedded functions)?

many many thanks

24 Sep 2008 Giray YAGLIKÇI

that is what i need. But how can i install that? There is no readme file. Could you manage it?

23 Jul 2008 john mark

this is the way we con do it.

08 Jul 2008 José Adalberto

Hi, excelent tool, but i need to generate code with Real Time Workshop, is this possible? even with the Matlab 6.5 version?
thank you

22 Jun 2008 Matt w

Hi, i need to use com port 5. is there anyway i can access this port using this block set? thanks in advance.

22 Oct 2007 monika m

hello & thanks 4 this stuff.i have a problem with running this blockset.u know i try it az i send something via com1 & reciving that through com2.but when i want to run its realtime workshop i have an error which says"error using rtw_c"& also "error oqured in sbuild".woud u pleaz help me to solve my simulink problems. thanks 4 your help.

02 Aug 2007 Samira S

I could not send and recieve data via this block set although it has no errors.Is there any comments in order to run that?

10 Jul 2007 Ilija Batas  
14 Jan 2007 asher levi  
05 Jan 2007 Steven Kolak

.
Simulink now supports serial RS-232 communication with Simulink blocks provided in the Instrument Control Toolbox.

These client blocks enable Simulink models to communicate with remote applications over the serial interface.

Visit The MathWorks serial web page for more information:
http://www.mathworks.com/serial

25 Nov 2006 mahmood ababsi

I have try your box. but have got some problem.
I want to receive a data from serial port and want to display it on the GUI.

26 Sep 2006 John Smith  
26 Sep 2006 Bas d'Herripon

Works fine, also in real time.
Some detailed examples with format and output would be nice.

17 May 2006 piter pam

The RTW and xPC release of this blockset will be also available in the next future

... I am interested by this ...

07 May 2006 A R

interesting

26 Apr 2006 Hemendra Pandey  
18 Mar 2006 GREGORY CONDE  
11 Mar 2006 Delporte Jean-François

I need to send the string "S76Q00P" on my serial port but When I write this string in the RS232 Write String block I have only in output 'S7'. I think that the problem is that the time between the string 'Q' and '0' is not enough long. How resolve this probleme?

08 Mar 2006 Duong Pham

I can't use it with realtime workshop.
Can any one use it with real time workshop

02 Mar 2006 Minh Tan Duong

Can you show me how does it work? Can you send some examples.

23 Feb 2006 Giuseppe Leonardo Cascella

great work & super documentation,
well done!!!

21 Feb 2006 lin adlina

hi Leonardo. I want your help.I want to know how to connect the dc motor speed controller circuit to the interface circuit using rs232.I hope you can help me.

03 Aug 2005 chan dran

hi leonard,
i want one help, i dont know how to configure with simulink. plz, guide mw how to configure the dll files with simulink

18 Jul 2005 Ehsan Tara  
08 May 2005 Rajput Ajay

Hi,Leonardo. Thanks for giving such help in matlab but still i am having some problems to receive data in matlab of version 6p5 from my microcontroller and also visual basic.So i would be thankful to u if u provide some guidance or tips regarding this problem.

08 May 2005 Rajput Ajay  
26 Mar 2005 Hasan YARDIMCI

That is great.Leonardo,would you mind sending me some documents about preparing RS232 GUI in matlab.I want to prepare an interface using matlab.I've an MCU(microcontroller unit) and it has serial port.How can be sent datas to my pc using matlab.

25 Mar 2005 Hector Fregoso

This software is great. The next is directed to the author. Leonardo I am really interested in how to program this type of software in MATLAB. Would you mind sending me a flow diagram of your software?

05 Nov 2004 priya santhanam  
24 Jun 2004 Fred Bergen

Excellent! Good Job! Examples are very helpful!

Contact us