Configuring Emulator Components

This topic introduces techniques for using the XML configuration engine to load and initialize the Microsoft® .NET Micro Framework emulator components in your device emulator.

What Is the XML Configuration Engine?

The XML configuration engine is a module in the extensible emulator that uses information in an XML file to specify two types of information: the information used to configure the emulator, and the data needed to load and initialize the emulator components required by your emulator. When you create your emulator, you must build your emulator components and then write an XML configuration file that contains these two types of information.

Initializing the Emulator

Your XML configuration file must begin and end with the <Emulator> and </Emulator> tags, respectively. Inside these tags, you use the <Types> tag to specify the objects that your emulator uses, as shown in the following example:

      <?xml version="1.0" encoding="utf-8"?>
      <Emulator>
        <Types>
          <GpioCollection>Microsoft.SPOT.Emulator.Gpio.GpioCollection</GpioCollection>
          <GpioPort>Microsoft.SPOT.Emulator.Gpio.GpioPort</GpioPort>
          <MemoryManager>Microsoft.SPOT.Emulator.Memory.MemoryManager</MemoryManager>
          <RamManager>Microsoft.SPOT.Emulator.Memory.RamManager</RamManager>
          <FlashManager>Microsoft.SPOT.Emulator.Memory.FlashManager</FlashManager>
          <FlashSector>Microsoft.SPOT.Emulator.Memory.FlashSector</FlashSector>
          <TimingServices>Microsoft.SPOT.Emulator.Time.TimingServices</TimingServices>
          <LcdDisplay>Microsoft.SPOT.Emulator.Lcd.LcdDisplay</LcdDisplay>
          <ComPort>Microsoft.SPOT.Emulator.Com.ComPortToMemoryStream</ComPort>
          <GpioSample>Microsoft.SPOT.Emulator.Sample.GpioSampleComponent, Microsoft.SPOT.Emulator.Sample.GPIOSample</GpioSample>
          <ComSample>Microsoft.SPOT.Emulator.Sample.ComSampleComponent, Microsoft.SPOT.Emulator.Sample.ComSample</ComSample>
          <LCDSample>Microsoft.SPOT.Emulator.Sample.LCDSampleComponent, Microsoft.SPOT.Emulator.Sample.LCDSample</LCDSample>
          <SocketSample>Microsoft.SPOT.Emulator.Sample.SocketSampleComponent, Microsoft.SPOT.Emulator.Sample.SocketSample</SocketSample>
        </Types>

        <!--More configuration info goes here-->
      </Emulator>
    

The preceding example uses the <Types> tag to state that it employs emulator components such as memory managers, the timing services manager, and the LCD manager. Each of these components, and the others listed in the example, must be configured before your program can use them.

Note

You can define custom XML tags to use between the <Types> and </Types> tags.

Although the configuration file contains some predefined tags, you can define custom XML tags to use between the <Types> and </Types> tags. For instance, the preceding example defines tags such as <LCDSample> and <SocketSample>.

Your XML file must keep its emulator component configuration information between the <EmulatorComponents> and </EmulatorComponents> tags. For each tag you use in the <Types> section of the configuration file, you must have a corresponding tag in the <EmulatorComponents> section. For instance, the preceding example uses the <MemoryManager> tag in its <Types> section. Therefore, it must have a <MemoryManager> tag in its <EmulatorComponents> section, as in the following example:

      <?xml version="1.0" encoding="utf-8"?>
      <Emulator>
        <Types>
          <GpioCollection>Microsoft.SPOT.Emulator.Gpio.GpioCollection</GpioCollection>
          <GpioPort>Microsoft.SPOT.Emulator.Gpio.GpioPort</GpioPort>
          <MemoryManager>Microsoft.SPOT.Emulator.Memory.MemoryManager</MemoryManager>
          <RamManager>Microsoft.SPOT.Emulator.Memory.RamManager</RamManager>
          <FlashManager>Microsoft.SPOT.Emulator.Memory.FlashManager</FlashManager>
          <FlashSector>Microsoft.SPOT.Emulator.Memory.FlashSector</FlashSector>
          <TimingServices>Microsoft.SPOT.Emulator.Time.TimingServices</TimingServices>
          <LcdDisplay>Microsoft.SPOT.Emulator.Lcd.LcdDisplay</LcdDisplay>
          <ComPort>Microsoft.SPOT.Emulator.Com.ComPortToMemoryStream</ComPort>
          <GpioSample>Microsoft.SPOT.Emulator.Sample.GpioSampleComponent, Microsoft.SPOT.Emulator.Sample.GPIOSample</GpioSample>
          <ComSample>Microsoft.SPOT.Emulator.Sample.ComSampleComponent, Microsoft.SPOT.Emulator.Sample.ComSample</ComSample>
          <LCDSample>Microsoft.SPOT.Emulator.Sample.LCDSampleComponent, Microsoft.SPOT.Emulator.Sample.LCDSample</LCDSample>
          <SocketSample>Microsoft.SPOT.Emulator.Sample.SocketSampleComponent, Microsoft.SPOT.Emulator.Sample.SocketSample</SocketSample>
        </Types>

        <EmulatorComponents>
          <MemoryManager id="MemoryManager">
            <RamManager type="RamManager" id="RamManger">
              <Size format="HexNumber">1000000</Size>
            </RamManager>
            <FlashManager type="FlashManager" id="FlashManager">
              <Size format="HexNumber">32000</Size>
              <FlashSectors>
                <FlashSector>
                  <Length format="HexNumber">1000</Length>
                  <Usage>Bootstrap</Usage>
                  <Partition>Start</Partition>
                  <Block>Start</Block>
                </FlashSector>
              </FlashSectors>
              <!--More flash sector info goes here-->
            </FlashManager>
          </MemoryManager>
        
          <!--More configuration info goes here-->
        </EmulatorComponents>
      </Emulator>
    

