PC817 Library for Proteus
Hello friends, I hope you all are doing great. In today's tutorial, I am going to share a new
PC817 Library for Proteus. PC817 is an optocoupler / optoisolator, which is used for electrical isolation between components or modules. It's normally used after Microcontroller Pins so that back emf doesn't burn them. You should also have a look at
Introduction to PC817, I have shared its complete details there.
PC817 is used a lot in Embedded projects but is not available in Proteus, so our team has designed it for the first time. Using this Library, now you can easily simulate this optocoupler in your Proteus simulations. So, let's get started with How to download & install PC817 Library for Proteus:
PC817 Library for Proteus
- First of all, download this PC817 Library for Proteus by clicking the below button:
[dt_default_button link="https://www.theengineeringprojects.com/ArduinoProjects/PC817 Library for Proteus.zip" button_alignment="default" animation="fadeIn" size="medium" default_btn_bg_color="" bg_hover_color="" text_color="" text_hover_color="" icon="fa fa-chevron-circle-right" icon_align="left"]Download Proteus Library[/dt_default_button]
- It's a zip file, which will have a Proteus Library folder.
- Open this folder, and you will find these 2 Library files in it:
- OptocouplersTEP.IDX
- OptocouplersTEP.LIB
- Place these Library Files in the Library folder of your Proteus software.
Note:
- Now open your Proteus ISIS software or restart it if its already open.
- In the components search box, make a search for PC817.
- If everything goes fine, then you will get results as shown in below figure:
- Now place this PC817 in your workspace.
- Default optocoupler available in Proteus contains 5 Pins but this PC817 has 4 Pins, as shown in below figure:
- I have shown both optocouplers in above figure.
- Now let's design a simple circuit to have a look at How it works:
- So, connect three LogicState and one LED with PC817, as shown in below figure:
- Now run your Proteus Simulation and change the states of your buttons.
- Both On & Off states of PC817 are shown in below figure:
- So, that's How you can easily simulate PC817 in Proteus.
I hope this PC817 Library will help you in your Engineering Projects. If you got into any trouble, then ask in comments and we will help you out. Thanks for reading, take care and have fun !!! :)
Create a Custom Filter in ASP.NET MVC
Hello friends, I hope you all are doing great. In today's tutorial, we will have a look at How to Create a Custom Filter in ASP.NET MVC. It's our 10th tutorial in ASP.NET MVC series. In our previous tutorial, we have cleared our concepts about
Filters in ASP.NETMVC and we have also implemented one built-in filter of ASP.NET MVC.
Now, its time to have a look at How to Create a Custom Filter in ASP.NET MVC, in which you can specify your own authentications or handling etc. In our ASP.NET applications, we have use custom built filters a lot for different purposes. So, let's have a look at How to Create a Custom Filter in ASP.NET MVC:
Create a Custom Filter in ASP.NET MVC
- In ASP.NET MVC, custom filters are handled by a base class named as ActionFilterAttribute.
- This ActionFilterAttribute class implements both IActionFilter & IResultFilter.
- Although ASP.NET MVC has numerous built-in filters but in many cases, there comes a need for custom rules or handles.
- In such cases, we need to design our custom Filters using ActionFilterAttribute.
- In your Solution Explorer, right click on the Main project and click on Add and then click on New Folder.
- It will create a New Folder in your project, rename it to ActionFilter.
- Now, right click on this ActionFilter folder and click Add and then Class, as we want to add new class in it, as shown in below figure:
- It will open up a new pop up window, where you need to select class and then give it a name.
- I have given a name TEPCustomActionFilter.cs to my Filter class file, as shown in below figure:
- Now click the Add Button and a new class will be added in your ActionFilter folder and will also open up in your workspace.
- It will have some default code in it, as shown in below figure:
- Let's add some code in our newly created filter class, as shown in below figure:
- We need to derive this class from ActionFilterAttribute that why I have extended the class name.
- We need to include System.Web.Mvc in order to use ActionFilterAttribute.
- In the class, I have created a simple function in which I am displaying a text on the output debug pane, after the execution of my project.
- So, we have created our custom filter, now it's time to add it in our StudentController which we have created in Tut # 6: Create a new Controller in ASP.NET MVC.
- Open your StudentController.cs file and place this filter in it, as shown in below figure:
- First of all, we need to add our package TEPwebApp.ActionFilter, ActionFilter is the name of our folder we created for our custom filter.
- Now before the StudentController class, place the code for our newly created custom Filter [TEPCustomActionFilter].
- Now run your project and after website opened in the browser, stop your project and check your Output Pane.
- You will find the text, as shown in below figure:
- I have highlighted our Text in the above figure.
- So, our filter has executed after the StudentController class and it has displayed the info.
- Such Filters are used for listening purposes, we can listen different types of data through them.
- Have a look at this video to get better understanding of How to Create Custom Filter in ASP.NET MVC:
So, that was all about How to Create a Custom Filter in ASP.NET MVC. I am just focusing on the basic details here, we need to clear our concepts first and with practice we can become pro. Will meet you guys in the next tutorial, take care and have fun !!!
Filters in ASP.NET MVC
Hello friends, I hope you all are doing great. In today's tutorial, we are gonna have a look at
Filters in ASP.NET MVC. It's our 9th tutorial in ASP.NET MVC series. It's also a new concept which is essential to discuss as it's used almost in every form submission.
We have already understand Controllers in ASP.NET MVC and we know that Controllers have action methods in it which are directly assigned to respective Views, which are then displayed to the user. But in some cases, we have to place some checks (called Filters) before or after this action method called. So, let's have a look at these Filters in ASP.NET MVC in detail:
Filters in ASP.NET MVC
- Filters are attributes which we can use before or after action method called in a Controller.
- Controllers are normally directly connected with their respective Views in the action method, but in some case we need to place some logic i.e. user authentication or IP address verification etc. before the View is displayed.
- In order to handle such intermediate logic or verification, ASP.NET MVC uses some Filters.
- Filters are simple custom classes where we can write our code and can assign different attributes or verification to our action method in Controllers.
- Let's have a look at the types of Filters supported by ASP.NET MVC:
Types of Filters in ASP.NET MVC
- ASP.NET MVC framework offers four types of Filters.
- Depending on the type of filters, they may occur before or after the action method.
- Let's have a look at these Filters and their description:
Types of Filters in ASP.NET MVC |
No. |
Type |
Description |
Interface |
1. |
Authorization .Filters |
These Filter performs some user authorizations or verification before action methods. |
IAuthorizationFilter |
2. |
Action Filters |
These Filters assign certain actions before or after methods. |
IActionFilter |
3. |
Result Filters |
These filters handles the View results and assigns some actions to it. |
IResultFilter |
4. |
Exception Filters |
These filters control the exceptions, if occurred during execution. |
IExceptionFilter |
- These four Filters always occur from top to Bottom as given in above table i.e. Authorization Filter will run first and action Filter will run afterwards and so on.
- This order can't be reversed or changed.
- ASP.NET MVC has some built-in Filters designed in it, some most commonly used built-in Filters are:
Built-in Filters in ASP.NET MVC |
No. |
Name |
Description |
Filter Type |
1. |
OutputCache |
This Filter stores / caches the web data for a specified amount of time. |
Result Filters |
2. |
HandleError |
This Filter handles different exceptions or errors generated during execution of MVC Application. |
Exception Filters |
3. |
Authorize |
This Filter is used for user verification or authorization before the action method. |
|
- Now let's have a look at How to use OutputCache Filter in ASP.NET MVC:
OutputCache Filter in ASP.NET MVC
- We will cover all these filters in our coming tutorials, as they will be required all along, but for now we will have a look at How to use OutputCache Filter for understanding the Filter concept.
- As I have mentioned earlier OutputCache is a built-in filter and it is used to store the web data for a specified time.
- It helps in saving the load time, suppose you are updating your site continuously for some live data, then you can place some checks like if a user refresh the page before 10 sec then upload the page from cache.
- In such cases you can use OutputCache, let's implement this logic in our StudentController, which we have created in Tut # 06: Create a New Controller in ASP.NET MVC.
- So, open your StudentController File and add the code in it, as shown in below figure:
- You can see in the above figure that I have created a Get method and I am simply displaying the current Date and Time on the page.
- Above this Get method, I have also added OutputCache Filter and I have assigned it a duration of 10 sec, so it will cache for 10 seconds.
- Now remove this Output Cache line, and refresh your page and on each refresh the time will change and it will get the current date and time.
- Now let's add this OutputCache line and give it a duration of 10 sec.
- If you refresh your page now, the time will not change, but if you refresh it after 10 seconds then it will change and get the new date and time.
- Here's a screenshot of our Student/Get page:
- Now you have seen we have placed the Filter code before action method so this OutputCache filter is executed before our Controller's action method.
- Have a look at this video, which will give you better understanding of OutptuCache:
So, that was all about Filters. I hope you have understood the basic concept of filters and have an idea about working of built-in filters. In our coming tutorial, we will have a look at How to create Custom Filters in ASP.NET MVC. So, will meet you in next tutorial, take care & have fun !!!
URL Routing in ASP.NET MVC
Hello friends, I hope you all are doing great. In today's tutorial, we will have a look at
URL Routing in ASP.NET MVC. It's the 8th tutorial in this ASP.NET MVC series. Today's tutorial is on a new concept in asp.net and it's essential to understand URL routing before going any further.
URL Routing is actually a part of core ASP.NET but MVC applications also use it. URL Routing is implemented by System.Web.Routing and ASP.NET MVC uses System.Web.Routing. So, let's have a look at what's URL Routing in ASP.NET MVC:
URL Routing in ASP.NET MVC
- URL Routing is used for directing the HTTP request (generated by the user) to the respective controller in ASP.NET MVC.
- Whenever a user types some url in the browser and hit enter then an HTTP request is generated and this HTTP request is then handled by the controller.
- This assigning of HTTP request to controller is done by URL Routing.
- In ASP.NET MVC application, a default Routing file is automatically created in the project.
- In your Solution Explorer, Click on the folder App_Start.
- In this folder, you will find a file named RouteConfig.cs that's our URL Routing file, all our settings are saved in it.
- So, open this file in your workspace, as shown in below figure:
- Now you can see this RouteConfig.cs file in above figure, it has some default code in it.
- Let's have a close look at this code and understand it:
- In this file, we have a MapRoute extension method of RouteCollection, which is a property of RouteTable class.
- In this MapRoute method, we have three lines of codes, This code is actually setting the URL for Home Page i.e. the index file will open up when you open Home Page.
- First line is name of our Route and in this case its Default.
- The second line specifies the URL parameters and you can see it specifies the url syntax, first we have the Controller, after that action from that Controller, and the third parameter is id.
- So, actually we want to assign the URL request to some Controller and then assign a action from that controller.
- In the 3rd line, we have assigned default parameters to our variables in URL.
- So, the Controller we have here is Home and the action we have assigned is Index and id is optional for now.
- Now if you recall from our previous tutorial Controllers in ASP.NET MVC that in our HomeController file we have a method called Index, as shown in below figure:
- So, I hope you have understood How this URL Routing is working.
- Let me summarize it, by default we have a URL Routing File and it has the MapRoute extension method for the Home Page and from HomeController file index action is assigned to the URL.
- This index action is further assigned to index View and thus it open the index page.
- Now, let's say you want to change your Home Page from index to About.
- So, you need to do these changes in the Route file:
- As you can see in the above code that I have just changed the action from index to About.
- If you remember, our HomeController also has another method About, which is assigned to About View.
- So, now my URL Route will open the Home Controller and then will run the About method and in turn About View will open up for the user.
- Now when you open the Home Page of your site then About Page will be open up.
- Here's the video demonstration of URL Routing ASP.NET MVC:
So, that was all about URL Routing in ASP.NET MVC. I hope you have enjoyed today's tutorial. If you have any questions, then ask in comments. Will meet you guys in the next tutorial, take care !!!