Difference between revisions of "Scilab/C4/Loading-and-saving-data-in-Xcos/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(3 intermediate revisions by 2 users not shown)
Line 9: Line 9:
 
! '''Narration'''
 
! '''Narration'''
 
|-
 
|-
|
+
|Show Slide:
Show Slide:
+
  
 
'''Title Slide'''
 
'''Title Slide'''
 
| Hello and welcome to the Spoken Tutorial on “ '''Loading and saving data in Xcos'''”.
 
| Hello and welcome to the Spoken Tutorial on “ '''Loading and saving data in Xcos'''”.
 
|-
 
|-
|
+
|Show Slide:
Show Slide:
+
  
 
'''Learning Objectives'''
 
'''Learning Objectives'''
|
+
|In this tutorial, we will learn how to:
In this tutorial, we will learn how to:
+
  
<ul>
+
*Save '''Xcos simulation data values''' to the '''workspace'''
<li><blockquote><p>Save '''Xcos''' simulation data values to the '''workspace'''.</p></blockquote></li>
+
*Read and write '''data''' in '''Xcos simulation''' using a '''C binary''' file
<li><blockquote><p>Read and write data in '''Xcos''' simulation using a '''C binary''' file</p></blockquote></li></ul>
+
 
|-
 
|-
|
+
|Show Slide:
Show Slide:
+
  
 
'''System Requirements'''
 
'''System Requirements'''
|
+
|To record this tutorial, I am using
To record this tutorial, I am using
+
  
<ul>
+
*'''Ubuntu 18.04 OS''' and
<li><blockquote><p>'''Ubuntu 18.04 OS''' and</p></blockquote></li>
+
*'''Scilab 6.1.0 version'''
<li><blockquote><p>'''Scilab 6.1.0 version'''</p></blockquote></li></ul>
+
 
|-
 
|-
|
+
|Show Slide:
Show Slide:
+
  
 
'''Pre-requisites'''
 
'''Pre-requisites'''
|
+
|To follow this tutorial, you should have
To follow this tutorial, you should have
+
  
<ul>
+
*Basic knowledge of '''Scilab''' and '''Xcos.'''
<li><blockquote><p>Basic knowledge of '''Scilab and Xcos.'''</p></blockquote></li>
+
*If not, for relevant tutorials please visit this website.
<li><blockquote><p>If not, for relevant tutorials please visit this website.</p></blockquote></li></ul>
+
 
|-
 
|-
|
+
|Show Slide:
Show Slide:
+
  
 
'''Code Files'''
 
'''Code Files'''
 
|
 
|
<ul>
+
*The files used in this tutorial are provided in the '''Code files''' link.
<li><blockquote><p>The files used in this tutorial are provided in the '''Code files''' link.</p></blockquote></li>
+
*Please download and extract the files.
<li><blockquote><p>Please download and extract the files.</p></blockquote></li>
+
*Make a copy and then use them while practising.
<li><blockquote><p>Make a copy and then use them while practising.</p></blockquote></li></ul>
+
 
|-
 
|-
| Cursor on the '''Untitled Xcos editing''' window.
+
|Cursor on the '''Untitled Xcos editing''' window.
|
+
|I have already opened the '''Xcos''' windows.
I have already opened the '''Xcos''' windows.
+
  
We can see two windows named '''Untitled Xcos''' and the '''Palette browser''' are opened'''.'''
+
We can see two windows named '''Untitled Xcos''' and the '''Palette browser''' are opened.
 
|-
 
|-
|
+
|On the '''Untitled Xcos''' window,
On the '''Untitled Xcos''' window,
+
  
 
Cursor on '''Toolbar''' &gt;&gt; Click on '''Open file''' option &gt;&gt; Click on '''SaveData.xcos''' &gt;&gt; Click on '''OK.'''
 
Cursor on '''Toolbar''' &gt;&gt; Click on '''Open file''' option &gt;&gt; Click on '''SaveData.xcos''' &gt;&gt; Click on '''OK.'''
|
+
|Go to the '''Untitled Xcos''' window.
Go to the '''Untitled Xcos''' window.
+
  
 
Click on the '''Open File''' icon on the '''Toolbar'''.
 
Click on the '''Open File''' icon on the '''Toolbar'''.
Line 79: Line 64:
 
Then click on the '''OK''' button.
 
Then click on the '''OK''' button.
 
|-
 
|-
| Adjust the Window accordingly.
+
|Adjust the Window accordingly.
|
+
|Let me adjust the window.
Let me adjust the window.
+
  
 
I have already created this file for demonstration.
 
I have already created this file for demonstration.
 
|-
 
|-
|
+
|On the '''SaveData.xcos''' window,
On the '''SaveData.xcos''' window,
+
  
 
cursor on the '''SaveData.xcos''' window.
 
cursor on the '''SaveData.xcos''' window.
| This file has a simple '''Xcos''' simulation diagram.
+
|This file has a simple '''Xcos simulation''' diagram.
 
|-
 
|-
|
+
|On the '''SaveData.xcos''' window,
On the '''SaveData.xcos''' window,
+
  
Hover cursor on '''RAMP''' block.
+
Hover cursor on '''RAMP block'''.
| It uses the '''RAMP''' block to generate a '''Ramp''' signal.
+
|It uses the '''RAMP block''' to generate a '''Ramp signal'''.
 
|-
 
|-
|
+
|On the '''SaveData.xcos''' window,
On the '''SaveData.xcos''' window,
+
  
