다음을 통해 공유


Device 클래스

업데이트: 2007년 11월

Windows Embedded CE를 기반으로 하며 제공, 정보 가져오기 및 장치 연결을 위한 메서드를 제공하는 장치 또는 에뮬레이터를 나타냅니다.

네임스페이스:  Microsoft.SmartDevice.Connectivity
어셈블리:  Microsoft.SmartDevice.Connectivity(Microsoft.SmartDevice.Connectivity.dll)

구문

Public Class Device

Dim instance As Device
public class Device
public ref class Device
public class Device

설명

데이터 저장소에서 모든 장치는 플랫폼에 속해 있습니다. 예를 들어 Windows Mobile 5.0 Pocket PC R2 Square 에뮬레이터는 Windows Mobile 5.0 Pocket PC 플랫폼에 속합니다.

이 클래스에는 생성자가 없습니다. 인스턴스를 가져오려면 GetDevice 또는 GetDevices를 사용합니다.

예제

Imports System
Imports System.Collections.ObjectModel
Imports Microsoft.SmartDevice.Connectivity



Class [source]

    Shared Sub Main(ByVal args() As String) 
        ' Get the datastore object
        Dim dsmgr As New DatastoreManager(1033)

        ' Get the platform object
        Dim platform As Platform = GetPlatformByName("Windows Mobile 5.0 Pocket PC SDK", dsmgr)

        Try
            ' Get the default device in the platform, usually an emulator.
            Dim device As Device = platform.GetDevice(platform.GetDefaultDeviceId())

            ' Output information about the device.
            Console.WriteLine("Name:  " + device.Name + vbCr + vbLf + "Platform:  " & _
                              device.Platform.ToString() + vbCr + vbLf + "ID:  " + _
                              device.Id.ToString())

            If device.IsEmulator() Then
                Console.WriteLine("Device is an Emulator")
            End If

            ' Output device properties
            Console.WriteLine(vbCr + vbLf + "Device Properties:")
            Console.WriteLine("    OS_Version: " + device.GetProperty("OS_Version"))
            ' Connect to the device.
            device.Connect()

            ' If the device is connected, retrieve system information and output to console.
            If device.IsConnected() Then
                Dim info As SystemInfo = device.GetSystemInfo()

                Console.WriteLine("Total Page File:  " + info.TotalPageFile.ToString())
                Console.WriteLine("Available Page File:  " + info.AvailPageFile.ToString())
                Console.WriteLine("Page Size:  " + info.PageSize.ToString() + vbCr + vbLf)

                Console.WriteLine("Total RAM:  " + info.TotalPhys.ToString())
                Console.WriteLine("Available RAM:  " + info.AvailPhys.ToString() + vbCr + vbLf)

                Console.WriteLine("Total Virtual Memory:  " + info.TotalVirtual.ToString())
                Console.WriteLine("Available Virtual Memory:  " + _
                                  info.AvailVirtual.ToString() + vbCr + vbLf)

                If info.ACLineStatus = 1 Then
                    Console.WriteLine("AC Line plugged in.")
                ElseIf info.ACLineStatus = 0 Then
                    Console.WriteLine("AC Line unplugged.")
                End If

                Console.WriteLine("Main Battery:  " + info.BatteryFlag.ToString())
                Console.WriteLine("   Capacity:  " + info.BatteryFullLifetime.ToString())
                Console.WriteLine("   Percent:  " + info.BatteryLifePercent.ToString())
                Console.WriteLine("   Life:  " + info.BatteryLifetime.ToString())


                Console.WriteLine("Device Time:  " + info.CurrentTime.ToString())

                Console.WriteLine("Processor Architecture:  " + _
                                  info.ProcessorArchitecture.ToString())
                Console.WriteLine("Instruction Set:  " + info.InstructionSet.ToString())
                Console.WriteLine("Number of CPU:  " + info.NumberOfProcessors.ToString())
                Console.WriteLine("OS:  " + info.OSMajor.ToString() + "." + _
                                  info.OSMinor.ToString() & _
                                  "." + info.OSBuildNo.ToString())
                Console.WriteLine("Locale ID:  " + info.SystemDefaultLocaleId.ToString())

                ' Query Device for current security policies 
                Dim readxml As String = "<wap-provisioningdoc>" & _
                "<characteristic type=""SecurityPolicy"">" & _
                "<parm-query name=""4123""/>" & _
                "<parm-query name=""4122""/>" & _
                "<parm-query name=""4101""/>" & _
                "<parm-query name=""4102""/>" & _
                "<parm-query name=""4097""/>" & _
                "</characteristic>" & _
                "</wap-provisioningdoc>"

                Console.WriteLine(device.ProvisionDevice(readxml, _
                                                         device.ConfigActions.ProcessInput))

                ' Deploy two-tier prompt security configuration to device and see changes
                Dim provisionxml As String = "<wap-provisioningdoc>" & _
                "<characteristic type=""SecurityPolicy"">" & _
                "<parm name=""4123"" value=""0"" />" & _
                "<parm name=""4122"" value=""0"" />" & _
                "<parm name=""4101"" value=""16"" />" & _
                "<parm name=""4102"" value=""1"" />" & _
                "<parm name=""4097"" value=""2"" />" & _
                "</characteristic>" & _
                "</wap-provisioningdoc>"

                Console.WriteLine(device.ProvisionDevice(provisionxml, _
                                                         device.ConfigActions.ProcessInput))

                ' Read metadata about the policies
                Console.WriteLine(device.ProvisionDevice(readxml, _
                                                         device.ConfigActions.ReadMetadata))
                device.Disconnect()
                Console.ReadLine()
            End If


        Catch e As System.Exception
            Console.WriteLine(e.Message)
            Console.ReadLine()
        End Try

    End Sub 'Main



    ' Returns a platform if the supplied name can be found in the datastore.
    ' Returns null pointer if platform cannot be found
    Private Shared Function GetPlatformByName(ByVal p As String, _
                                              ByVal dsmgr As DatastoreManager) As Platform
        ' Get all platforms in the datastore.
        Dim platforms As Collection(Of Platform) = dsmgr.GetPlatforms()

        ' Find the platform whose name matches the parameter.
        Dim platform As Platform
        For Each platform In platforms
            If platform.Name = p Then
                Return platform
            End If
        Next platform
        Return Nothing

    End Function 'GetPlatformByName
