private static void Main(string[] args) { Console.WriteLine("ESCPOS_NET Test Application..."); Console.WriteLine("1 ) Test Serial Port"); Console.WriteLine("2 ) Test Network Printer"); Console.Write("Choice: "); var comPort = ""; string baudRate; string ip; string networkPort; var response = Console.ReadLine(); var valid = new List <string> { "1", "2" }; if (!valid.Contains(response)) { response = "1"; } var choice = int.Parse(response); if (choice == 1) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { while (!comPort.StartsWith("COM")) { Console.Write("COM Port (eg. COM5): "); comPort = Console.ReadLine(); if (string.IsNullOrWhiteSpace(comPort)) { comPort = "COM5"; } } Console.Write("Baud Rate (eg. 115200): "); baudRate = Console.ReadLine(); if (string.IsNullOrWhiteSpace(baudRate)) { baudRate = "115200"; } printer = new SerialPrinter(comPort, 115200); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Console.Write("File / virtual com path (eg. /dev/usb/lp0): "); comPort = Console.ReadLine(); if (string.IsNullOrWhiteSpace(comPort)) { comPort = "/dev/usb/lp0"; } printer = new FilePrinter(comPort); } } else if (choice == 2) { Console.Write("IP Address (eg. 192.168.1.240): "); ip = Console.ReadLine(); if (string.IsNullOrWhiteSpace(ip)) { ip = "192.168.1.240"; } Console.Write("TCP Port (eg. 9000): "); networkPort = Console.ReadLine(); if (string.IsNullOrWhiteSpace(networkPort)) { networkPort = "9000"; } printer = new NetworkPrinter(ip, int.Parse(networkPort), true); } var monitor = false; Console.Write("Turn on Live Status Back Monitoring? (y/n): "); response = Console.ReadLine().Trim().ToLowerInvariant(); if (response.Length >= 1 && response[0] == 'y') { monitor = true; } e = new EPSON(); var testCases = new Dictionary <Option, string> { { Option.Printing, "Printing" }, { Option.LineSpacing, "Line Spacing" }, { Option.BarcodeStyles, "Barcode Styles" }, { Option.BarcodeTypes, "Barcode Types" }, { Option.TwoDimensionCodes, "2D Codes" }, { Option.TextStyles, "Text Styles" }, { Option.FullReceipt, "Full Receipt" }, { Option.Images, "Images" }, { Option.LegacyImages, "Legacy Images" }, { Option.LargeByteArrays, "Large Byte Arrays" }, { Option.CashDrawerPin2, "Cash Drawer Pin2" }, { Option.CashDrawerPin5, "Cash Drawer Pin5" }, { Option.Exit, "Exit" } }; while (true) { foreach (var item in testCases) { Console.WriteLine($"{(int) item.Key} : {item.Value}"); } Console.Write("Execute Test: "); if (!int.TryParse(Console.ReadLine(), out choice) || !Enum.IsDefined(typeof(Option), choice)) { Console.WriteLine("Invalid entry. Please try again."); continue; } var enumChoice = (Option)choice; if (enumChoice == Option.Exit) { return; } Console.Clear(); if (monitor) { printer.StartMonitoring(); } Setup(monitor); printer?.Write(e.PrintLine($"== [ Start {testCases[enumChoice]} ] ==")); switch (enumChoice) { case Option.Printing: printer.Write(Tests.Printing(e)); break; case Option.LineSpacing: printer.Write(Tests.LineSpacing(e)); break; case Option.BarcodeStyles: printer.Write(Tests.BarcodeStyles(e)); break; case Option.BarcodeTypes: printer.Write(Tests.BarcodeTypes(e)); break; case Option.TwoDimensionCodes: printer.Write(Tests.TwoDimensionCodes(e)); break; case Option.TextStyles: printer.Write(Tests.TextStyles(e)); break; case Option.FullReceipt: printer.Write(Tests.Receipt(e)); break; case Option.Images: printer.Write(Tests.Images(e, false)); break; case Option.LegacyImages: printer.Write(Tests.Images(e, true)); break; case Option.LargeByteArrays: try { printer.Write(Tests.TestLargeByteArrays(e)); } catch (Exception e) { Console.WriteLine( $"Aborting print due to test failure. Exception: {e?.Message}, Stack Trace: {e?.GetBaseException()?.StackTrace}"); } break; case Option.CashDrawerPin2: printer.Write(Tests.CashDrawerOpenPin2(e)); break; case Option.CashDrawerPin5: printer.Write(Tests.CashDrawerOpenPin5(e)); break; default: Console.WriteLine("Invalid entry."); break; } Setup(monitor); printer?.Write(e.PrintLine($"== [ End {testCases[enumChoice]} ] ==")); printer?.Write(e.PartialCutAfterFeed(5)); // TODO: write a sanitation check. // TODO: make DPI to inch conversion function // TODO: full cuts and reverse feeding not implemented on epson... should throw exception? // TODO: make an input loop that lets you execute each test separately. // TODO: also make an automatic runner that runs all tests (command line). //Thread.Sleep(1000); } }
static void Main(string[] args) { Console.WriteLine("ESCPOS_NET Test Application..."); Console.WriteLine("1 ) Test Serial Port"); Console.WriteLine("2 ) Test Network Printer"); Console.Write("Choice: "); string comPort = ""; string baudRate; string ip; string networkPort; var response = Console.ReadLine(); var valid = new List <string> { "1", "2" }; if (!valid.Contains(response)) { response = "1"; } int choice = int.Parse(response); if (choice == 1) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { while (!comPort.StartsWith("COM")) { Console.Write("COM Port (eg. COM20): "); comPort = Console.ReadLine(); if (string.IsNullOrWhiteSpace(comPort)) { comPort = "COM20"; } } Console.Write("Baud Rate (eg. 115200): "); baudRate = Console.ReadLine(); if (string.IsNullOrWhiteSpace(baudRate)) { baudRate = "115200"; } printer = new SerialPrinter(comPort, int.Parse(baudRate)); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Console.Write("File / virtual com path (eg. /dev/usb/lp0): "); comPort = Console.ReadLine(); if (string.IsNullOrWhiteSpace(comPort)) { comPort = "/dev/usb/lp0"; } printer = new FilePrinter(comPort); } } else if (choice == 2) { Console.Write("IP Address (eg. 192.168.1.240): "); ip = Console.ReadLine(); if (string.IsNullOrWhiteSpace(ip)) { ip = "192.168.1.240"; } Console.Write("TCP Port (eg. 9000): "); networkPort = Console.ReadLine(); if (string.IsNullOrWhiteSpace(networkPort)) { networkPort = "9000"; } printer = new NetworkPrinter(ip, int.Parse(networkPort)); } bool monitor = false; Console.Write("Turn on Live Status Back Monitoring? (y/n): "); response = Console.ReadLine().Trim().ToLowerInvariant(); if (response.Length >= 1 && response[0] == 'y') { monitor = true; } e = new EPSON(); List <string> testCases = new List <string>() { "Printing", "Line Spacing", "Barcode Styles", "Text Styles", "Full Receipt" }; while (true) { int i = 0; foreach (var item in testCases) { i += 1; Console.WriteLine($"{i} : {item}"); } Console.WriteLine("99 : Exit"); Console.Write("Execute Test: "); try { choice = Convert.ToInt32(Console.ReadLine()); if (choice != 99 && (choice < 1 || choice > testCases.Count)) { throw new InvalidOperationException(); } } catch { Console.WriteLine("Invalid entry. Please try again."); continue; } if (choice == 99) { return; } Console.Clear(); if (monitor) { printer.StartMonitoring(); } Setup(); printer.Write(e.PrintLine($"== [ Start {testCases[choice - 1]} ] ==")); switch (choice) { case 1: printer.Write(Tests.Printing(e)); break; case 2: printer.Write(Tests.LineSpacing(e)); break; case 3: printer.Write(Tests.BarcodeStyles(e)); break; case 4: printer.Write(Tests.TextStyles(e)); break; case 5: printer.Write(Tests.Receipt(e)); break; default: Console.WriteLine("Invalid entry."); break; } Setup(); printer.Write(e.PrintLine($"== [ End {testCases[choice - 1]} ] ==")); printer.Write(e.PartialCutAfterFeed(5)); //TestCutter(); //TestMultiLineWrite(); //TestHEBReceipt(); // TODO: write a sanitation check. // TODO: make DPI to inch conversion function // TODO: full cuts and reverse feeding not implemented on epson... should throw exception? // TODO: make an input loop that lets you execute each test separately. // TODO: also make an automatic runner that runs all tests (command line). //Thread.Sleep(1000); } }
static void Main(string[] args) { Console.WriteLine("Welcome to the ESCPOS_NET Test Application!"); Console.Write("Would you like to see all debug messages? (y/n): "); var response = Console.ReadLine().Trim().ToLowerInvariant(); var logLevel = LogLevel.Information; if (response.Length >= 1 && response[0] == 'y') { Console.WriteLine("Debugging enabled!"); logLevel = LogLevel.Trace; } var factory = LoggerFactory.Create(b => b.AddConsole().SetMinimumLevel(logLevel)); var logger = factory.CreateLogger <Program>(); ESCPOS_NET.Logging.Logger = logger; Console.WriteLine("1 ) Test Serial Port"); Console.WriteLine("2 ) Test Network Printer"); Console.Write("Choice: "); string comPort = ""; string baudRate; string ip; string networkPort; response = Console.ReadLine(); var valid = new List <string> { "1", "2" }; if (!valid.Contains(response)) { response = "1"; } int choice = int.Parse(response); if (choice == 1) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { while (!comPort.StartsWith("COM")) { Console.Write("COM Port (enter for default COM5): "); comPort = Console.ReadLine(); if (string.IsNullOrWhiteSpace(comPort)) { comPort = "COM5"; } } Console.Write("Baud Rate (enter for default 115200): "); baudRate = Console.ReadLine(); if (string.IsNullOrWhiteSpace(baudRate)) { baudRate = "115200"; } printer = new SerialPrinter(portName: comPort, baudRate: 115200); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Console.Write("File / virtual com path (eg. /dev/usb/lp0): "); comPort = Console.ReadLine(); if (string.IsNullOrWhiteSpace(comPort)) { comPort = "/dev/usb/lp0"; } printer = new FilePrinter(filePath: comPort, false); } } else if (choice == 2) { Console.Write("IP Address (eg. 192.168.1.240): "); ip = Console.ReadLine(); if (string.IsNullOrWhiteSpace(ip)) { ip = "192.168.254.202"; } Console.Write("TCP Port (enter for default 9100): "); networkPort = Console.ReadLine(); if (string.IsNullOrWhiteSpace(networkPort)) { networkPort = "9100"; } printer = new NetworkPrinter(ipAddress: ip, port: int.Parse(networkPort), reconnectOnTimeout: true); } bool monitor = false; Thread.Sleep(500); Console.Write("Turn on Live Status Back Monitoring? (y/n): "); response = Console.ReadLine().Trim().ToLowerInvariant(); if (response.Length >= 1 && response[0] == 'y') { monitor = true; } e = new EPSON(); var testCases = new Dictionary <Option, string>() { { Option.SingleLinePrinting, "Single Line Printing" }, { Option.MultiLinePrinting, "Multi-line Printing" }, { Option.LineSpacing, "Line Spacing" }, { Option.BarcodeStyles, "Barcode Styles" }, { Option.BarcodeTypes, "Barcode Types" }, { Option.TwoDimensionCodes, "2D Codes" }, { Option.TextStyles, "Text Styles" }, { Option.FullReceipt, "Full Receipt" }, { Option.CodePages, "Code Pages (Euro, Katakana, Etc)" }, { Option.Images, "Images" }, { Option.LegacyImages, "Legacy Images" }, { Option.LargeByteArrays, "Large Byte Arrays" }, { Option.CashDrawerPin2, "Cash Drawer Pin2" }, { Option.CashDrawerPin5, "Cash Drawer Pin5" }, { Option.Exit, "Exit" } }; while (true) { foreach (var item in testCases) { Console.WriteLine($"{(int)item.Key} : {item.Value}"); } Console.Write("Execute Test: "); if (!int.TryParse(Console.ReadLine(), out choice) || !Enum.IsDefined(typeof(Option), choice)) { Console.WriteLine("Invalid entry. Please try again."); continue; } var enumChoice = (Option)choice; if (enumChoice == Option.Exit) { return; } Console.Clear(); if (monitor) { printer.StartMonitoring(); } Setup(monitor); printer?.Write(e.PrintLine($"== [ Start {testCases[enumChoice]} ] ==")); switch (enumChoice) { case Option.SingleLinePrinting: printer.Write(Tests.SingleLinePrinting(e)); break; case Option.MultiLinePrinting: printer.Write(Tests.MultiLinePrinting(e)); break; case Option.LineSpacing: printer.Write(Tests.LineSpacing(e)); break; case Option.BarcodeStyles: printer.Write(Tests.BarcodeStyles(e)); break; case Option.BarcodeTypes: printer.Write(Tests.BarcodeTypes(e)); break; case Option.TwoDimensionCodes: printer.Write(Tests.TwoDimensionCodes(e)); break; case Option.TextStyles: printer.Write(Tests.TextStyles(e)); break; case Option.FullReceipt: printer.Write(Tests.Receipt(e)); break; case Option.Images: printer.Write(Tests.Images(e, false)); break; case Option.LegacyImages: printer.Write(Tests.Images(e, true)); break; case Option.LargeByteArrays: try { printer.Write(Tests.TestLargeByteArrays(e)); } catch (Exception e) { Console.WriteLine($"Aborting print due to test failure. Exception: {e?.Message}, Stack Trace: {e?.GetBaseException()?.StackTrace}"); } break; case Option.CashDrawerPin2: printer.Write(Tests.CashDrawerOpenPin2(e)); break; case Option.CashDrawerPin5: printer.Write(Tests.CashDrawerOpenPin5(e)); break; default: Console.WriteLine("Invalid entry."); break; } Setup(monitor); printer?.Write(e.PrintLine($"== [ End {testCases[enumChoice]} ] ==")); printer?.Write(e.PartialCutAfterFeed(5)); // TODO: also make an automatic runner that runs all tests (command line). } }
static void Main(string[] args) { Console.WriteLine("ESCPOS_NET Test Application..."); Console.WriteLine("1 ) Test Serial Port"); Console.WriteLine("2 ) Test Network Printer"); Console.Write("Choice: "); string comPort = ""; string baudRate; string ip; string networkPort; var response = Console.ReadLine(); var valid = new List <string> { "1", "2" }; if (!valid.Contains(response)) { response = "1"; } int choice = int.Parse(response); if (choice == 1) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { while (!comPort.StartsWith("COM")) { Console.Write("COM Port (eg. COM5): "); comPort = Console.ReadLine(); if (string.IsNullOrWhiteSpace(comPort)) { comPort = "COM5"; } } Console.Write("Baud Rate (eg. 115200): "); baudRate = Console.ReadLine(); if (string.IsNullOrWhiteSpace(baudRate)) { baudRate = "115200"; } printer = new SerialPrinter(portName: comPort, baudRate: int.Parse(baudRate)); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Console.Write("File / virtual com path (eg. /dev/usb/lp0): "); comPort = Console.ReadLine(); if (string.IsNullOrWhiteSpace(comPort)) { comPort = "/dev/usb/lp0"; } printer = new FilePrinter(filePath: comPort, false); } } else if (choice == 2) { Console.Write("IP Address (eg. 192.168.1.240): "); ip = Console.ReadLine(); if (string.IsNullOrWhiteSpace(ip)) { ip = "192.168.1.240"; } Console.Write("TCP Port (eg. 9000): "); networkPort = Console.ReadLine(); if (string.IsNullOrWhiteSpace(networkPort)) { networkPort = "9000"; } printer = new NetworkPrinter(ipAddress: ip, port: int.Parse(networkPort), reconnectOnTimeout: true); } bool monitor = false; Console.Write("Turn on Live Status Back Monitoring? (y/n): "); response = Console.ReadLine().Trim().ToLowerInvariant(); if (response.Length >= 1 && response[0] == 'y') { monitor = true; } e = new EPSON(); var testCases = new Dictionary <Option, string>() { { Option.Printing, "Printing" }, { Option.LineSpacing, "Line Spacing" }, { Option.BarcodeStyles, "Barcode Styles" }, { Option.BarcodeTypes, "Barcode Types" }, { Option.TwoDimensionCodes, "2D Codes" }, { Option.TextStyles, "Text Styles" }, { Option.FullReceipt, "Full Receipt" }, { Option.CodePages, "Code Pages (Euro, Katakana, Etc)" }, { Option.Images, "Images" }, { Option.LegacyImages, "Legacy Images" }, { Option.LargeByteArrays, "Large Byte Arrays" }, { Option.CashDrawerPin2, "Cash Drawer Pin2" }, { Option.CashDrawerPin5, "Cash Drawer Pin5" }, { Option.Exit, "Exit" } }; while (true) { foreach (var item in testCases) { Console.WriteLine($"{(int)item.Key} : {item.Value}"); } Console.Write("Execute Test: "); if (!int.TryParse(Console.ReadLine(), out choice) || !Enum.IsDefined(typeof(Option), choice)) { Console.WriteLine("Invalid entry. Please try again."); continue; } var enumChoice = (Option)choice; if (enumChoice == Option.Exit) { return; } Console.Clear(); if (monitor) { printer.StartMonitoring(); } Setup(monitor); printer?.Write(e.PrintLine($"== [ Start {testCases[enumChoice]} ] ==")); switch (enumChoice) { case Option.Printing: printer.Write(Tests.Printing(e)); break; case Option.LineSpacing: printer.Write(Tests.LineSpacing(e)); break; case Option.BarcodeStyles: printer.Write(Tests.BarcodeStyles(e)); break; case Option.BarcodeTypes: printer.Write(Tests.BarcodeTypes(e)); break; case Option.TwoDimensionCodes: printer.Write(Tests.TwoDimensionCodes(e)); break; case Option.TextStyles: printer.Write(Tests.TextStyles(e)); break; case Option.FullReceipt: printer.Write(Tests.Receipt(e)); break; case Option.CodePages: var codePage = CodePage.PC437_USA_STANDARD_EUROPE_DEFAULT; Console.WriteLine("To run this test, you must select the index of a code page to print."); Console.WriteLine("The default CodePage is typically CodePage 0 (USA/International)."); Console.WriteLine("Press enter to see the list of Code Pages."); Console.ReadLine(); List <object> codePages = new List <object>(); foreach (var value in Enum.GetValues(typeof(CodePage))) { codePages.Add(value); } for (int i = 0; i < codePages.Count; i++) { Console.WriteLine(i.ToString() + ": " + codePages[i] + " (Page " + ((int)codePages[i]) + ")"); } Console.Write("Index for test Code Page (NOT Page #): "); var page = Console.ReadLine(); try { codePage = (CodePage)codePages[int.Parse(page)]; } catch { Console.WriteLine("Invalid code page selected, defaulting to CodePage 0."); } printer.Write(Tests.CodePages(e, codePage)); break; case Option.Images: printer.Write(Tests.Images(e, false)); break; case Option.LegacyImages: printer.Write(Tests.Images(e, true)); break; case Option.LargeByteArrays: try { printer.Write(Tests.TestLargeByteArrays(e)); } catch (Exception e) { Console.WriteLine($"Aborting print due to test failure. Exception: {e?.Message}, Stack Trace: {e?.GetBaseException()?.StackTrace}"); } break; case Option.CashDrawerPin2: printer.Write(Tests.CashDrawerOpenPin2(e)); break; case Option.CashDrawerPin5: printer.Write(Tests.CashDrawerOpenPin5(e)); break; default: Console.WriteLine("Invalid entry."); break; } Setup(monitor); printer?.Write(e.PrintLine($"== [ End {testCases[enumChoice]} ] ==")); printer?.Write(e.PartialCutAfterFeed(5)); // TODO: also make an automatic runner that runs all tests (command line). } }