Hover cursor on '''CSCOPE''' block.
+
Hover cursor on '''CSCOPE block'''.
|
+
|And the '''CSCOPE block''' to plot it.
And the '''CSCOPE''' block to plot it.
+
  
Let us see how to record the generated Ramp signal.
+
Let us see how to record the generated '''Ramp signal'''.
 
|-
 
|-
|
+
|On the '''SaveData.xcos''' window,
On the '''SaveData.xcos''' window,
+
  
 
cursor on the '''SaveData.xcos window'''
 
cursor on the '''SaveData.xcos window'''
| First we will see how to push the values generated by the '''RAMP''' block to '''workspace.'''
+
|First we will see how to push the values generated by the '''RAMP block''' to '''workspace.'''
 
|-
 
|-
|
+
|On '''palette browser''',
On '''palette browser''',
+
  
 
click on '''Sinks''' &gt;&gt; scroll down &gt;&gt; click on '''TOWS_c.'''
 
click on '''Sinks''' &gt;&gt; scroll down &gt;&gt; click on '''TOWS_c.'''
|
+
|Go to the '''Palette browser''' window.
Go to the '''palette browser''' window.
+
  
Click on the '''Sinks''' palette.
+
Click on the '''Sinks palette'''.
  
In the right panel, select the '''TOWS_c''' block. This is the '''To Workspace''' block.
+
In the right panel, select the '''TOWS_c block'''. This is the '''To Workspace block'''.
 
|-
 
|-
| As per narration
+
|As per narration
| '''Drag and Drop''' the '''To Workspace''' block to the '''SaveData.xcos''' window'''.'''
+
|'''Drag and Drop''' the '''To Workspace block''' to the '''SaveData.xcos''' window.
 
|-
 
|-
|
+
|On the '''editing''' window,
On the '''editing''' window,
+
  
Double click on the '''TOWS_c''' block.
+
Double-click on the '''TOWS_c''' block.
| Double click on the '''To Workspace''' block to configure its properties.
+
|Double-click on the '''To Workspace block''' to '''configure''' its properties.
 
|-
 
|-
|
+
|On the '''Scilab Multiple Values Request''' Window of '''TOWS_c block'''
On the '''Scilab Multiple Values Request''' Window of '''TOWS_c''' block,
+
  
 
Double click on the '''Size of Buffer.''' Text field to highlight it.
 
Double click on the '''Size of Buffer.''' Text field to highlight it.
|
+
|The size of '''buffer''' is by default set to '''128.'''
The size of buffer is by default set to '''128.'''
+
  
This means that 128 values will be saved in the block .
+
This means that 128 values will be saved in the '''block'''.
  
If any more values are passed, the block will overwrite the previous values.
+
If any more values are '''passed''', the '''block''' will overwrite the previous values.
 
|-
 
|-
|
+
|On the '''Scilab Multiple Values Request''' Window of '''TOWS_c block'''
On the '''Scilab Multiple Values Request''' Window of '''TOWS_c''' block,
+
  
Double click on the '''Variable Name''' text field to highlight it.
+
Double-click on the '''Variable Name''' text field to highlight it.
|
+
|The '''Variable Name''' is the name of the '''variable''' to which the values are saved.
The '''Variable Name''' is the name of the variable to which the values are saved.
+
  
By default it is set to '''A.'''
+
By default it is '''set''' to '''A.'''
 
|-
 
|-
|
+
|On the '''Scilab Multiple Values Request''' Window of '''TOWS_c block'''
On the '''Scilab Multiple Values Request''' Window of '''TOWS_c''' block,
+
  
 
Double click on the '''Inherit''' Text field to highlight it.
 
Double click on the '''Inherit''' Text field to highlight it.
  
 
Click on the '''OK''' button at the bottom.
 
Click on the '''OK''' button at the bottom.
|
+
|'''Inherit''' is used to decide whether to take the '''event input''' or not.
'''Inherit''' is used to decide whether to take the event input or not.
+
  
By default Inherit is set to '''0''' which means it has to take event input.
+
By default '''Inherit''' is '''set''' to '''0''' which means it has to take '''event input'''.
  
 
Click on the '''OK''' button to close this window.
 
Click on the '''OK''' button to close this window.
 
|-
 
|-
|
+
|On '''SaveData.xcos Window''',
On '''SaveData.xcos Window''',
+
  
Connect as per narration'''.'''
+
Connect as per narration.
|
+
|Let us make the connections.
Let us make the connections.
+
  
Select the '''black input port''' of the '''To Workspace''' block.
+
Select the '''black input port''' of the '''To workspace block'''.
  
Connect it to the line joining the '''RAMP''' and the '''CSCOPE''' block.
+
Connect it to the line joining the '''RAMP''' and the '''CSCOPE block'''.
 
|-
 
|-
|
+
|On '''SaveData.xcos Window''',
On '''SaveData.xcos Window''',
+
  
 
Connect as per narration'''.'''
 
Connect as per narration'''.'''
|
+
|Next, select the '''red input port''' of the '''To workspace block'''.
Next, Select the '''red input port''' of the '''TOWS_c''' block.
+
  
Connect it to the line joining the '''CLOCK_c''' and the '''CSCOPE''' block.
+
Connect it to the line joining the '''CLOCK_c''' and the '''CSCOPE block'''.
  
Our file is ready for simulation.
+
Our file is ready for '''simulation'''.
 
|-
 
|-
|
+
|On the '''SaveData.xcos''' window,
On the '''SaveData.xcos''' window,
+
  
 
Click on '''Start''' button on the toolbar &gt;&gt; click on '''OK''' button on the '''Warning message.'''
 
