Modules | |
Enumerations | |
Events related with the printers and jobs | |
Classes | |
class | DeepsyPrinterManager |
Manager for access the printers functionalities and events raised More... | |
Detailed Description
To work with Deepsy printer service it is necessary to use DeepsyPrinterManager located in GMV.ITS.HAL.DEEPSY.Printer.Facade for getting the initial PrinterManager object.
To obtain a list of Printers objects:
Examples
-
Add print job
For adding a print job it is necessary to call to PrintImage method of Printer.using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.Printer{class AddPrintJobApp{static void Main(string[] args){Console.WriteLine($"Printer. Add job example");string deepsyServerIp = args?[0];DeepsyPrinterManager printerManager = new DeepsyPrinterManager(deepsyServerIp);List<IPrinter> printerList = printerManager.Printers.ToList();Console.WriteLine($"There are {printerList?.Count} printers.");{// The image is previously stored in deepsy deviceprinter.PrintImage("/tmp/ticket.png");}Console.WriteLine("Press ESC for exit");while (Console.ReadKey().Key != ConsoleKey.Escape){}}}}
-
Set printer configuration
Setting printer configuration is provided by Printer.SetDefaultConfiguration. In this example, there is a change in paper width configuration.using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.Printer{class SetPrinterConfigurationApp{static void Main(string[] args){Console.WriteLine($"Printer. Set configuration");string deepsyServerIp = args?[0];DeepsyPrinterManager printerManager = new DeepsyPrinterManager(deepsyServerIp);List<IPrinter> printerList = printerManager.Printers.ToList();Console.WriteLine($"There are {printerList?.Count} printers.");PrinterConfigDto printerConfigDto = new PrinterConfigDto(){PrinterParameter = PrinterParameter.PaperWidth,Value = 50};PrinterConfigDto printerSpeedConfigDto = new PrinterConfigDto(){PrinterParameter = PrinterParameter.Speed,Value = 2};{printer.SetDefaultConfiguration(printerConfigDto);printer.SetDefaultConfiguration(printerSpeedConfigDto);}Console.WriteLine("Press ESC for exit");while (Console.ReadKey().Key != ConsoleKey.Escape){}}}}
-
Print a self-test ticket An example on how to print a self-test ticket is provided: using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.Printer{class SelfTicketApp{static void Main(string[] args){Console.WriteLine($"Printer. Print self ticket");string deepsyServerIp = args?[0];DeepsyPrinterManager printerManager = new DeepsyPrinterManager(deepsyServerIp,8150,8151);List<IPrinter> printerList = printerManager.Printers.ToList();Console.WriteLine($"There are {printerList?.Count} printers.");{// It can be printed using the printer managerprinter.PrintTestTicket();}Console.WriteLine("Press ESC for exit");while (Console.ReadKey().Key != ConsoleKey.Escape){}}}}
-
Subscribe to events
There are 4 types of events in the printer system:- PrinterList : This event happens when a printer is added to or removed from the system. To receive this kind of events, it is necessary to subscribe to the PrinterManager object
- PrinterAlarm : This event happens when a printer starts or stops having an alarm. To receive this kind of events, it is necessary to subscribe to the PrinterManager object
- PrinterStatus : This event happens when a printer status changes. To receive this kind of events, it is necessary to subscribe to the PrinterManager object
- PaperLevel : This event happens when a printer starts or stops having an paperLevel. To receive this kind of events, it is necessary to subscribe to the PrinterManager object
-
JobStatus : This event happens when a job status changes. To receive this kind of events, it is necessary to subscribe to the PrinterManager object
This example subscribes to every event.
using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.Printer{class PrinterEventsApp{static void Main(string[] args){Console.WriteLine($"Printer. Events");string deepsyServerIp = args.Length == 0 ? "192.168.0.144" : args[0];DeepsyPrinterManager printerManager = new DeepsyPrinterManager(deepsyServerIp);List<IPrinter> printerList = printerManager.Printers.ToList();Console.WriteLine($"There are {printerList?.Count} printers.");printerManager.PrinterList += PrinterManager_PrinterList;{printer.PrinterAlarm += PrinterManager_PrinterAlarm;printer.PrinterStatus += PrinterManager_PrinterStatus;printer.PaperLevel += PrinterManager_PaperLevel;printer.ImageList += PrinterManager_ImageList;}IList<IPrinterConfigDto> configurations = new List<IPrinterConfigDto>();configurations.Add(new PrinterConfigDto() { PrinterParameter = PrinterParameter.PaperAdj, Value = 1 });{IJob job = printer.PrintImage("/etc/tickets/my_ticket.png", configurations);job.JobStatus += PrinterManager_JobStatus;}Console.WriteLine("Press ESC for exit");while (Console.ReadKey().Key != ConsoleKey.Escape){}}private static void PrinterManager_JobStatus(object sender, DEEPSY.Printer.Interface.Event.JobStatusEvent e){Console.WriteLine($"Job ${e.JobId} status: {e.JobStatus}");}private static void PrinterManager_PaperLevel(object sender, DEEPSY.Printer.Interface.Event.PaperLevelEvent e){Console.WriteLine($"Printer ${e.Printer.PrinterInformation.SerialNumber} paper level: {e.PaperLevel}");}private static void PrinterManager_PrinterStatus(object sender, DEEPSY.Printer.Interface.Event.PrinterStatusEvent e){Console.WriteLine($"Printer ${e.Printer.PrinterInformation.SerialNumber} status: {e.Status}");}private static void PrinterManager_PrinterAlarm(object sender, DEEPSY.Printer.Interface.Event.PrinterAlarmEvent e){Console.WriteLine($"Printer ${e.Printer.PrinterInformation.SerialNumber} event: {e.Alarm}");}private static void PrinterManager_PrinterList(object sender, DEEPSY.Printer.Interface.Event.PrinterListEvent e){Console.WriteLine($"Printer list ${e.Printer.PrinterInformation.SerialNumber} {e.Action}");}private static void PrinterManager_ImageList(object sender, DEEPSY.Printer.Interface.Event.ImageListEvent e){if (e.Action == HAL.DEEPSY.Printer.Interface.Enum.PrinterListAction.Added){Console.WriteLine($"Image {e.Image.Uri} stored in slot {e.Image.SlotId} of printer {e.Printer.Id}");}else{Console.WriteLine($"Image deleted from slot {e.Image.SlotId} of printer {e.Printer.Id}");}}}}
-
Paper Level
using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.Printer{class PaperLevelApp{static void Main(string[] args){Console.WriteLine($"Printer. Paper level");string deepsyServerIp = args?[0];DeepsyPrinterManager printerManager = new DeepsyPrinterManager(deepsyServerIp);List<IPrinter> printerList = printerManager.Printers.ToList();Console.WriteLine($"There are {printerList?.Count} printers.");{printer.PrinterAlarm += PrinterManager_PrinterAlarm;printer.PrinterStatus += PrinterManager_PrinterStatus;printer.PaperLevel += PrinterManager_PaperLevel;}IList<IPrinterConfigDto> configurations = new List<IPrinterConfigDto>();configurations.Add(new PrinterConfigDto() { PrinterParameter = PrinterParameter.PaperAdj, Value = 1 });{IPrinterInformationDto printerInformationDto = printer.PrinterInformation;Console.WriteLine($"SN {printerInformationDto.SerialNumber} Paper Level: {printerInformationDto.PaperLevel}");}Console.WriteLine("Press ESC for exit");while (Console.ReadKey().Key != ConsoleKey.Escape){}}private static void PrinterManager_JobStatus(object sender, DEEPSY.Printer.Interface.Event.JobStatusEvent e){Console.WriteLine($"Job ${e.JobId} status: {e.JobStatus}");}private static void PrinterManager_PaperLevel(object sender, DEEPSY.Printer.Interface.Event.PaperLevelEvent e){Console.WriteLine($"Printer ${e.Printer.PrinterInformation.SerialNumber} paper level: {e.PaperLevel}");}private static void PrinterManager_PrinterStatus(object sender, DEEPSY.Printer.Interface.Event.PrinterStatusEvent e){Console.WriteLine($"Printer ${e.Printer.PrinterInformation.SerialNumber} status: {e.Status}");}private static void PrinterManager_PrinterAlarm(object sender, DEEPSY.Printer.Interface.Event.PrinterAlarmEvent e){Console.WriteLine($"Printer ${e.Printer.PrinterInformation.SerialNumber} event: {e.Alarm}");}private static void PrinterManager_PrinterList(object sender, DEEPSY.Printer.Interface.Event.PrinterListEvent e){Console.WriteLine($"Printer list ${e.Printer.PrinterInformation.SerialNumber} {e.Action}");}}}
-
Store and print image (DTD200)
A stored image is placed in one of the allowed slots of the printer, the stored image is printed, and then it is deleted from that slot.using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.Printer{class StoreAndPrintImageApp{static void Main(string[] args){try{Console.WriteLine($"Printer. Store an print image");DeepsyPrinterManager printerManager = new DeepsyPrinterManager("192.168.0.150");List<IPrinter> printerList = printerManager.GetPrinters().ToList();Console.WriteLine($"There are {printerList?.Count} printers.");if (printerList.Count <= 0){Console.WriteLine($"No printers found. Aborting.");return;}IPrinter printer = printerList.First();string imagePath = "/tmp/image.png";int slotId = 1;Console.WriteLine($"Getting NV images list");IEnumerable<INVImageDto> images = printer.GetNVImageList();PrintImages(images);Console.WriteLine($"Storing NV image in slot {slotId} with path {imagePath}");printer.StoreNVImage(imagePath, slotId);System.Threading.Thread.Sleep(1000);Console.WriteLine($"Getting NV images list");images = printer.GetNVImageList();PrintImages(images);IEnumerable<IPrinterConfigDto> configs = new List<IPrinterConfigDto>(){new PrinterConfigDto(PrinterParameter.PaperWidth, 57),new PrinterConfigDto(PrinterParameter.TicketOffset, 1),new PrinterConfigDto(PrinterParameter.LeftMargin, 2),new PrinterConfigDto(PrinterParameter.RightMargin, 2),new PrinterConfigDto(PrinterParameter.UpperMargin, 10),new PrinterConfigDto(PrinterParameter.BottomMargin, 20),new PrinterConfigDto(PrinterParameter.CutProfile, 2),};Console.WriteLine($"Printing NV image");printer.PrintNVImage(slotId, configs);System.Threading.Thread.Sleep(1000);Console.WriteLine($"Deleting NV image");printer.DeleteNVImage(slotId);System.Threading.Thread.Sleep(1000);Console.WriteLine($"Getting NV images list");images = printer.GetNVImageList();PrintImages(images);Console.WriteLine($"Finished successfully");return;}catch (HalException deepsyEx){Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");}catch (Exception ex){Console.WriteLine($"Error Not Handled exception {ex.Message}");}}private static void PrintImages(IEnumerable<INVImageDto> imgs){Console.WriteLine($"There are {imgs.Count()} images stored");if (imgs.Count() <= 0) return;int maxPathLength = imgs.Select(i => i.Uri.Length).Max();maxPathLength = maxPathLength > 6 ? maxPathLength : 6;int spaces1 = (maxPathLength - 4) / 2;int spaces2 = maxPathLength - spaces1 - 4;Console.WriteLine($" Slot id | {new string(' ', spaces1)}Path{new string(' ', spaces2)} | Width | Height | MD5 | MD5 Base64 ");Console.WriteLine($"-----------{new string('-', maxPathLength)}---------------------------------------------------------------------------------------");imgs.ToList().ForEach(img => Console.WriteLine($" {img.SlotId} | {img.Uri}{new string(' ', maxPathLength - img.Uri.Length)} | {img.Width} | {img.Height} | {img.Md5} | {img.Md5Base64}"));}}}
-
Print html ticket (DTD200)
The HTML file to be printed includes a header that is first stored in the printer, then printed, and finally deleted from the printer.using System;using System.Collections.Generic;using System.Linq;namespace GMV.ITS.HAL.DEEPSY.Examples.Printer{class AddPrintJobHtmlApp{static void Main(string[] args){Console.WriteLine($"Printer. Add job example");string deepsyServerIp = args.Length == 0 ? "192.168.0.150" : args[0];DeepsyPrinterManager printerManager = new DeepsyPrinterManager(deepsyServerIp);List<IPrinter> printerList = printerManager.Printers.ToList();Console.WriteLine($"There are {printerList?.Count} printers.");{// Store image in deepsy deviceprinter.StoreNVImage("/tmp/ticket.png",1);}System.Threading.Thread.Sleep(1000);{// The header image is previously stored in deepsy device (ticket.png)printer.PrintHtml("/tmp/ticket.html");}System.Threading.Thread.Sleep(5000);{printer.DeleteNVImage(1);}Console.WriteLine("Press ESC for exit");while (Console.ReadKey().Key != ConsoleKey.Escape){}}}}