Share via


Microsoft.SmartDevice.DeviceAgentTransport 네임스페이스

업데이트: 2007년 11월

이 네임스페이스에는 스마트 장치 연결 API의 장치 부분을 구성하는 형식이 들어 있습니다. 이 네임스페이스를 참조하고 사용하는 관리되는 스마트 장치 응용 프로그램을 장치 에이전트 응용 프로그램이라고 합니다. 스마트 장치 연결 API를 사용하는 데스크톱 응용 프로그램은 장치 에이전트를 장치에 배포하고 패킷 데이터를 교환하여 장치 에이전트와 통신할 수 있습니다. 이 라이브러리를 사용하면 스마트 장치 연결 API가 장치 상호 연결을 처리하고 메커니즘 세부 정보를 전송하는 동안 장치와 데스크톱 간에 프로그래밍 방식으로 데이터를 교환할 수 있습니다.

스마트 장치 프로젝트에서 Microsoft.SmartDevice.DeviceAgentTransport를 사용하려면 다음 작업을 수행하십시오.

  • 스마트 장치 프로젝트에서 Microsoft.Smartdevice.DeviceAgentTransport.dll 어셈블리(drive:\Program Files\Common Files\Microsoft Shared\CoreCon\1.0\Target\Microsoft.Smartdevice.DeviceAgentTransport.dll)에 대한 참조를 추가합니다.

  • 네이티브 DeviceAgentTransport.dll 라이브러리(drive:\Program Files\Common Files\Microsoft Shared\CoreCon\1.0\Target\wce400\cpu\DeviceAgentTransport.dll)와 관리되는 Microsoft.Smartdevice.DeviceAgentTransport.dll 어셈블리를 스마트 장치에 배포합니다.

자세한 내용은 스마트 장치 연결 API를 사용하여 장치 제어연습: 데스크톱 및 장치 응용 프로그램 사이에서 데이터 교환을 참조하십시오.

참고:

Visual C++를 사용하여 장치 에이전트를 만들려면 관리되지 않는 장치측 스마트 장치 연결 API를 사용합니다.

클래스

 

인터페이스

 

열거형

 

예제

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SmartDevice.DeviceAgentTransport
Imports System.Windows.Forms


Class Program

    <MTAThread()>  _
    Shared Sub Main(ByVal args() As String) 
        Dim serviceids(0 To 0) As String
        serviceids(0) = "2FAD740C-B5D3-4ad0-BE23-5682503584BF"

        ' Get an instance of Device Agent Transport
        Dim transport As IDeviceAgentTransport = _
            DeviceAgentTransportFactory.GetAgentTransport()
        ' Register the callback object with the Device Agent Transport.
        Dim shutdownCallback As New ShutdownCallback()
        transport.RegisterShutdownCallback(shutdownCallback, shutdownCallback)
        ' Let the desktop application know that this device agent was deployed successfully 
        ' and will handle the supplied list of service IDs.
        transport.AcknowledgeLaunch(Convert.ToUInt32(serviceids.Length), serviceids)

        ' Open a communcation stream with desktop application on the service.
        Dim packetStream As IDevicePacketStream
        transport.AcceptConnectionEx(serviceids(0), packetStream)
        Dim packet As IPacket

        ' Check for a packet while communication stream is connected.
        While packetStream.IsConnected()
            ' If a packet is found, display the string and integer data.
            If packetStream.IsPacketAvailable() Then
                packetStream.Read(packet)
                Dim sb As New StringBuilder()
                While Not packet.IsEndOfPacket()
                    Select Case packet.ReadDataType()
                        Case DataType.BoolType
                            Dim boolValue As Boolean = packet.ReadBool()
                        Case DataType.ByteArrayType
                            ' Read bytes and convert IntPtr to byte[]
                            Dim ptr As IntPtr
                            Dim size As System.UInt32 = 0
                            packet.ReadBytes(ptr, size)
                            Dim buffer As Byte() = InteropUtils.ConvertIntPtrToByteArray(ptr, _
                                Convert.ToInt32(size))
                        Case DataType.ByteType
                            Dim byteValue As Byte = packet.ReadByte()
                        Case DataType.CharType
                            Dim charValue As Char = packet.ReadChar()
                        Case DataType.Int32Type
                            sb.Append("Int32Type:  " + packet.ReadInt32().ToString() + _
                                      vbCr + vbLf)
                        Case DataType.StringType
                            sb.Append("String:  " + packet.ReadString() + vbCr + vbLf)
                        Case Else
                    End Select
                End While
                MessageBox.Show(sb.ToString())
                Exit While
            End If
            System.Threading.Thread.Sleep(1000)
        End While
        packet = PacketFactory.GetNewPacket()

        ' Write the version of .NET Compact Framework into the packet.
        packet.WriteString("Hello Desktop Computer")
        packet.WriteInt32(Environment.Version.Major)
        packet.WriteInt32(Environment.Version.Minor)
        packet.WriteInt32(Environment.Version.Build)
        packet.WriteInt32(Environment.Version.Revision)

        ' Pass the packet to desktop application.
        packetStream.Write(packet)

    End Sub 'Main