Click on '''Start''' button on the toolbar &gt;&gt; click on '''OK''' button on the '''Warning message.'''
|
+
|Let us run this '''simulation''' by clicking on the '''Start''' button on the '''toolbar'''.
Let us run this simulation by clicking on the '''Start''' Button on the '''toolbar'''.
+
  
 
A '''Warning message''' will appear.
 
A '''Warning message''' will appear.
Line 198: Line 162:
 
Ignore the message and click on the '''OK''' button.
 
Ignore the message and click on the '''OK''' button.
 
|-
 
|-
|
+
|On the '''Graphic''' window,
On the '''Graphic''' window,
+
  
 
Hover cursor on the '''graph.'''
 
Hover cursor on the '''graph.'''
  
 
Close the '''Graphic''' window.
 
Close the '''Graphic''' window.
|
+
|We can see a straight line with '''slope 2'''.
We can see a straight line with slope 2.
+
  
 
Let’s close the graphic window.
 
Let’s close the graphic window.
 
|-
 
|-
| Switch to '''workspace.'''
+
|Switch to '''workspace.'''
|
+
|Now let us look at the '''values'''.
Now let us look at the values.
+
  
 
Switch to the '''workspace'''.
 
Switch to the '''workspace'''.
 
|-
 
|-
|
+
|On the '''workspace''',
On the '''workspace''',
+
  
 
Type '''''A''''' &gt;&gt; press '''Enter.'''
 
Type '''''A''''' &gt;&gt; press '''Enter.'''
|
+
|Let us '''execute''' the '''variable A'''.
Let us execute the variable '''A'''.
+
  
 
Type '''A''' on the '''workspace''' and press '''Enter'''.
 
Type '''A''' on the '''workspace''' and press '''Enter'''.
 
|-
 
|-
|
+
|On the '''workspace''' window,
On the '''workspace''' window,
+
  
 
Highlight '''variable A.'''
 
Highlight '''variable A.'''
Line 232: Line 190:
  
 
Highlight '''time.'''
 
Highlight '''time.'''
|
+
|'''A''' is a special '''variable'''.
'''A''' is a special variable.
+
  
 
We can either extract '''values''' from '''A''' or we can extract '''times''' from '''A.'''
 
We can either extract '''values''' from '''A''' or we can extract '''times''' from '''A.'''
  
Let us look at the values.
+
Let us look at the '''values'''.
 
|-
 
|-
|
+
|On the '''workspace''' window,
On the '''workspace''' window,
+
  
 
Type '''''A.values''''' &gt;&gt; Press '''Enter.'''
 
Type '''''A.values''''' &gt;&gt; Press '''Enter.'''
|
+
|Type '''A.values''' on the '''workspace'''.
Type '''A.values''' on the '''workspace'''.
+
  
 
Press '''Enter.'''
 
Press '''Enter.'''
 
|-
 
|-
|
+
|On the '''workspace''',
On the '''workspace''',
+
  
 
Scroll up to show all the values and Highlight them.
 
Scroll up to show all the values and Highlight them.
| These are all the values from the graph and are now saved in the workspace.
+
|These are all the values from the graph and are now saved in the '''workspace'''.
 
|-
 
|-
|
+
|On the '''workspace''',
On the '''workspace''',
+
  
 
hover cursor on a new line on the workspace.
 
hover cursor on a new line on the workspace.
| Now we need to save these values in a file so that we can share them.
+
|Now we need to save these '''values''' in a file so that we can share them.
 
|-
 
|-
| Switch to '''SaveData.xcos''' window.
+
|Switch to '''SaveData.xcos''' window.
| Switch back to the '''SaveData.xcos''' window.
+
|Switch back to the '''SaveData.xcos''' window.
 
|-
 
|-
|
+
|On the '''palette browser''',
On the '''palette browser''',
+
  
Click on '''Sinkss''' &gt;&gt; Click on '''WRITEC_f''' block.
+
Click on '''Sinkss''' &gt;&gt; Click on '''WRITEC_f block'''.
|
+
|To save these '''values''', we will use the '''WRITEC_f block'''.
To save these values, we will use the '''WRITEC_f''' block.
+
  
Go to the '''palette browser''' window.
+
Go to the '''Palette browser''' window.
  
Click on the '''Sinks''' palette.
+
Click on the '''Sinks palette'''.
  
Click on the '''WRITEC_f''' block in the right panel.
+
Click on the '''WRITEC_f block''' in the right panel.
  
This is the '''Write to C binary file''' block.
+
This is the '''Write to C binary file block'''.
 
|-
 
|-
| As per narration
+
|As per narration
| '''Drag and Drop''' the block on the '''SaveData.xcos''' window.
+
|Drag and drop the '''block''' on the '''SaveData.xcos''' window.
 
|-
 
|-
|
+
|On the '''SaveData.xcos''' window,
On the '''SaveData.xcos''' window,
+
  
Double click on '''WRITEC_f''' block.
+
Double-click on '''WRITEC_f block'''.
| Double click on the '''WRITEC_f''' block to configure its properties.
+
|Double-click on the '''WRITEC_f block''' to '''configure''' its properties.
 
|-
 
|-
|
+
|On the '''Scilab Multiple Values Request''' Window of '''WRITEC_f block''',
On the '''Scilab Multiple Values Request''' Window of '''WRITEC_f''' block,
+
  
 
Double click on the '''Input Size''' Text field to highlight it.
 
Double click on the '''Input Size''' Text field to highlight it.
| '''Input Size''' is the size of our input values.
+
|'''Input Size''' is the size of our input '''values'''.
 
