Bagikan melalui


PosExplorer Class (POS untuk Dokumentasi .NET v1.14 SDK)

PosExplorer menyediakan aplikasi Point of Service (POS) dengan satu titik masuk ke layanan Microsoft Point of Service untuk .NET (POS untuk .NET). PosExplorer mendukung aplikasi dengan:

  • Menghitung perangkat POS yang diinstal.
  • Membuat instans Objek Layanan.
  • Menerima peristiwa Plug and Play saat perangkat periferal POS tersambung atau terputus.

Properti PosExplorer

Tabel berikut ini menjelaskan properti PosExplorer .

Properti Tipe Deskripsi
PosRegistryKey string Mengembalikan POS untuk kunci registri akar konfigurasi .NET relatif terhadap HKEY_LOCAL_MACHINE.
StatisticsFile string Mengembalikan jalur ke file tempat statistik perangkat berada.
MenyinkronkanObject ISynchronizeInvoke Memegang objek ISynchronizeInvoke.

Metode PosExplorer

Tabel berikut ini menjelaskan metode PosExplorer .

Metode Jenis Hasil Deskripsi
CreateInstance PosDevice Membuat instans Objek Layanan untuk perangkat.
GetDevice Info Perangkat Mengembalikan perangkat dari jenis yang ditentukan (harus hanya satu dalam sistem).
GetDevice Info Perangkat Mengembalikan perangkat jenis dengan nama logis atau alias yang ditentukan.
GetDevices DeviceCollection Mengembalikan semua perangkat POS.
GetDevices DeviceCollection Mengembalikan semua perangkat POS dengan tingkat kompatibilitas yang ditentukan.
GetDevices DeviceCollection Mengembalikan perangkat POS dari jenis tersebut.
GetDevices DeviceCollection Mengembalikan perangkat POS dari jenis dan tingkat kompatibilitas.
Refresh Tidak Menghitung ulang daftar perangkat POS yang terpasang dan membangun kembali struktur data internal.

Peristiwa PosExplorer

Tabel berikut ini menjelaskan peristiwa PosExplorer .

Kejadian Deskripsi
DeviceAddedEvent Diterima ketika perangkat POS yang kompatibel dengan Plug and Play tersambung.
DeviceRemovedEvent Diterima ketika perangkat POS yang kompatibel dengan Plug and Play terputus.

Contoh

Contoh kode berikut menunjukkan cara membuat instans PosExplorer, menyambungkan ke peristiwa Plug and Play, dan menggunakannya untuk mengidentifikasi semua perangkat Magnetic Stripe Reader (MSR) yang terhubung. Contoh kode mencetak informasi tentang MSR ke konsol dan menutup perangkat setelah selesai.

// Creates a new instance of an MSR.
void CreateMsr(DeviceInfo msrinfo)
{
    msr = (Msr)explorer.CreateInstance(msrinfo);
    msr.Open();
    msr.Claim(1000);
    msr.DeviceEnabled = true;
}

static void Main(string[] args)
{

    // Create a new instance of PosExplorer and use it to
    // collect device information.
    PosExplorer explorer = new PosExplorer();
    DeviceCollection devices = explorer.GetDevices();

    // Search all connected devices for an MSR, print its service
    // object name to the console, and close it when finished.
    foreach (DeviceInfo device in devices)
    {
      if (device.Type == DeviceType.Msr)
      {
         if (device.ServiceObjectName == currentMsr)
         {
            CreateMsr(device);
            Console.WriteLine(device.ServiceObjectName);

            // It is important that applications close all open
            // Service Objects before terminating.
            msr.Close();
            msr = null;
         }
      }
    }
}

Lihat Juga

Konsep

Sumber Daya Lain