| 
5 | 5 | using System.Runtime.InteropServices;  | 
6 | 6 | using Microsoft.Extensions.Logging;  | 
7 | 7 | using System.Threading;  | 
 | 8 | +using ESCPOS_NET.Printers;  | 
 | 9 | +using ESCPOS_NET.Utils;  | 
8 | 10 | 
 
  | 
9 | 11 | namespace ESCPOS_NET.ConsoleTest  | 
10 | 12 | {  | 
@@ -32,13 +34,15 @@ static void Main(string[] args)  | 
32 | 34 |             Console.WriteLine("1 ) Test Serial Port");  | 
33 | 35 |             Console.WriteLine("2 ) Test Network Printer");  | 
34 | 36 |             Console.WriteLine("3 ) Test Samba-Shared Printer");  | 
 | 37 | +            Console.WriteLine("4 ) Test USB Printer");  | 
35 | 38 |             Console.Write("Choice: ");  | 
36 | 39 |             string comPort = "";  | 
37 | 40 |             string ip;  | 
38 | 41 |             string networkPort;  | 
39 | 42 |             string smbPath;  | 
 | 43 | +            string usbPort = string.Empty;  | 
40 | 44 |             response = Console.ReadLine();  | 
41 |  | -            var valid = new List<string> { "1", "2", "3" };  | 
 | 45 | +            var valid = new List<string> { "1", "2", "3", "4" };  | 
42 | 46 |             if (!valid.Contains(response))  | 
43 | 47 |             {  | 
44 | 48 |                 response = "1";  | 
@@ -100,6 +104,43 @@ static void Main(string[] args)  | 
100 | 104 | 
 
  | 
101 | 105 |                 printer = new SambaPrinter(tempFileBasePath: @"C:\Temp", filePath: smbPath);  | 
102 | 106 |             }  | 
 | 107 | +            else if (choice == 4)  | 
 | 108 | +            {  | 
 | 109 | +                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))  | 
 | 110 | +                {  | 
 | 111 | +                    var usboptions = DeviceFinder.GetDevices();//gets the usb devices connected to the pc  | 
 | 112 | +                    if (usboptions.Count > 0)  | 
 | 113 | +                    {  | 
 | 114 | +                        int i = 0;  | 
 | 115 | +                        int num = 1;  | 
 | 116 | +                        while (i < usboptions.Count)  | 
 | 117 | +                        {  | 
 | 118 | + | 
 | 119 | +                            Console.WriteLine($"{i + num}. Name: {usboptions[i].BusName} S/N: {usboptions[i].SerialNum}");  | 
 | 120 | +                            i++;  | 
 | 121 | +                            //serial number and name for printer. Name reported might just be USB Printing Support or something generic  | 
 | 122 | +                            //the property necessary for printing is Device Path this is just for UI  | 
 | 123 | +                        }  | 
 | 124 | +                        Console.Write("Choose Printer (eg. 1): ");  | 
 | 125 | +                        string c = Console.ReadLine();  | 
 | 126 | +                        if (int.TryParse(c, out int chosen) && chosen > 0)  | 
 | 127 | +                        {  | 
 | 128 | +                            usbPort = usboptions[chosen - 1].DevicePath;  | 
 | 129 | +                        }  | 
 | 130 | +                    }  | 
 | 131 | +                    printer = new USBPrinter(usbPort);  | 
 | 132 | +                }  | 
 | 133 | +                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))  | 
 | 134 | +                {  | 
 | 135 | +                    Console.Write("File / usb path (eg. /dev/usb/lp0): ");  | 
 | 136 | +                    usbPort = Console.ReadLine();  | 
 | 137 | +                    if (string.IsNullOrWhiteSpace(usbPort))  | 
 | 138 | +                    {  | 
 | 139 | +                        comPort = "/dev/usb/lp0";  | 
 | 140 | +                    }  | 
 | 141 | +                    printer = new FilePrinter(filePath: usbPort, false);  | 
 | 142 | +                }  | 
 | 143 | +            }  | 
103 | 144 | 
 
  | 
104 | 145 |             bool monitor = false;  | 
105 | 146 |             Thread.Sleep(500);  | 
 | 
0 commit comments