In the preceding example, the <EmulatorComponents> section of the configuration file specifies configuration information for the memory manager, which first appears in the <Types> section. The memory manager initializes each type of memory that the emulator uses. Specifically, it has <RamManager>, <FlashManager>, and <FlashSector> tags that correspond to the same tags in the <Types> section of the configuration file.

If a component does not require configuration information, you must still have a tag for it in the <EmulatorComponents> section of the configuration file. In such instances, the tag would be empty. For instance, the preceding example specifies a <GpioSample> component in its <Types> section. That component, which is one of the sample components provided in the .NET Micro Framework SDK, does not require configuration information. Therefore, the configuration file should contain an empty tag for it, as in the following example:

      <?xml version="1.0" encoding="utf-8"?>
      <Emulator>
        <Types>
          <GpioCollection>Microsoft.SPOT.Emulator.Gpio.GpioCollection</GpioCollection>
          <GpioPort>Microsoft.SPOT.Emulator.Gpio.GpioPort</GpioPort>
          <MemoryManager>Microsoft.SPOT.Emulator.Memory.MemoryManager</MemoryManager>
          <RamManager>Microsoft.SPOT.Emulator.Memory.RamManager</RamManager>
          <FlashManager>Microsoft.SPOT.Emulator.Memory.FlashManager</FlashManager>
          <FlashSector>Microsoft.SPOT.Emulator.Memory.FlashSector</FlashSector>
          <TimingServices>Microsoft.SPOT.Emulator.Time.TimingServices</TimingServices>
          <LcdDisplay>Microsoft.SPOT.Emulator.Lcd.LcdDisplay</LcdDisplay>
          <ComPort>Microsoft.SPOT.Emulator.Com.ComPortToMemoryStream</ComPort>
          <GpioSample>Microsoft.SPOT.Emulator.Sample.GpioSampleComponent, Microsoft.SPOT.Emulator.Sample.GPIOSample</GpioSample>
          <ComSample>Microsoft.SPOT.Emulator.Sample.ComSampleComponent, Microsoft.SPOT.Emulator.Sample.ComSample</ComSample>
          <LCDSample>Microsoft.SPOT.Emulator.Sample.LCDSampleComponent, Microsoft.SPOT.Emulator.Sample.LCDSample</LCDSample>
          <SocketSample>Microsoft.SPOT.Emulator.Sample.SocketSampleComponent, Microsoft.SPOT.Emulator.Sample.SocketSample</SocketSample>
        </Types>

        <EmulatorComponents>
          <MemoryManager id="MemoryManager">
            <RamManager type="RamManager" id="RamManger">
              <Size format="HexNumber">1000000</Size>
            </RamManager>
            <FlashManager type="FlashManager" id="FlashManager">
              <Size format="HexNumber">32000</Size>
              <FlashSectors>
                <FlashSector>
                  <Length format="HexNumber">1000</Length>
                  <Usage>Bootstrap</Usage>
                  <Partition>Start</Partition>
                  <Block>Start</Block>
                </FlashSector>
              </FlashSectors>
              <!--More flash sector info goes here-->
            </FlashManager>
          </MemoryManager>
        
          <GpioSample/>      
          <!--More configuration info goes here-->
       </EmulatorComponents>
      </Emulator>