/// <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) { } }
private void OpenDevice(ref PosCommon posCommon, string strDeviceName, string strDeviceLevel) { if (string.IsNullOrEmpty(strDeviceLevel) || string.IsNullOrEmpty(strDeviceName)) { return; } DeviceCollection devices = _posExplorer.GetDevices((DeviceCompatibilities)Enum.Parse(typeof(DeviceCompatibilities), strDeviceLevel, false)); DeviceInfo drv = devices.Cast <DeviceInfo>().Where(x => x.ServiceObjectName.Equals(strDeviceName)).FirstOrDefault(); try { posCommon = (PosCommon)_posExplorer.CreateInstance(drv); posCommon.Open(); SetDataEventEnabledPosCommon(ref posCommon, true); HookUpEvents(posCommon, true); } catch (Exception ex) { //sMessengeError = ex.Message; throw ex; } }
/// <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) { } }