|-
 
|-
|
+
|On the '''Scilab Multiple Values Request''' Window of '''WRITEC_f block'''
On the '''Scilab Multiple Values Request''' Window of '''WRITEC_f''' block,
+
  
 
Double click on the '''Output File Name''' Text field to highlight it &gt;&gt; Change it to '''''‘data’'''''
 
Double click on the '''Output File Name''' Text field to highlight it &gt;&gt; Change it to '''''‘data’'''''
|
+
|'''Output File''' is the name of our output file.
'''Output File''' is the name of our output file.
+
  
I will name the output file as '''‘ data ‘'''.
+
I will name the output file as '''‘data ‘'''.
  
If no file path is entered, the file will be saved in the '''Current working directory.'''
+
If no '''file path''' is entered, the file will be saved in the '''Current working directory.'''
 
|-
 
|-
|
+
|On the '''Scilab Multiple Values Request''' window of '''WRITEC_f block'''
On the '''Scilab Multiple Values Request''' Window of '''WRITEC_f''' block,
+
  
Double click on the '''Output Format''' Text field to highlight it &gt;&gt; Change it to ‘ '''d''' ’
+
Double-click on the '''Output Format''' Text field to highlight it &gt;&gt; Change it to ‘ '''d''' ’
|
+
|'''Output Format''' is the format of the output file.
'''Output Format''' is the format of the output file.
+
  
By default it is '''‘ c ‘.''' That is, by default, values are saved as integers.
+
By default it is '''‘ c ‘.''' That is, by default, '''values''' are saved as '''integers'''.
  
But, I want to save the values as '''double.''' So''',''' I will change it to '''‘d’.'''
+
But, I want to save the '''values''' as '''double.''' So, I will change it to '''‘d’.'''
 
|-
 
|-
|
+
|On the '''Scilab Multiple Values Request''' Window of '''WRITEC_f block''',
On the '''Scilab Multiple Values Request''' Window of '''WRITEC_f''' block,
+
  
Double click on the '''Buffer Size''' Text field to highlight it.
+
Double-click on the '''Buffer Size''' Text field to highlight it.
| '''Buffer Size''' is the size of the buffer.
+
|'''Buffer Size''' is the size of the '''buffer'''.
 
|-
 
|-
|
+
|On '''SaveData.xcos Window''',
On '''SaveData.xcos Window''',
+
  
 
Connect as per narration'''.'''
 
Connect as per narration'''.'''
|
+
|Let us make the connections.
Let us make the connections.
+
  
Select the '''black input port''' of the '''WRITEC_f''' block.
+
Select the '''black input port''' of the '''WRITEC_f block'''.
  
Connect it to the line joining the '''RAMP''' and the '''CSCOPE''' block.
+
Connect it to the line joining the '''RAMP''' and the '''CSCOPE block'''.
 
|-
 
|-
|
+
|On '''SaveData.xcos Window''',
On '''SaveData.xcos Window''',
+
  
 
Connect as per narration'''.'''
 
Connect as per narration'''.'''
|
+
|Next, select the '''red input port''' of the '''WRITEC_f block'''.
Next, Select the '''red input port''' of the '''WRITEC_f''' block.
+
  
Connect it to the line joining the '''CLOCK_c''' and the '''CSCOPE''' block.
+
Connect it to the line joining the '''CLOCK_c''' and the '''CSCOPE block'''.
  
Our file is ready for simulation.
+
Our file is ready for '''simulation'''.
 
|-
 
|-
|
+
|On the '''SaveData.xcos''' window,
On the '''SaveData.xcos''' window,
+
  
 
Click on '''Start''' button on the toolbar &gt;&gt; click on '''OK''' button on the Warning message.
 
