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

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 5: Line 5:
 
'''Keywords: Xcos,TOWS_c, C_binary, workspace, read, write, data file, scilab'''
 
'''Keywords: Xcos,TOWS_c, C_binary, workspace, read, write, data file, scilab'''
  
 
+
{|border=1
 
+
! '''Visual Cue'''
{| border=1
+
! '''Narration'''
| '''Visual Cue'''
+
| '''Narration'''
+
 
|-
 
|-
 
|
 
|
Line 23: Line 21:
 
|
 
|
 
In this tutorial, we will learn how to:
 
In this tutorial, we will learn how to:
 +
 +
<ul>
 +
<li><blockquote><p>Save '''Xcos''' simulation data values to the '''workspace'''.</p></blockquote></li>
 +
<li><blockquote><p>Read and write data in '''Xcos''' simulation using a '''C binary''' file</p></blockquote></li></ul>
 
|-
 
|-
 
|
 
|
Line 28: Line 30:
  
 
'''System Requirements'''
 
'''System Requirements'''
| To record this tutorial, I am using
+
|
 +
To record this tutorial, I am using
 +
 
 +
<ul>
 +
<li><blockquote><p>'''Ubuntu 18.04 OS''' and</p></blockquote></li>
 +
<li><blockquote><p>'''Scilab 6.1.0 version'''</p></blockquote></li></ul>
 
|-
 
|-
 
|
 
|
Line 34: Line 41:
  
 
'''Pre-requisites'''
 
'''Pre-requisites'''
| To follow this tutorial, you should have
+
|
 +
To follow this tutorial, you should have
 +
 
 +
<ul>
 +
<li><blockquote><p>Basic knowledge of '''Scilab and Xcos.'''</p></blockquote></li>
 +
<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>
 +
<li><blockquote><p>The files used in this tutorial are provided in the '''Code files''' link.</p></blockquote></li>
 +
<li><blockquote><p>Please download and extract the files.</p></blockquote></li>
 +
<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.
Line 46: Line 62:
 
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'''.
 
 
  
 
A window will appear.
 
A window will appear.
 
 
  
 
Go to the '''Downloads''' folder and select the file '''SaveData.xcos'''.
 
Go to the '''Downloads''' folder and select the file '''SaveData.xcos'''.
 
 
  
 
Then click on the '''OK''' button.
 
Then click on the '''OK''' button.
Line 78: Line 82:
 
|
 
|
 
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.
Line 86: Line 88:
 
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.
+
 
|-
 
|-
 
|
 
|
Line 102: Line 103:
 
|
 
|
 
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.
Line 111: Line 110:
  
 
cursor on the '''SaveData.xcos window'''
 
cursor on the '''SaveData.xcos window'''
| First we will see how to push 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 block on the '''SaveData.xcos '''window'''.'''
+
| '''Drag and Drop''' the '''TOWS_c''' 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.
Line 141: Line 134:
 
|
 
|
 
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.
Line 158: Line 145:
 
|
 
|
 
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.'''
Line 171: Line 154:
 
|
 
|
 
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.
Line 182: Line 161:
 
'''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.
  
 
+
Click on the '''OK''' button to close this window.
By default Inherit is set to '''0 '''which means it has to take event input.
+
 
+
 
+
 
+
Click on '''OK''' to close this window.
+
 
|-
 
|-
 
|
 
|
Line 196: Line 171:
 
|
 
|
 
Let us make the connections.
 
Let us make the connections.
 
 
  
 
Select the '''black input port''' of the '''TOWS_c''' block.
 
Select the '''black input port''' of the '''TOWS_c''' 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.
+
 
|-
 
|-
 
|
 
|
Line 210: Line 181:
 
Connect as per narration'''.'''
 
Connect as per narration'''.'''
 
|
 
|
Next, Select the '''red input port''' of the '''TOWS_c '''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.
Line 222: Line 189:
 
|
 
|
 
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.'''
Line 229: Line 194:
 
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'''.
  
 
+
An '''Warning message''' will appear.
 
+
An '''Warning message''' will appear.  
+
  
 
Ignore the message and click on the '''OK''' button.
 
Ignore the message and click on the '''OK''' button.
Line 237: Line 200:
 
|
 
|
 
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.
Line 257: Line 212:
 
|
 
|
 
Now let us look at the values.
 
Now let us look at the values.
 
 
  
 
Switch to the '''workspace'''.
 
Switch to the '''workspace'''.
Line 264: Line 217:
 
|
 
|
 
On the '''workspace''',
 
On the '''workspace''',
 
 
  
 
Type '''''A''''' &gt;&gt; press '''Enter.'''
 
Type '''''A''''' &gt;&gt; press '''Enter.'''
 
|
 
|
Now 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'''.
Line 277: Line 226:
 
|
 
|
 
On the '''workspace''' window,
 
On the '''workspace''' window,
 
 
  
 
Highlight '''variable A.'''
 
Highlight '''variable A.'''
 
 
  
 
Highlight '''values.'''
 
Highlight '''values.'''
 
 
  
 
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.
Line 305: Line 242:
 
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.'''
Line 326: Line 261:
 
|-
 
|-
 
| Switch to '''SaveData.xcos''' window.
 
| Switch to '''SaveData.xcos''' window.
| Let's switch back to the '''SaveData.xcos''' window.
+
| Switch back to the '''SaveData.xcos''' window.
 
|-
 
|-
 
|
 
|
Line 333: Line 268:
 
Click on '''Sinkss''' &gt;&gt; Click on '''WRITEC_f''' block.
 
Click on '''Sinkss''' &gt;&gt; Click on '''WRITEC_f''' block.
 
|
 
|
To save the 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.
  
 
+
This is the '''Write to C binary file''' block.
Click on the''' WRITEC_f''' block in the right panel.
+
 
+
 
+
 
+
This is the '''Write to C binary file '''block.
+
 
|-
 
|-
 
| As per narration
 
| As per narration
Line 361: Line 288:
 
|-
 
|-
 
|
 
|
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.
Line 369: Line 294:
 
|-
 
|-
 
|
 
|
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.'''
Line 388: Line 307:
 
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.
  
 
+
But, I want to save the values as '''double.''' So''',''' I will change it to '''‘d’.'''
By default it is '''‘ c ‘. '''That is, by default, values are saved as integers.
+
 
+
 
+
 
+
But, I want to save the data 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.
Line 411: Line 322:
 
|-
 
|-
 
|
 
|
On the '''Scilab Multiple Values Request '''Window of '''WRITEC_f '''block,
+
On the '''Scilab Multiple Values Request''' Window of '''WRITEC_f''' block,
 
+
 
+
  
 
Click on the '''OK''' button.
 
Click on the '''OK''' button.
|  
+
|
 
|-
 
|-
 
|
 
|
Line 424: Line 333:
 
|
 
|
 
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.
+
 
|-
 
|-
 
|
 
|
Line 438: Line 343:
 
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.
Line 457: Line 356:
 
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.
 
+
An '''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.
Line 491: Line 378:
 
|
 
|
 
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
| Let's 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'''.
 
 
  
 
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.
Line 538: Line 409:
 
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.
Line 564: Line 427:
 
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'''.
Line 582: Line 441:
 
|
 
|
 
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'''.
Line 595: Line 450:
 
|
 
|
 
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 .
Line 606: Line 457:
 
This is the buffer size.
 
This is the buffer size.
  
 
+
Let’s close this window by clicking on the '''OK''' button.
 
+
 
+
 
+
 
+
 
+
 
+
 
+
 
+
 
+
Close this window by clicking on the '''OK''' button.
+
 
|-
 
|-
 
|
 
|
Line 624: Line 465:
 
|
 
|
 
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.
+
 
|-
 
|-
 
|
 
|
Line 640: Line 477:
 
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 us run this simulation 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.
Line 671: Line 501:
 
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:
  
 
+
<ul>
In this tutorial, we have learnt to:
+
<li><blockquote><p>Save '''Xcos''' simulation data values to the '''workspace'''.</p></blockquote></li>
 +
<li><blockquote><p>Read and write data in '''Xcos''' Simulation using a '''C binary''' file</p></blockquote></li></ul>
 
|-
 
|-
 
|
 
|
Line 682: Line 514:
 
As an assignment,
 
As an assignment,
  
 +
Create two '''Xcos''' simulation files:
  
 
+
<ul>
Create two '''Xcos''' simulation files:
+
<li><blockquote><p>Use the first for plotting a straight line with slope 3.</p></blockquote></li>
 +
<li><blockquote><p>Push the values to the workspace and save them as a binary encoded file.</p></blockquote></li>
 +
<li><blockquote><p>Create another '''Xcos''' simulation to plot a new graph of a straight line with slope 3.</p></blockquote></li>
 +
<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
Line 697: Line 531:
 
|
 
|
 
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.
Line 709: Line 541:
 
|-
 
|-
 
| 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.
 +
 
 
|-
 
|-
 
|
 
|
Line 717: Line 551:
 
|
 
|
 
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.
  
 
+
For more details, please visit this website.
 
+
For more details, please visit this site.
+
 
|-
 
|-
|
+
| 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 site.
+
 
|-
 
|-
|
+
| 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.
 
|-
 
|-
Line 742: Line 568:
 
|
 
|
 
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.
 
|}
 
|}
 
''' '''
 

Revision as of 21:17, 4 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 TOWS_c block to the SaveData.xcos window.

On the editing window,

Double click on the TOWS_c block.

Double click on the TOWS_c 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 TOWS_c 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 TOWS_c 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.

An 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 the Scilab Multiple Values Request Window of WRITEC_f block,

Click on the OK button.

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