// Program is loaded. Start the processing void HPTest_Load(object sender, EventArgs e) { // Load saved settings LoadSettings(); // Initialize communications settings string[] Portnames = System.IO.Ports.SerialPort.GetPortNames(); cbPrinterPortName.Items.Clear(); cbPrinterPortName.Items.AddRange(Portnames); if (Portnames.Length > 0) { cbPrinterPortName.Items.AddRange(Portnames); cbPrinterPortName.SelectedIndex = 0; } // Instantiate the printer HP = new HitachiPrinter(this, 0) { PrinterType = HitachiPrinterType.UX, SOP4Enabled = true, EventLogging = HPEventLogging.All, MessageStyle = FormatSetup.Individual, MergeRequests = false, Shifts = new string[, ] { { "0:00", "7:00", "15:00", "23:00", "24:00" }, { "3", "1", "2", "3", "3" } } }; HP.Log += HP_Log; HP.Complete += HP_Complete; HP.Unsolicited += HP_Unsolicited; SetButtonEnables(); }
// Printer Status Unsolicited interrupt arrived void HP_Unsolicited(HitachiPrinter p, HPEventArgs e) { if (e.Message.StartsWith(HitachiPrinter.sSTX) && e.Message.EndsWith(HitachiPrinter.sETX)) { switch (e.Message.Substring(1, 1)) { case HitachiPrinter.sBEL: PrintStart(p, e); break; case HitachiPrinter.sDLE: PrintEnd(p, e); break; case "1": // It is a status break; default: // Who knows break; } } else { // Who knows } }
// Form is closing. Clean up the application void HPTest_FormClosing(object sender, FormClosingEventArgs e) { HP.Log -= HP_Log; HP.Complete -= HP_Complete; HP.Unsolicited -= HP_Unsolicited; HP = null; SaveSettings(); }
// Print End Unsolicited interrupt arrived void PrintEnd(HitachiPrinter p, HPEventArgs e) { // Send message to printer }
// Print Start Unsolicited interrupt arrived void PrintStart(HitachiPrinter p, HPEventArgs e) { // Add message build here }
// Requested operation has completed void HP_Complete(HitachiPrinter p, HPEventArgs e) { switch (e.Op) { case PrinterOps.Nop: break; case PrinterOps.Connect: break; case PrinterOps.Disconnect: break; case PrinterOps.IssueControl: break; case PrinterOps.ColumnSetup: break; case PrinterOps.WriteSpecification: break; case PrinterOps.WriteFormat: break; case PrinterOps.WriteText: break; case PrinterOps.WriteCalendarOffset: break; case PrinterOps.WriteCalendarSubZS: break; case PrinterOps.WriteCountCondition: break; case PrinterOps.WritePattern: break; case PrinterOps.Message: break; case PrinterOps.Fetch: if ((FetchOps)e.SubOp == FetchOps.Status) { HPStatus status = HP.GetStatus(); } break; case PrinterOps.Retrieve: break; case PrinterOps.RetrievePattern: break; case PrinterOps.SetClock: break; case PrinterOps.Idle: break; case PrinterOps.PassThru: break; case PrinterOps.ENQ: break; case PrinterOps.SOP16ClearBuffer: break; case PrinterOps.SOP16RestartPrinting: break; case PrinterOps.ChangeInkDropRule: break; case PrinterOps.ChangeMessageFormat: break; case PrinterOps.PositionItem: break; case PrinterOps.WriteCalendarZS: break; case PrinterOps.WriteCalendarSub: break; case PrinterOps.WriteCalendarSubRule: break; case PrinterOps.TimedDelay: break; case PrinterOps.CreateMessage: break; case PrinterOps.SendMessage: break; case PrinterOps.SetNozzle: break; case PrinterOps.ShutDown: break; default: break; } SetButtonEnables(); }
// Hitachi printer object has something noteworthy to say public void HP_Log(HitachiPrinter p, HPEventArgs e) { lbTraffic.Items.Add(HP.Translate(e.Message)); }