. Net micro framework simulators-Basic Principles

Source: Internet
Author: User

Use the. NET micro framework Simulator-Basic Principles

 

Abstract: virtual instrument (VI) technology plays an increasingly important role in many high-cost industrial projects. In the development of electronic products, various simulators also provide convenience for developers and increase productivity. This article introduces Microsoft's latest embedded development framework. Net micro framework simulator. Describes the basic working processes and principles of the simulator startup process, link components, and registration information.

Keywords

. Net micro framework, hardware emulator, start up, component, registry

 

. Net MFIntroduction to simulators

 

The. net mf simulator is a Windows operating environment of. Net mf clr. The Core Components (execution engine, type system, GC, etc.) and basic class libraries are the same as those running on the actual device. The difference between the two lies in the Hal layer (hardware abstract layer ). The Hal layer of the simulator is not actually a hardware device driver, but instead a driver provided by windows. This fully demonstrates the high separation between the middle layer and the layer of the MF architecture, and provides the foundation for the authenticity and accuracy of the simulation.

Describes the logical structure of the. NET micro framework simulator.

 

Emulator components are components of simulators. You can use them to develop custom hardware simulators. Here, MVP Liu Hongfeng has some good examples of custom simulators:

 

Research on. NET micro framework-Simulator Transformation
Http://blog.csdn.net/yefanqiu/archive/2007/10/31/1860020.aspx

Research on. NET micro framework-Simulator with IO
Http://blog.csdn.net/yefanqiu/archive/2007/12/30/2005462.aspx

Research on. NET micro framework-Simulator with AD
Http://blog.csdn.net/yefanqiu/archive/2007/12/31/2006197.aspx

Research on. NET micro framework-Simulator with I2C bus
Http://blog.csdn.net/yefanqiu/archive/2007/12/31/2006370.aspx

 

The configuration engine is used to assemble components at runtime. It uses XML to describe various configuration parameters of the hardware model.

 

 

Startup Process

 

During debugging, you only need to select the simulator as the deployment target in the project properties. During the deployment, the simulator will be automatically called and run our program, but this process masks the details of the simulator startup .. Net micro framework simulator is also a. Net (usually Windows form) application, but the simulator adds components (component) and xml configuration file (emulator. config) content. When the simulator is started:

 

1. Load default Components

The loaddefacomponcomponents () virtual method of the simulator is called. It creates the default basic component of the simulator by calling a series of registercomponent methods. You can also configure, replace, or delete these default components through the configuration file (emulator. config. In the code, we can also access these default components through a series of attributes of the emulator class.

 

2. Read the configuration file

After the default component is constructed, the configuration engine of emulator reads the xml configuration file (emulator. config ). Components described in the configuration file are created and registered as required. In this case, the configure (system. xml. xmlreader reader) method of the emulator class is called to parse the type from the xml configuration file.

 

3. install components

After the previous two steps, all components have been configured. At this time, the system will call the setupcomponent method of the emulator and custom component classes to assemble the previously created components.

 

4. initialize the component

After all components are installed, the initializecomponent method of the emulator class and emulatorcomponent class will be called to initialize each component.

 

5. Load the. NET micro Framework Assembly

 

6. Run the simulator

 

In actual development, in general, configure, setupcomponent, and initializecomponent do not need to be called by programmers in the Code unless you want to develop your own simulator components.

 

 

Register Components

 

You need to call the registercomponent method to register the simulator component by programming. As mentioned above, the configuration engine of the simulator calls this method in the config phase. The registercomponent method is actually called internally when loaddefacomponcomponents () is called. Using reflector, we can see that its content is as follows:

 

Protected virtual void loaddefacomponcomponents ()
{
This. registercomponent (New Hal ());
This. registercomponent (New comportcollection ());
This. registercomponent (New gpiocollection ());
This. registercomponent (New spibus ());
This. registercomponent (New memorymanager ());
This. registercomponent (New timingservices ());
This. registercomponent (New i2cbus ());
This. registercomponent (New serialportcollection ());
This. registercomponent (New namedpipeserver ());
}

 

In fact, loaddefacomponcomponents () is registered for the default component.

For manual registration, you must note that if one component is included in another component, you must provide a method to overload the parent component to registercomponent when registering the child component. When unregistercomponent is called to remove a component, all child components linked to it are automatically deleted. For example, the memorymanager component has two sub-components: rammanager and flashmanager. When memorymanager is removed, rammanager and flashmanager are also removed.

 

 

Access registered components

 

Registered simulator components can be accessed through the findcomponentbyid method of the emulator class. We often call this function to initialize the specified component. For example, in the sampleemulator provided by the SDK, we can see a function like this:

 

/** // <Summary>

/// Helper method to initialize buttons.

/// </Summary>

/// <Param name = "button"> the button to be initialized. </param>

/// <Param name = "componentid">

/// The string identifying the button,

/// Found in the config file

/// </Param>

/// <Param name = "key"> the key that this button shocould respond to. </param>

Private void initializebutton (Button button, string componentid, keys key)

{

Button. Port = _ emulator. findcomponentbyid (componentid) as gpio. gpioport;

Button. Key = key;

}

 

Findcomponentbyid also has a common purpose that is used to check the necessary components during initialization. The following code is used:

 

Public override void initializecomponent ()

{

Base. initializecomponent ();

// The following two lines of code check whether the simulator has a component named "pin_down ".

// Check whether the component type is gpioport.

If (findcomponentbyid ("pin_down") as gpioport = NULL)

Throw new exception ("the component 'pin _ low' is required by the emulator .");

// Start the UI thread

Thread uithread = new thread (startform );

Uithread. Start ();

}

 

Now, I am writing this article for the time being. There are still many things worth exploring about the simulator. You are welcome to contact me if you are interested.

 

References:

 

  • MS. Net micro Framework Team
  • Windows Embedded blog from China
  • MVP Liu Hongfeng's blog
  • . Net MF China's resource site winbile. Net (being revised)
  • Windows Embedded team blog in the blog Park
  • [Books] embedded programming with the. NET micro framework
  • [Books] expert. Net micro framework
  •  

     

    Enjoy!

     

    Yellow winter

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.