379 lines
10 KiB
C#
379 lines
10 KiB
C#
using Inspectron.Epson;
|
|
using Inspectron.Epson.PrintServer.Printers.Utils;
|
|
using Inspectron.Epson.PrintServer.Printers.Utils.FinalRecipe;
|
|
using Inspectron.Epson.SOAP;
|
|
using SixLabors.ImageSharp;
|
|
using SixLabors.ImageSharp.PixelFormats;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Xml.Linq;
|
|
|
|
|
|
//SoapEpsonPrinter printer = new SoapEpsonPrinter("localhost:8888");
|
|
//var print = new SoapEpsonPrint();
|
|
//print
|
|
// .AddText("123")
|
|
// .AddFeed()
|
|
// .AddFeed()
|
|
// .AddCut(SoapEpsonPrint.CUT_FEED);
|
|
|
|
//var task = await printer.Send(print);
|
|
//var status = await printer.GetStatus(print);
|
|
|
|
//HttpClient httpClient = new HttpClient(new HttpClientHandler
|
|
//{
|
|
// ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
|
|
//});
|
|
|
|
//var requestText = @"
|
|
//<?xml version=""1.0"" encoding=""UTF-8""?>
|
|
//<epos-print xmlns=""http://www.epson-pos.com/schemas/2011/03/epos-print"">
|
|
// <text>Hello, World!</text>
|
|
//<feed />
|
|
//<feed />
|
|
//</epos-print>";
|
|
|
|
|
|
//var request = new HttpRequestMessage(HttpMethod.Post,
|
|
// "https://localhost:8888/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000");
|
|
//var response = httpClient.Send(request);
|
|
//var responseText = await response.Content.ReadAsStringAsync();
|
|
//Console.WriteLine(responseText);
|
|
|
|
|
|
|
|
//var printer = new EpsonPrinter();
|
|
//await printer.ConnectAsync("127.0.0.1",8888);
|
|
//for (int i = 0; i < 20; i++)
|
|
//{
|
|
// await printer.PrintTextAsync("Hello\n");
|
|
//}
|
|
|
|
//await printer.FeedLinesAsync(5);
|
|
//await printer.CutAsync();
|
|
|
|
//var status = await printer.GetPrinterStatusAsync();
|
|
//Console.ReadLine();
|
|
|
|
|
|
//var receipt = new Receipt
|
|
//{
|
|
// CompanyName = "Klingler Gastro AG",
|
|
// Address1 = "Münzplatz 3",
|
|
// Address2 = "CH-8001 Zürich",
|
|
// Phone = "043 321 22 22",
|
|
// ReceiptNumber = "1-81-202",
|
|
// DateTime = new DateTime(2025, 12, 16, 14, 58, 0),
|
|
// Guests = 2,
|
|
// Total = 160.00m,
|
|
// Currency = "CHF",
|
|
// TotalInAlternateCurrency = 172.80m,
|
|
// AlternateCurrency = "EUR",
|
|
// PaymentMethod = "MASTER",
|
|
// PaymentAmount = 160.00m,
|
|
// ServerName = "Yves",
|
|
// Terminal = "Hauptkasse ZH",
|
|
// TableNumber = "12",
|
|
// VatNumber = "CHE-449.635.880 MWST",
|
|
// ThankYouMessage = "Das Team bedankt sich herzlich für Ihren",
|
|
// GoodbyeMessageLine1 = "Besuch.",
|
|
// GoodbyeMessageLine2 = "Auf Wiedersehen."
|
|
//};
|
|
|
|
//// Add items
|
|
//receipt.Items.Add(new ReceiptItem
|
|
//{
|
|
// Quantity = 1,
|
|
// Description = "San Pellegrino 50cl",
|
|
// UnitPrice = 6.50m,
|
|
// TotalPrice = 6.50m,
|
|
// TaxCategory = "A"
|
|
//});
|
|
|
|
//receipt.Items.Add(new ReceiptItem
|
|
//{
|
|
// Quantity = 1,
|
|
// Description = "Panna 50cl",
|
|
// UnitPrice = 6.50m,
|
|
// TotalPrice = 6.50m,
|
|
// TaxCategory = "A"
|
|
//});
|
|
|
|
//receipt.Items.Add(new ReceiptItem
|
|
//{
|
|
// Quantity = 1,
|
|
// Description = "Granini Tomatensaft",
|
|
// UnitPrice = 5.50m,
|
|
// TotalPrice = 5.50m,
|
|
// TaxCategory = "A"
|
|
//});
|
|
|
|
//receipt.Items.Add(new ReceiptItem
|
|
//{
|
|
// Quantity = 2,
|
|
// Description = "Business Lunch Menu Seco",
|
|
// UnitPrice = 44.00m,
|
|
// TotalPrice = 88.00m,
|
|
// TaxCategory = "A"
|
|
//});
|
|
|
|
//receipt.Items.Add(new ReceiptItem
|
|
//{
|
|
// Quantity = 2,
|
|
// Description = "Brunello di Montalcino 1",
|
|
// UnitPrice = 16.00m,
|
|
// TotalPrice = 32.00m,
|
|
// TaxCategory = "A"
|
|
//});
|
|
|
|
//receipt.Items.Add(new ReceiptItem
|
|
//{
|
|
// Quantity = 2,
|
|
// Description = "Espresso",
|
|
// UnitPrice = 5.50m,
|
|
// TotalPrice = 11.00m,
|
|
// TaxCategory = "A"
|
|
//});
|
|
|
|
//receipt.Items.Add(new ReceiptItem
|
|
//{
|
|
// Quantity = 1,
|
|
// Description = "Tip",
|
|
// UnitPrice = 10.50m,
|
|
// TotalPrice = 10.50m,
|
|
// TaxCategory = "B"
|
|
//});
|
|
|
|
//// Add tax breakdown
|
|
//receipt.TaxBreakdown.Add(new TaxInfo
|
|
//{
|
|
// Category = "A",
|
|
// Rate = 8.1m,
|
|
// Gross = 149.50m,
|
|
// Net = 138.30m,
|
|
// TaxAmount = 11.20m,
|
|
// Currency = "CHF"
|
|
//});
|
|
|
|
//receipt.TaxBreakdown.Add(new TaxInfo
|
|
//{
|
|
// Category = "B",
|
|
// Rate = 0m,
|
|
// Gross = 10.50m,
|
|
// Net = 10.50m,
|
|
// TaxAmount = 0.00m,
|
|
// Currency = "CHF"
|
|
//});
|
|
|
|
|
|
//// Convert to print commands
|
|
//var converter = new ReceiptConverter(lineWidth: 48, bigFontLineWidth: 24);
|
|
//var printCommands = converter.ConvertToPrintCommands(receipt);
|
|
|
|
//// Print the commands
|
|
//Console.WriteLine("=== PRINT COMMANDS ===\n");
|
|
//await printer.SetAbsolutePrintPosition(97);
|
|
//await printer.LoadImageAsync("ristorante-klinglers.ch-logo_white_bg.png",390);
|
|
//await printer.SetAbsolutePrintPosition(0);
|
|
//await Task.Delay(200);
|
|
//await printer.FeedLinesAsync(1);
|
|
//await printer.SetCustomLineSpacing(22);
|
|
//foreach (var command in printCommands)
|
|
//{
|
|
// string attributes = "";
|
|
// if (command.IsBig) attributes += "[BIG] ";
|
|
// if (command.IsBold) attributes += "[BOLD] ";
|
|
|
|
// Console.WriteLine($"{attributes}{command.Text}");
|
|
|
|
// if (command.IsBig)
|
|
// {
|
|
// await printer.SetFontSizeAsync(2, 1);
|
|
// }
|
|
// else
|
|
// {
|
|
// await printer.SetFontSizeAsync(1, 1);
|
|
// }
|
|
// //await Task.Delay(200);
|
|
|
|
// await printer.SetEmphasized(command.IsBold);
|
|
// //await Task.Delay(200);
|
|
|
|
// await printer.PrintTextAsync(command.Text + "\n");
|
|
// //await Task.Delay(200);
|
|
|
|
//}
|
|
|
|
//await printer.SetDefaultLineSpacing();
|
|
//await printer.PrintTextAsync(
|
|
// "1x San Pellegrino 50cl 6.50 6.50 A\n1x Panna 50cl 6.50 6.50 A");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// clear printer buffer
|
|
//await printer.SendRawCommandAsync([0x10, 0x14, 0x08, 0x01, 0x03, 0x14, 0x01, 0x06, 0x02, 0x08]);
|
|
//
|
|
//for (int i = 0; i < 10; i++)
|
|
//{
|
|
// await printer.SendRawCommandAsync(EpsonCommands.LineFeed);
|
|
// await Task.Delay(200);
|
|
//}
|
|
|
|
//await printer.InitAsync();
|
|
//await Task.Delay(200);
|
|
|
|
//KitchenReceiptPrinter krp = new KitchenReceiptPrinter(33);
|
|
var receipt = new KitchenReceipt(
|
|
Location: "Warme Küche",
|
|
Date: "23-Okt-25 12:18 Nr.:13201B166",
|
|
Owner: "Mariano Amato\n32 (VK Restaurant)",
|
|
Tisch: "22",
|
|
items: new List<KitchenItem>
|
|
{
|
|
new KitchenGang("1. Gang"),
|
|
new KitchenProduct(1, "Avocado Sashimi"),
|
|
new KitchenProduct(1, "Baby Spinach Salad with Truffl"),
|
|
new KitchenGang("2. Gang"),
|
|
new KitchenProduct(1, "Beef Tataki"),
|
|
new KitchenProduct(1, "Salmon Taco")
|
|
}
|
|
);
|
|
|
|
var test = JsonSerializer.Serialize(receipt, new JsonSerializerOptions() { WriteIndented = true });
|
|
Console.WriteLine(test);
|
|
|
|
////// Create printer with 42 character line width (default)
|
|
//var commands = krp.ConvertToCommands(receipt);
|
|
|
|
//foreach (PrintCommand command in commands)
|
|
//{
|
|
// await printer.SetBiggerFontTM220(command.IsBig);
|
|
// await Task.Delay(200);
|
|
// await printer.SetRedColor(command.IsRed);
|
|
// await Task.Delay(200);
|
|
// await printer.SetEmphasized(command.IsBold);
|
|
// await Task.Delay(200);
|
|
// await printer.PrintTextAsync(command.Text + "\n");
|
|
// await Task.Delay(200);
|
|
//}
|
|
|
|
|
|
|
|
//await printer.SetBiggerFontTM220(true);
|
|
// 24
|
|
//await printer.SetFontSizeAsync(2,2);
|
|
//await Task.Delay(200);
|
|
//await printer.SelectFont(EpsonCommands.PrinterFont.A);
|
|
//await Task.Delay(200);
|
|
//await printer.PrintTextAsync("HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_\n");
|
|
//await Task.Delay(200);
|
|
|
|
//// 48
|
|
//await printer.SetFontSizeAsync(1, 1);
|
|
//await Task.Delay(200);
|
|
//await printer.SelectFont(EpsonCommands.PrinterFont.A);
|
|
//await Task.Delay(200);
|
|
//await printer.PrintTextAsync("HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_\n");
|
|
//await Task.Delay(200);
|
|
//await printer.SetBiggerFontTM220(false);
|
|
//await Task.Delay(200);
|
|
//await printer.SelectFont(EpsonCommands.PrinterFont.A);
|
|
//await Task.Delay(200);
|
|
//await printer.PrintTextAsync("HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_HHHH_\n");
|
|
//await Task.Delay(200);
|
|
|
|
|
|
|
|
//await printer.FeedLinesAsync(10);
|
|
//await Task.Delay(1000);
|
|
|
|
|
|
//await printer.SetQuadrupleMode(false);
|
|
//await printer.PrintImageBitModeAsync("test.png",maxWidth:24);
|
|
//await printer.LoadImageAsync("test.png", 100);
|
|
//await printer.PrintLoadedImage();
|
|
|
|
//for (int i = 1; i < 5; i++)
|
|
//{
|
|
// List<byte> lineBytes = new List<byte>();
|
|
|
|
// for (int j = 0; j < i; j++)
|
|
// {
|
|
// lineBytes.AddRange([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,]);
|
|
// lineBytes.AddRange([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,]);
|
|
|
|
// }
|
|
// var bytes = EpsonCommands.CreateBitImageCommand(EpsonCommands.BitImageMode.SingleDensity8Dot,
|
|
// lineBytes.ToArray(), i*16);
|
|
// await printer.SendRawCommandAsync(bytes);
|
|
// await printer.SendRawCommandAsync(EpsonCommands.LineFeed);
|
|
//}
|
|
|
|
|
|
//await printer.SetAbsolutePrintPosition(50);
|
|
//await printer.SetFontSizeAsync(2, 2);
|
|
//await printer.PrintTextAsync("Hello!");
|
|
//await printer.SendRawCommandAsync(EpsonCommands.LineFeed);
|
|
//await printer.FeedLinesAsync(7);
|
|
|
|
//await printer.PrintImageBitModeAsync("test.png");
|
|
//var bytes = EpsonCommands.CreateBitImageCommand(EpsonCommands.BitImageMode.SingleDensity8Dot,
|
|
// [
|
|
// 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
// 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ], 32);
|
|
//await printer.SendRawCommandAsync(bytes);
|
|
//await Task.Delay(2000);
|
|
//await printer.PrintBuffer();
|
|
|
|
//await printer.SendRawCommandAsync([0x1b,0x21,0x10+0x21]);
|
|
//await printer.PrintTextAsync("Hello!");
|
|
//await printer.FeedLinesAsync(5);
|
|
|
|
//await printer.CutAsync();
|
|
|
|
|
|
|
|
////await CheckStatus(20);
|
|
|
|
//Task CheckStatus(int iterations)
|
|
//{
|
|
// return Task.Run(async () =>
|
|
// {
|
|
// for (int i = 0; i < iterations; i++)
|
|
// {
|
|
// var status = await printer.GetPrinterStatusAsync();
|
|
// Console.WriteLine($"Printer Status: {status}");
|
|
// var paperStatus = await printer.GetPaperSensorStatusAsync();
|
|
// Console.WriteLine($"Paper Sensor Status: {paperStatus}");
|
|
// await Task.Delay(100);
|
|
// }
|
|
// });
|
|
|
|
//}
|
|
|
|
|
|
//SoapEpsonPrinter printer = new SoapEpsonPrinter("10.0.20.11");
|
|
//SoapEpsonPrinter printer = new SoapEpsonPrinter("localhost:8888");
|
|
//var print = new SoapEpsonPrint();
|
|
//print
|
|
// .AddTextAlign(SoapEpsonPrint.ALIGN_CENTER)
|
|
// .AddTextSize(2, 2)
|
|
// .AddText("It works! Finally!!!")
|
|
// .AddFeed()
|
|
// .AddFeed()
|
|
// .AddFeed()
|
|
// .AddCut(SoapEpsonPrint.CUT_FEED);
|
|
|
|
//var task = await printer.Send(print);
|
|
//var status = await printer.GetStatus(print);
|
|
|
|
//Console.WriteLine($"Printer Status: {status}"); |