h. Controlling PIC18F2xJ50 via an ASP.NET website

Controlling a microcontroller via an ASP.NET website might seem obvious and simple to implement, but there are many traps that might spoil the first excitement about the promising technology. Though designing an ASP.NET application in Visual Basic or Visual C# is similar to designing a Windows application, there are some important rules to follow. Windows application graphics user interface (GUI) instantly relays messages about particular graphics components states to appropriate handler functions. However, a web application works through a web application server, like Microsoft Internet Information Server (IIS). A programmer must decide when it is the right time to commit data to the IIS. Therefore, it is very important to set each GUI component properties right. Our examples use checkboxes (on Default.aspx form), which are originally configured not to immediately report their state changes to the IIS, so their AutoPostBack properties must be set to TRUE. This causes Internet Explorer on a client computer to send information immediately after a check box checked state changes.

Another concern is connecting to a microcontroller. A web application has to serve many clients at the same time, but all the clients have to address the same microcontroller. It is therefore important to connect to the microcontroller only at web application level at startup. A microcontroller object must be created as a shared object in Visual Basic or as a static object in Visual C#:

VB.NET:

Shared PIC As New SVLib_PIC18F24J50.SVPICAPI

C#.NET:

static SVLib_PIC18F24J50::SVPICAPI PIC;

Next, a shared variable named connected has to be defined on the application level, so that all the sessions can see it. The Page_Load handler then opens the communication channel to the microcontroller only at the first communication request to the microcontroller by the first opened session. The application also shows the digital and analog inputs values. However, automatic refreshing of the values is not possible with a simple web application. Press “Refresh” button any time you want to see refreshed values of the inputs and outputs.

Testing and installing the sample ASP.NET application

The application requires ASP.NET functionality installed on the IIS. It also needs .NET framework 4.0 installed in the server or on the development workstation. 32-bit (Simple PIC18F2xJ50 ASP.NET4 example x86.zip) and 64-bit (Simple PIC18F2xJ50 ASP.NET4 example x64.zip) sample applications in the Downloads section were developed in Visual Studio 2010 and they should also work on Visual Studio 2012. But it is important to know that the Visual Studio 2010.NET has an inbuilt 32-bit express IIS therefore a 32-bit version of the application must be used for testing and deployment into 32-bit environments. However, a 64-bit Windows IIS would not support 32-bit DLLs. Therefore the 64-bit sample application includes a new 64-bit version of SVLIB_PIC18F24J50 v2.5.NET4.dll.

Installing ASP.NET application is a standard procedure: Create a folder on the computer server with IIS. Go to the development workstation expand the Build menu and click “Publish…”. The easiest was to deploy ASP.NET application on server is via “File system” method. Set target location on the shared server disc and click Publish button. Now, create a new website on the IIS and indicate the new ASP.NET application location. Please, note that the controlled board must be connected and installed on the server prior to starting the web application. If you disconnect the control board the application must be restated upon reconnection.

The following pictures briefly depict the application deployment procedure. Please, see the Microsoft original documentation for more details.