End Class '[source]
using System;
using System.Collections.ObjectModel;
using Microsoft.SmartDevice.Connectivity;

class source
{
    static void Main(string[] args)
    {
        // Get the datastore object
        DatastoreManager dsmgr = new DatastoreManager(1033);

        // Get the platform object
        Platform platform = GetPlatformByName("Windows Mobile 5.0 Pocket PC SDK", dsmgr);

        try
        {
            // Get the default device in the platform, usually an emulator.
            Device device = platform.GetDevice(platform.GetDefaultDeviceId());

            // Output information about the device.
            Console.WriteLine("Name:  " + device.Name + "\r\n" +
                            "Platform:  " + device.Platform + "\r\n" +
                            "ID:  " + device.Id);

            if (device.IsEmulator())
            {
                Console.WriteLine("Device is an Emulator");
            }

            // Output device properties
            Console.WriteLine("\r\nDevice Properties:");
            Console.WriteLine("    OS_Version: " + device.GetProperty("OS_Version"));

            // Connect to the device.
            device.Connect();

            // If the device is connected, retrieve system information and output to console.
            if (device.IsConnected())
            {
                SystemInfo info = device.GetSystemInfo();

                Console.WriteLine("Total Page File:  " + info.TotalPageFile.ToString());
                Console.WriteLine("Available Page File:  " + info.AvailPageFile.ToString());
                Console.WriteLine("Page Size:  " + info.PageSize.ToString() + "\r\n");

                Console.WriteLine("Total RAM:  " + info.TotalPhys.ToString());
                Console.WriteLine("Available RAM:  " + info.AvailPhys.ToString() + "\r\n");

                Console.WriteLine("Total Virtual Memory:  " + info.TotalVirtual.ToString());
                Console.WriteLine("Available Virtual Memory:  " + info.AvailVirtual.ToString()
                    + "\r\n");

                if (info.ACLineStatus == 1)
                {
                    Console.WriteLine("AC Line plugged in.");
                }
                else if(info.ACLineStatus == 0)
                {
                    Console.WriteLine("AC Line unplugged.");
                }
                Console.WriteLine("Main Battery Flag:  " + info.BatteryFlag.ToString());
                Console.WriteLine("   Capacity:  " + info.BatteryFullLifetime.ToString());
                Console.WriteLine("   Percent:  " + info.BatteryLifePercent.ToString());
                Console.WriteLine("   Life:  " + info.BatteryLifetime.ToString());

                Console.WriteLine("Device Time:  " + info.CurrentTime.ToString());

                Console.WriteLine("Processor Architecture:  " + 
                    info.ProcessorArchitecture.ToString());
                Console.WriteLine("Instruction Set:  " + info.InstructionSet.ToString());
                Console.WriteLine("Number of CPU:  " + info.NumberOfProcessors.ToString());
                Console.WriteLine("OS:  " + info.OSMajor.ToString() + "." + 
                    info.OSMinor.ToString() + 
                                  "." + info.OSBuildNo.ToString());
                Console.WriteLine("Locale ID:  " + info.SystemDefaultLocaleId.ToString());

                // Query Device for current security policies 
                string readxml = @"
<wap-provisioningdoc>
    <characteristic type=""SecurityPolicy"">
        <parm-query name=""4123""/>
        <parm-query name=""4122""/>
        <parm-query name=""4101""/>
        <parm-query name=""4102""/>
        <parm-query name=""4097""/>
    </characteristic>
</wap-provisioningdoc>";
                Console.WriteLine(device.ProvisionDevice(readxml, 
                    Device.ConfigActions.ProcessInput));

                // Deploy two-tier prompt security configuration to device and see changes
                string provisionxml = @"
<wap-provisioningdoc>
    <characteristic type=""SecurityPolicy"">
        <parm name=""4123"" value=""0"" />
        <parm name=""4122"" value=""0"" />
        <parm name=""4101"" value=""16"" />
        <parm name=""4102"" value=""1"" />
        <parm name=""4097"" value=""2"" />
    </characteristic>
</wap-provisioningdoc>";
                Console.WriteLine(device.ProvisionDevice(provisionxml, 
                    Device.ConfigActions.ProcessInput));

                // Read metadata about the policies
                Console.WriteLine(device.ProvisionDevice(readxml, 
                    Device.ConfigActions.ReadMetadata));

                device.Disconnect();
                Console.ReadLine();
            }
        }

        catch (System.Exception e)
        {
            Console.WriteLine(e.Message);
            Console.ReadLine();
        }
    }


    // Returns a platform if the supplied name can be found in the datastore.
    // Returns null pointer if platform cannot be found
    private static Platform GetPlatformByName(string p, DatastoreManager dsmgr)
    {
        // Get all platforms in the datastore.
        Collection<Platform> platforms = dsmgr.GetPlatforms();

        // Find the platform whose name matches the parameter.
        foreach (Platform platform in platforms)
        {
            if (platform.Name == p) return platform;
        }
        return null;
    }
}

상속 계층 구조

System.Object
  Microsoft.SmartDevice.Connectivity.Device

스레드로부터의 안전성

이 형식의 모든 공용 static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

참고 항목

참조

Device 멤버

Microsoft.SmartDevice.Connectivity 네임스페이스