Click on '''Start''' button on the toolbar &gt;&gt; click on '''OK''' button on the Warning message.
|
+
|Let's '''run''' the '''simulation''' again by clicking on the '''Start''' Button on the '''toolbar.'''
Let's run the simulation again by clicking on the '''Start''' Button on the '''toolbar.'''
+
  
 
A '''Warning message''' will appear. Ignore the message and click on the '''OK''' button.
 
A '''Warning message''' will appear. Ignore the message and click on the '''OK''' button.
 
|-
 
|-
|
+
|On the '''Graphic''' window,
On the '''Graphic''' window,
+
  
 
Hover cursor on the '''graph.'''
 
Hover cursor on the '''graph.'''
  
 
'''Close''' the Graphic window.
 
'''Close''' the Graphic window.
|
+
|We can see the graph.
We can see the graph.
+
  
 
Let’s close the graphic window.
 
Let’s close the graphic window.
 
|-
 
|-
| As per narration.
+
|As per narration.
| Let's go to the location where we have saved the data file.
+
|Let's go to the location where we have saved the '''data''' file.
 
|-
 
|-
|
+
|On '''file manager window''',
On '''file manager window''',
+
  
 
Click on the '''data''' file once.
 
Click on the '''data''' file once.
|
+
|We can see a file named '''‘data‘''' .
We can see a file named '''‘ data ‘''' .
+
  
Since it is a binary encoded file we cannot simply read it.
+
Since it is a '''binary encoded''' file we cannot simply read it.
  
We would need a special block to read this file.
+
We would need a special '''block''' to read this file.
 
|-
 
|-
| Switch back to '''SaveData.xcos''' file
+
|Switch back to '''SaveData.xcos''' file
| Switch back to the '''SaveData.xcos''' window.
+
|Switch back to the '''SaveData.xcos''' window.
 
|-
 
|-
|
+
|On the '''SaveData.xcos''' window,
On the '''SaveData.xcos''' window,
+
  
 
Cursor on '''Toolbar''' &gt;&gt; Click on '''Open file''' option &gt;&gt; Click on '''LoadData.xcos''' &gt;&gt; Click on '''OK'''
 
Cursor on '''Toolbar''' &gt;&gt; Click on '''Open file''' option &gt;&gt; Click on '''LoadData.xcos''' &gt;&gt; Click on '''OK'''
|
+
|Let us open the file '''LoadData.xcos'''
Let us open the file '''LoadData.xcos'''
+
  
 
Click on the '''Open File''' icon on the '''Toolbar'''.
 
Click on the '''Open File''' icon on the '''Toolbar'''.
Line 391: Line 323:
 
A window will appear.
 
A window will appear.
  
Go to '''Downloads''' Folder and select the file '''LoadData.xcos'''.
+
Go to '''Downloads''' folder and select the file '''LoadData.xcos'''.
  
 
Then click on the '''OK''' button.
 
Then click on the '''OK''' button.
  
We will use this file to read our data file.
+
We will use this file to read our '''data''' file.
 
|-
 
|-
| Adjust the Window accordingly.
+
|Adjust the Window accordingly.
| Let me adjust the window.
+
|Let me adjust the window.
 
|-
 
|-
|
+
|On the '''palette browser,'''
On the '''palette browser,'''
+
  
Click on '''Sources''' &gt;&gt; Click on '''READC_f''' block.
+
Click on '''Sources''' &gt;&gt; Click on '''READC_f block'''.
|
+
|We will use the '''READC_f block''' to read our '''values'''.
We will use the '''READC_f''' block to read our values.
+
  
Go to the '''palette browser''' window.
+
Go to the '''Palette browser''' window.
  
Click on the '''Sources''' palette.
+
Click on the '''Sources palette'''.
  
Click on '''READC_f''' Block in the right panel.
+
Click on '''READC_f block''' in the right panel.
  
This is the '''Read from C Binary''' block.
+
This is the '''Read from C Binary block'''.
 
|-
 
|-
 
| As per narration
 
| As per narration
| '''Drag and Drop''' the block on the '''LoadData.xcos''' window.
+
| '''Drag and Drop''' the '''block''' on the '''LoadData.xcos''' window.
 
|-
 
|-
 
|
 
|
 
On the '''LoadData.xcos''' window,
 
On the '''LoadData.xcos''' window,
  
Double click on '''READC_f''' block..
+
Double-click on '''READC_f block'''
| Double click on the '''READC_f''' block to configure its properties'''.'''
+
| Double-click on the '''READC_f block''' to '''configure''' its properties.
 
|-
 
|-
|
+
|On the '''Scilab Multiple Values Request''' Window of '''READC_f block'''
On the '''Scilab Multiple Values Request''' Window of '''READC_f''' block,
+
  
Double click on the '''Input File Name''' Text field to highlight it. &gt;&gt; Change it to '''''data'''''
+
Double-click on the '''Input File Name''' Text field to highlight it. &gt;&gt; Change it to '''''data'''''
|
+
|'''Input File Name''' is the name and the '''path''' of your '''data''' file.
'''Input file''' name is the name and the path of your data file.
+
  
Since my data file was named '''data''' I will change it to '''data'''.
+
Since my '''data''' file was named '''data''' I will change it to '''data'''.
 
|-
 
|-
|
+
|On the '''Scilab Multiple Values Request''' Window of '''READC_f block'''
On the '''Scilab Multiple Values Request''' Window of '''READC_f''' block,
+
  
Double click on the '''Input Format''' Text field to highlight it &gt;&gt; Change it to '''''d.'''''
+
Double-click on the '''Input Format''' Text field to highlight it &gt;&gt; Change it to '''''d.'''''
|
+
|'''Input format''' is the format of the '''data''' file.
'''Input format''' is the format of the data file.
+
  
Since the format for my data file is '''double''' , I will change it to '''d'''.
+
Since the format for my '''data''' file is '''double''', I will change it to '''d'''.
 
|-
 
|-
|
+
|On the '''Scilab Multiple Values Request''' Window of '''READC_f''' block,
On the '''Scilab Multiple Values Request''' Window of '''READC_f''' block,
+
  
Double click on the '''Buffer Size''' Text field to highlight it.
+
Double-click on the '''Buffer Size''' Text field to highlight it.
  
 
Click the '''OK''' button .
 
Click the '''OK''' button .
|
+
|This is the '''buffer''' size.
This is the buffer size.
+
  
 
Let’s close this window by clicking on the '''OK''' button.
 
Let’s close this window by clicking on the '''OK''' button.
 
|-
 
|-
|
+
|On '''LoadData.xcos Window''',
On '''LoadData.xcos Window''',
+
  
 
Connect as per narration'''.'''
 
Connect as per narration'''.'''
|
+
|Let us make the connections.
Let us make the connections.
+
  
Select the '''black output port''' of the '''READC_f''' block.
+
Select the '''black output port''' of the '''READC_f block'''.
  
Connect it to the '''black input port''' of the '''CSCOPE''' block.
+
Connect it to the '''black input port''' of the '''CSCOPE block'''.
 
|-
 
|-
|
+
|On '''LoadData.xcos Window''',
On '''LoadData.xcos Window''',
+
  
Connect as per narration'''.'''
+
Connect as per narration.
|
+
|Lastly, select the '''red input port''' of the '''READC_f block'''.
Lastly, Select the '''red input port''' of the '''READC_f''' block.
+
  
Connect it to the line joining the '''CLOCK_C''' &amp; the '''CSCOPE''' block.
+
Connect it to the line joining the '''CLOCK_C''' &amp; the '''CSCOPE block'''.
 
|-
 
|-
|
+
|On the '''LoadData.xcos''' window,
On the '''LoadData.xcos''' window,
+
  
 
Click on '''Start''' button on the '''toolbar'''
 
Click on '''Start''' button on the '''toolbar'''
| Let’s run this simulation again by clicking on the '''Start''' Button on the '''toolbar'''.
+
|Let’s '''run''' this '''simulation''' again by clicking on the '''Start''' button on the '''toolbar'''.
 
|-
 
|-
|
+
|On the '''Graphic''' Window,
On the '''Graphic''' Window,
+
  
 
Hover Cursor on the '''Graph.'''
 
Hover Cursor on the '''Graph.'''
|
+
|We have a similar graph to the one we had earlier without using the '''RAMP block'''.
We have a similar graph to the one we had earlier without using the '''RAMP''' block.
+
  
This is because we have loaded the values from the data file.
+
This is because we have loaded the '''values''' from the '''data''' file.
 
|-
 
|-
|
+
|Show Slide:
Show Slide:
+
  
 
'''Summary'''
 
'''Summary'''
|
+
|This brings us to the end of this tutorial. Let us summarise.
This brings us to the end of this tutorial. Let us summarise.
+
  
 
In this tutorial, we have learnt to:
 
In this tutorial, we have learnt to:
  
<ul>
+
*Save '''Xcos simulation data values''' to the '''workspace'''.
<li><blockquote><p>Save '''Xcos''' simulation data values to the '''workspace'''.</p></blockquote></li>
+
*Read and write '''data''' in '''Xcos Simulation''' using a '''C binary''' file
<li><blockquote><p>Read and write data in '''Xcos''' Simulation using a '''C binary''' file</p></blockquote></li></ul>
+
 
|-
 
|-
|
+
|Show Slide:
Show Slide:
+
  
 
'''Assignment'''
 
'''Assignment'''
|
+
|As an assignment,
As an assignment,
+
  
Create two '''Xcos''' simulation files:
+
Create two '''Xcos simulation''' files:
  
<ul>
+
*Use the first for plotting a straight line with '''slope 3'''.
<li><blockquote><p>Use the first for plotting a straight line with slope 3.</p></blockquote></li>
+
*Push the '''values''' to the '''workspace''' and save them as a '''binary encoded''' file.
<li><blockquote><p>Push the values to the workspace and save them as a binary encoded file.</p></blockquote></li>
+
*Create another '''Xcos simulation''' to plot a new graph of a straight line with '''slope 3'''.
<li><blockquote><p>Create another '''Xcos''' simulation to plot a new graph of a straight line with slope 3.</p></blockquote></li>
+
*Use only the saved '''data values'''.
<li><blockquote><p>Use only the saved data values.</p></blockquote></li></ul>
+
 
|-
 
|-
 
| Show Slide: '''About Spoken Tutorial project'''
 
| Show Slide: '''About Spoken Tutorial project'''
|
+
|The video at the following link summarises the Spoken Tutorial project.
The video at the following link summarises the Spoken Tutorial project.
+
  
 
Please download and watch it
 
Please download and watch it
 
|-
 
|-
| Show Slide: '''Spoken Tutorial Workshops'''
+
|Show Slide: '''Spoken Tutorial Workshops'''
|
+
|The Spoken Tutorial Project team conducts workshops and gives certificates.
The Spoken Tutorial Project team conducts workshops and gives certificates.
+
  
 
For more details, please write to us.
 
For more details, please write to us.
 
|-
 
|-
|
+
|Show Slide:
Show Slide:
+
  
 
'''Answers for THIS Spoken Tutorial'''
 
'''Answers for THIS Spoken Tutorial'''
| Please post your timed queries in this forum.
+
|Please post your timed queries in this forum.
 
|-
 
|-
| Show Slide: '''FOSSEE Forum'''
+
|Show Slide: '''FOSSEE Forum'''
|
+
|Please post your general and technical queries on '''Scilab''' in this forum.
Please post your general and technical queries on '''Scilab''' in this forum.
+
  
 
|-
 
|-
|
+
|Show Slide:
Show Slide:
+
  
 
'''Textbook Companion project.'''
 
'''Textbook Companion project.'''
|
+
|The FOSSEE team coordinates the Textbook Companion project.
The FOSSEE team coordinates the Textbook Companion project.
+
  
 
We give Certificates and Honorarium to the contributors.
 
We give Certificates and Honorarium to the contributors.
Line 550: Line 455:
 
For more details, please visit this website.
 
For more details, please visit this website.
 
|-
 
|-
| Show Slide: '''Lab Migration'''
+
|Show Slide: '''Lab Migration'''
|
+
|The FOSSEE team coordinates the Lab Migration project.
The FOSSEE team coordinates the Lab Migration project.
+
  
 
For more details, please visit this website.
 
For more details, please visit this website.
 
|-
 
|-
| Show Slide: '''Acknowledgement'''
+
|Show Slide: '''Acknowledgement'''
| Spoken Tutorial and FOSSEE projects are funded by the Ministry of Education, Government of India.
+
|Spoken Tutorial and FOSSEE projects are funded by the Ministry of Education, Government of India.
 
|-
 
|-
| Show Slide: '''Thank you'''
+
|Show Slide: '''Thank you'''
|
+
|This is Utkarsh Anand, FOSSEE intern 2021, IIT Bombay signing off.
This is Utkarsh Anand, FOSSEE intern 2021, IIT Bombay signing off.
+
  
 
Thanks for joining.
 
Thanks for joining.
 
|}
 
|}

Latest revision as of 17:01, 21 September 2021

Title of script: Loading and saving data in Xcos

Author: Rupak Rokade and Utkarsh

Keywords: Xcos,TOWS_c, C_binary, workspace, read, write, data file, scilab

Visual Cue Narration
Show Slide:

Title Slide

Hello and welcome to the Spoken Tutorial on “ Loading and saving data in Xcos”.
Show Slide:

Learning Objectives

In this tutorial, we will learn how to:
  • Save Xcos simulation data values to the workspace
  • Read and write data in Xcos simulation using a C binary file
Show Slide:

System Requirements

To record this tutorial, I am using
  • Ubuntu 18.04 OS and
  • Scilab 6.1.0 version
Show Slide:

Pre-requisites

To follow this tutorial, you should have
  • Basic knowledge of Scilab and Xcos.
  • If not, for relevant tutorials please visit this website.
Show Slide:

Code Files

  • The files used in this tutorial are provided in the Code files link.
  • Please download and extract the files.
  • Make a copy and then use them while practising.
Cursor on the Untitled Xcos editing window. I have already opened the Xcos windows.

We can see two windows named Untitled Xcos and the Palette browser are opened.

On the Untitled Xcos window,

Cursor on Toolbar >> Click on Open file option >> Click on SaveData.xcos >> Click on OK.

Go to the Untitled Xcos window.

Click on the Open File icon on the Toolbar.

A window will appear.

Go to the Downloads folder and select the file SaveData.xcos.

Then click on the OK button.

Adjust the Window accordingly. Let me adjust the window.

I have already created this file for demonstration.

On the SaveData.xcos window,

cursor on the SaveData.xcos window.

This file has a simple Xcos simulation diagram.
On the SaveData.xcos window,

Hover cursor on RAMP block.

It uses the RAMP block to generate a Ramp signal.
On the SaveData.xcos window,

Hover cursor on CSCOPE block.

And the CSCOPE block to plot it.

Let us see how to record the generated Ramp signal.

On the SaveData.xcos window,

cursor on the SaveData.xcos window

First we will see how to push the values generated by the RAMP block to workspace.
On palette browser,

click on Sinks >> scroll down >> click on TOWS_c.

Go to the Palette browser window.

Click on the Sinks palette.

In the right panel, select the TOWS_c block. This is the To Workspace block.

As per narration Drag and Drop the To Workspace block to the SaveData.xcos window.
On the editing window,

Double-click on the TOWS_c block.

Double-click on the To Workspace block to configure its properties.
On the Scilab Multiple Values Request Window of TOWS_c block

Double click on the Size of Buffer. Text field to highlight it.

The size of buffer is by default set to 128.

This means that 128 values will be saved in the block.

If any more values are passed, the block will overwrite the previous values.

On the Scilab Multiple Values Request Window of TOWS_c block

Double-click on the Variable Name text field to highlight it.

The Variable Name is the name of the variable to which the values are saved.

By default it is set to A.

On the Scilab Multiple Values Request Window of TOWS_c block

Double click on the Inherit Text field to highlight it.

Click on the OK button at the bottom.

Inherit is used to decide whether to take the event input or not.

By default Inherit is set to 0 which means it has to take event input.

Click on the OK button to close this window.

On SaveData.xcos Window,

Connect as per narration.

Let us make the connections.

Select the black input port of the To workspace block.

Connect it to the line joining the RAMP and the CSCOPE block.

On SaveData.xcos Window,

Connect as per narration.

Next, select the red input port of the To workspace block.

Connect it to the line joining the CLOCK_c and the CSCOPE block.

Our file is ready for simulation.

On the SaveData.xcos window,

Click on Start button on the toolbar >> click on OK button on the Warning message.

Let us run this simulation by clicking on the Start button on the toolbar.

A Warning message will appear.

Ignore the message and click on the OK button.

On the Graphic window,

Hover cursor on the graph.

Close the Graphic window.

We can see a straight line with slope 2.

Let’s close the graphic window.

Switch to workspace. Now let us look at the values.

Switch to the workspace.

On the workspace,

Type A >> press Enter.

Let us execute the variable A.

Type A on the workspace and press Enter.

On the workspace window,

Highlight variable A.

Highlight values.

Highlight time.

A is a special variable.

We can either extract values from A or we can extract times from A.

Let us look at the values.

On the workspace window,

Type A.values >> Press Enter.

Type A.values on the workspace.

Press Enter.

On the workspace,

Scroll up to show all the values and Highlight them.

These are all the values from the graph and are now saved in the workspace.
On the workspace,

hover cursor on a new line on the workspace.

Now we need to save these values in a file so that we can share them.
Switch to SaveData.xcos window. Switch back to the SaveData.xcos window.
On the palette browser,

Click on Sinkss >> Click on WRITEC_f block.

To save these values, we will use the WRITEC_f block.

Go to the Palette browser window.

Click on the Sinks palette.

Click on the WRITEC_f block in the right panel.

This is the Write to C binary file block.

As per narration Drag and drop the block on the SaveData.xcos window.
On the SaveData.xcos window,

Double-click on WRITEC_f block.

Double-click on the WRITEC_f block to configure its properties.
On the Scilab Multiple Values Request Window of WRITEC_f block,

Double click on the Input Size Text field to highlight it.

Input Size is the size of our input values.
On the Scilab Multiple Values Request Window of WRITEC_f block

Double click on the Output File Name Text field to highlight it >> Change it to ‘data’

Output File is the name of our output file.

I will name the output file as ‘data ‘.

If no file path is entered, the file will be saved in the Current working directory.

On the Scilab Multiple Values Request window of WRITEC_f block

Double-click on the Output Format Text field to highlight it >> Change it to ‘ d

Output Format is the format of the output file.

By default it is ‘ c ‘. That is, by default, values are saved as integers.

But, I want to save the values as double. So, I will change it to ‘d’.

On the Scilab Multiple Values Request Window of WRITEC_f block,

Double-click on the Buffer Size Text field to highlight it.

Buffer Size is the size of the buffer.
On SaveData.xcos Window,

Connect as per narration.

Let us make the connections.

Select the black input port of the WRITEC_f block.

Connect it to the line joining the RAMP and the CSCOPE block.

On SaveData.xcos Window,

Connect as per narration.

Next, select the red input port of the WRITEC_f block.

Connect it to the line joining the CLOCK_c and the CSCOPE block.

Our file is ready for simulation.

On the SaveData.xcos window,

Click on Start button on the toolbar >> click on OK button on the Warning message.

Let's run the simulation again by clicking on the Start Button on the toolbar.

A Warning message will appear. Ignore the message and click on the OK button.

On the Graphic window,

Hover cursor on the graph.

Close the Graphic window.

We can see the graph.

Let’s close the graphic window.

As per narration. Let's go to the location where we have saved the data file.
On file manager window,

Click on the data file once.

We can see a file named ‘data‘ .

Since it is a binary encoded file we cannot simply read it.

We would need a special block to read this file.

Switch back to SaveData.xcos file Switch back to the SaveData.xcos window.
On the SaveData.xcos window,

Cursor on Toolbar >> Click on Open file option >> Click on LoadData.xcos >> Click on OK

Let us open the file LoadData.xcos

Click on the Open File icon on the Toolbar.

A window will appear.

Go to Downloads folder and select the file LoadData.xcos.

Then click on the OK button.

We will use this file to read our data file.

Adjust the Window accordingly. Let me adjust the window.
On the palette browser,

Click on Sources >> Click on READC_f block.

We will use the READC_f block to read our values.

Go to the Palette browser window.

Click on the Sources palette.

Click on READC_f block in the right panel.

This is the Read from C Binary block.

As per narration Drag and Drop the block on the LoadData.xcos window.

On the LoadData.xcos window,

Double-click on READC_f block

Double-click on the READC_f block to configure its properties.
On the Scilab Multiple Values Request Window of READC_f block

Double-click on the Input File Name Text field to highlight it. >> Change it to data

Input File Name is the name and the path of your data file.

Since my data file was named data I will change it to data.

On the Scilab Multiple Values Request Window of READC_f block

Double-click on the Input Format Text field to highlight it >> Change it to d.

Input format is the format of the data file.

Since the format for my data file is double, I will change it to d.

On the Scilab Multiple Values Request Window of READC_f block,

Double-click on the Buffer Size Text field to highlight it.

Click the OK button .

This is the buffer size.

Let’s close this window by clicking on the OK button.

On LoadData.xcos Window,

Connect as per narration.

Let us make the connections.

Select the black output port of the READC_f block.

Connect it to the black input port of the CSCOPE block.

On LoadData.xcos Window,

Connect as per narration.

Lastly, select the red input port of the READC_f block.

Connect it to the line joining the CLOCK_C & the CSCOPE block.

On the LoadData.xcos window,

Click on Start button on the toolbar

Let’s run this simulation again by clicking on the Start button on the toolbar.
On the Graphic Window,

Hover Cursor on the Graph.

We have a similar graph to the one we had earlier without using the RAMP block.

This is because we have loaded the values from the data file.

Show Slide:

Summary

This brings us to the end of this tutorial. Let us summarise.

In this tutorial, we have learnt to:

  • Save Xcos simulation data values to the workspace.
  • Read and write data in Xcos Simulation using a C binary file
Show Slide:

Assignment

As an assignment,

Create two Xcos simulation files:

  • Use the first for plotting a straight line with slope 3.
  • Push the values to the workspace and save them as a binary encoded file.
  • Create another Xcos simulation to plot a new graph of a straight line with slope 3.
  • Use only the saved data values.
Show Slide: About Spoken Tutorial project The video at the following link summarises the Spoken Tutorial project.

Please download and watch it

Show Slide: Spoken Tutorial Workshops The Spoken Tutorial Project team conducts workshops and gives certificates.

For more details, please write to us.

Show Slide:

Answers for THIS Spoken Tutorial

Please post your timed queries in this forum.
Show Slide: FOSSEE Forum Please post your general and technical queries on Scilab in this forum.
Show Slide:

Textbook Companion project.

The FOSSEE team coordinates the Textbook Companion project.

We give Certificates and Honorarium to the contributors.

For more details, please visit this website.

Show Slide: Lab Migration The FOSSEE team coordinates the Lab Migration project.

For more details, please visit this website.

Show Slide: Acknowledgement Spoken Tutorial and FOSSEE projects are funded by the Ministry of Education, Government of India.
Show Slide: Thank you This is Utkarsh Anand, FOSSEE intern 2021, IIT Bombay signing off.

Thanks for joining.

Contributors and Content Editors

Nancyvarkey, PoojaMoolya, Utkarsha