Difference between revisions of "Scilab/C4/Loading-and-saving-data-in-Xcos/English"
(Created page with "'''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''...") |
|||
Line 7: | Line 7: | ||
− | {| | + | {| border=1 |
+ | | '''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: | ||
|- | |- | ||
+ | | | ||
+ | Show Slide: | ||
+ | |||
+ | '''System Requirements''' | ||
+ | | To record this tutorial, I am using | ||
|- | |- | ||
+ | | | ||
+ | Show Slide: | ||
+ | |||
+ | '''Pre-requisites''' | ||
+ | | To follow this tutorial, you should have | ||
|- | |- | ||
+ | | | ||
+ | Show Slide: | ||
+ | |||
+ | '''Code Files''' | ||
+ | | | ||
|- | |- | ||
+ | | 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 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 block on 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 '''OK''' 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.''' | ||
+ | | | ||
+ | Now 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. | ||
+ | | Let's switch back to the '''SaveData.xcos''' window. | ||
|- | |- | ||
+ | | | ||
+ | On the '''palette browser''', | ||
+ | |||
+ | Click on '''Sinkss''' >> Click on '''WRITEC_f''' block. | ||
+ | | | ||
+ | To save the 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 data 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.''' | ||
+ | |||
+ | |||
+ | |||
+ | 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 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 | ||
+ | | Let's 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. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | 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 us run this simulation 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: | ||
|- | |- | ||
+ | | | ||
+ | Show Slide: | ||
+ | |||
+ | '''Assignment''' | ||
+ | | | ||
+ | As an assignment, | ||
+ | |||
+ | |||
+ | |||
+ | Create two '''Xcos''' simulation files: | ||
|- | |- | ||
+ | | 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 site. | ||
|- | |- | ||
+ | | | ||
+ | Show Slide: '''Lab Migration''' | ||
+ | | | ||
+ | The FOSSEE team coordinates the Lab Migration project. | ||
+ | |||
+ | |||
+ | |||
+ | For more details, please visit this site. | ||
|- | |- | ||
+ | | | ||
+ | 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. | ||
|} | |} | ||
''' ''' | ''' ''' |
Revision as of 18:34, 6 August 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: |
Show Slide: System Requirements |
To record this tutorial, I am using |
Show Slide: Pre-requisites |
To follow this tutorial, you should have |
Show Slide: Code Files |
|
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 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 block on 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 OK 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. |
Now 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. |
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. | Let's switch back to the SaveData.xcos window. |
On the palette browser, Click on Sinkss >> Click on WRITEC_f block. |
To save the 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 data 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.
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 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 | Let's 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.
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 us run this simulation 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: |
Show Slide: Assignment |
As an assignment,
Create two Xcos simulation files: |
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 site. |
Show Slide: Lab Migration |
The FOSSEE team coordinates the Lab Migration project.
For more details, please visit this site. |
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. |