Ejemplo n.º 1
0
        /// <summary>
        /// How to use "PosExplorer" sample1.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExample1_Click(object sender, System.EventArgs e)
        {
            //Use a Logical Device Name which has been set on the SetupPOS.
            try
            {
                //Create PosExplorer
                PosExplorer posExplorer = new PosExplorer();

                DeviceInfo deviceInfo = null;

                //Get DeviceInfo use devicecategory and logicalname.
                deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, m_strLogicalName);

                m_PosCommon = (PosCommon)posExplorer.CreateInstance(deviceInfo);

                //Open the device
                m_PosCommon.Open();

                //Get the exclusive control right for the opened device.
                //Then the device is disable from other application.
                m_PosCommon.Claim(1000);

                //Enable the device.
                m_PosCommon.DeviceEnabled = true;

                //CheckHealth.
                m_PosCommon.CheckHealth(Microsoft.PointOfService.HealthCheckLevel.Interactive);

                //Close device
                m_PosCommon.Close();
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// When the method "closing" is called,
        /// the following code is run.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnClose_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (m_PosCommon != null)
                {
                    //Cancel the device
                    m_PosCommon.DeviceEnabled = false;

                    //Release the device exclusive control right.
                    m_PosCommon.Release();

                    //Finish using the device.
                    m_PosCommon.Close();
                }
            }
            catch (PosControlException)
            {
            }
        }
Ejemplo n.º 3
0
 private static void CloseDevice(PosCommon device)
 {
     if (device == null)
     {
         return;
     }
     try
     {
         if (device.Claimed)
         {
             device.Release();
         }
     }
     catch
     {
     }
     try
     {
         device.Close();
     }
     catch
     {
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// How to use "PosExplorer" sample2.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExample2_Click(object sender, System.EventArgs e)
        {
            try
            {
                //Create PosExplorer
                PosExplorer      posExplorer = new PosExplorer();
                DeviceInfo       deviceInfo  = null;
                DeviceCollection deviceCollection;

                //Get DeviceCollection use device categoly
                deviceCollection = posExplorer.GetDevices(DeviceType.PosPrinter);
                string[] astrLogicalNames;

                Hashtable hashDevice = new Hashtable(0);
                foreach (DeviceInfo devInfo in deviceCollection)
                {
                    //if the device name is registered.
                    if (devInfo.LogicalNames.Length > 0)
                    {
                        astrLogicalNames = devInfo.LogicalNames;
                        for (int i = 0; i < astrLogicalNames.Length; i++)
                        {
                            if (!hashDevice.ContainsKey(astrLogicalNames[i]))
                            {
                                m_PosCommon = (PosCommon)posExplorer.CreateInstance(devInfo);

                                //Use Legacy Opos
                                //if(m_PosCommon.Compatibility.Equals(DeviceCompatibilities.Opos))
                                //Use Opos for .Net
                                if (m_PosCommon.Compatibility.Equals
                                        (DeviceCompatibilities.CompatibilityLevel1))
                                {
                                    try
                                    {
                                        //Register hashtable key:LogicalName,Value:DeviceInfo
                                        hashDevice.Add(astrLogicalNames[i], devInfo);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                        }
                    }
                }

                deviceInfo = (DeviceInfo)hashDevice[m_strLogicalName];

                m_PosCommon = (PosCommon)posExplorer.CreateInstance(deviceInfo);

                //Open the device
                m_PosCommon.Open();

                //Get the exclusive control right for the opened device.
                //Then the device is disable from other application.
                m_PosCommon.Claim(1000);

                //Enable the device.
                m_PosCommon.DeviceEnabled = true;

                //CheckHealth.
                m_PosCommon.CheckHealth(Microsoft.PointOfService.HealthCheckLevel.Interactive);

                //Close device
                m_PosCommon.Close();
            }
            catch (Exception)
            {
            }
        }