End Class 'Program

' Define your own shutdown implementation
Class ShutdownCallback
    Implements IAgentTransportShutdownCallback

    Sub Shutdown(ByVal in_pUnknown As Object) _
        Implements IAgentTransportShutdownCallback.Shutdown

        ' Insert cleanup code here

    End Sub 'Shutdown
End Class 'ShutdownCallback
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SmartDevice.DeviceAgentTransport;
using System.Windows.Forms;

class Program
{
    [MTAThread]
    static void Main(string[] args)
    {
        string[] serviceids = { "2FAD740C-B5D3-4ad0-BE23-5682503584BF" };

        // Get an instance of Device Agent Transport
        IDeviceAgentTransport transport = DeviceAgentTransportFactory.GetAgentTransport();

        // Register the callback object with the Device Agent Transport.
        ShutdownCallback shutdownCallback = new ShutdownCallback();
        transport.RegisterShutdownCallback(shutdownCallback, shutdownCallback);

        // Let the desktop application know that this device agent was deployed successfully 
        // and will handle the supplied list of service IDs.
        transport.AcknowledgeLaunch(Convert.ToUInt32(serviceids.Length), serviceids);

        // Open a communcation stream with desktop application on the service.
        IDevicePacketStream packetStream;
        transport.AcceptConnectionEx(serviceids[0], out packetStream);

        IPacket packet;

        // Check for a packet while communication stream is connected.
        while (packetStream.IsConnected())
        {
            // If a packet is found, display the string and integer data.
            if (packetStream.IsPacketAvailable())
            {
                packetStream.Read(out packet);
                StringBuilder sb = new StringBuilder();
                while (!packet.IsEndOfPacket())
                {
                    switch (packet.ReadDataType())
                    {
                        case DataType.BoolType:
                            bool boolValue = packet.ReadBool();
                            break;
                        case DataType.ByteArrayType:
                            // Read bytes and convert IntPtr to byte[]
                            IntPtr ptr;
                            uint size = 0;
                            packet.ReadBytes(out ptr, out size);
                            byte[] buffer = InteropUtils.ConvertIntPtrToByteArray(ptr, 
                                Convert.ToInt32(size));
                            break;
                        case DataType.ByteType:
                            byte byteValue = packet.ReadByte();
                            break;
                        case DataType.CharType:
                            char charValue = packet.ReadChar();
                            break;
                        case DataType.Int32Type:
                            sb.Append("Int32Type:  " + packet.ReadInt32().ToString() + "\r\n");
                            break;
                        case DataType.StringType:
                            sb.Append("String:  " + packet.ReadString() + "\r\n");
                            break;
                        default:
                            break;
                    }
                }
                MessageBox.Show(sb.ToString());
                break;
            }
            System.Threading.Thread.Sleep(1000);
        }

        packet = PacketFactory.GetNewPacket();

        // Write the version of .NET Compact Framework into the packet.
        packet.WriteString("Hello Desktop Computer");
        packet.WriteInt32(Environment.Version.Major);
        packet.WriteInt32(Environment.Version.Minor);
        packet.WriteInt32(Environment.Version.Build);
        packet.WriteInt32(Environment.Version.Revision);

        // Pass the packet to desktop application.
        packetStream.Write(packet);
    }
}

// Define your own shutdown implementation
class ShutdownCallback : IAgentTransportShutdownCallback
{
    public void Shutdown(object in_pUnknown)
    {
        // Insert cleanup code here
    }
}

참고 항목

참조

기타 리소스

스마트 장치 연결 API를 사용하여 장치 제어

스마트 장치 연결 API 샘플