using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.PointOfService; namespace TestApp { class Program { static PosPrinter posPrinter = null; private static string posPrint(params string[] p) { return String.Join(string.Empty, p.Select(o => o.ToString().Replace("|", "\u001b|")).ToArray()); } private static string Header() { var header = new StringBuilder(); header.Append(posPrint("|bC|3C", "Settings.CompanyName", "\n")); header.Append(posPrint("|N", "Settings.CompanyAddress", "\n")); header.Append(posPrint("Settings.CompanyPhone", "\n")); header.Append(posPrint("Email: ", "Settings.CompanyEmail", "\n")); header.Append(posPrint("VAT no: ", "Settings.CompanyVatNumber", "\n")); header.Append(posPrint(DateTime.Now.ToString("dd/mm/yyyy HH:mm"), "\n")); header.Append(posPrint("|500uF")); return header.ToString(); } static void Main(string[] args) { var data = new StringBuilder(); var posExplorer = new PosExplorer(); var deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, "PosPrinter"); Console.WriteLine(deviceInfo.ManufacturerName); Console.WriteLine(deviceInfo.ServiceObjectName); Console.WriteLine(deviceInfo.Compatibility.ToString()); Console.WriteLine(deviceInfo.Description); Console.WriteLine(deviceInfo.IsDefault); Console.WriteLine(deviceInfo.Type); Console.WriteLine(deviceInfo.LogicalNames.FirstOrDefault()); posPrinter = (PosPrinter)posExplorer.CreateInstance(deviceInfo); posPrinter.Open(); posPrinter.Claim(1000); // Get the exclusive control right for the opened device, then the device is disabled from other application. posPrinter.DeviceEnabled = true; // Enable the device. data.Append(Header()); posPrinter.TransactionPrint(PrinterStation.Receipt, PrinterTransactionControl.Transaction); posPrinter.PrintNormal(PrinterStation.Receipt, data.ToString()); posPrinter.TransactionPrint(PrinterStation.Receipt, PrinterTransactionControl.Normal); posPrinter.DeviceEnabled = false; // Cancel the device. posPrinter.Release(); // Release the device exclusive control right. posPrinter.Close(); // Finish using the device. } } }