From 318a4e1d440567f2f64a90b771128c632a28cbdf Mon Sep 17 00:00:00 2001 From: NicolaP Date: Wed, 20 Oct 2021 15:55:31 +0200 Subject: [PATCH] Migliorata scrittura codice per stampa --- ZebraPrinter.vb | 88 +++++++++++++++---------------- ZebraPrinterUtilities.vbproj.user | 2 +- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/ZebraPrinter.vb b/ZebraPrinter.vb index a2660f1..a5dfb9f 100644 --- a/ZebraPrinter.vb +++ b/ZebraPrinter.vb @@ -73,47 +73,47 @@ Class ZebraPrinter End Function ' creo e stampo l'etichetta (ricevo il nome del template da usare) - Public Async Sub Print(FilePath As String) - Await Task.Run(Async Function() + Public Sub Print(FilePath As String) + Try + ' Connecting... + m_printerConnection.Open() + EmitLog("Connessione stampante: APERTA") + ' Sending Data... + Dim LabelFile As String = File.ReadAllText(FilePath) + For Each Variable In m_Values + LabelFile = LabelFile.Replace(Variable.Key, Variable.Value) + Next + Dim LabelBytes As Byte() = Encoding.UTF8.GetBytes(LabelFile) + Task.Delay(200) + ' stampo etichetta + m_printerConnection.Write(LabelBytes) + m_Waiting = False + EmitLog("Etichetta pronta") + Catch __unusedConnectionException1__ As ConnectionException + EmitLog(__unusedConnectionException1__.ToString) + ' Communications Error + Catch __unusedZebraPrinterLanguageUnknownException2__ As ZebraPrinterLanguageUnknownException + EmitLog(__unusedZebraPrinterLanguageUnknownException2__.ToString) + Catch ex As Exception + EmitLog(ex.ToString) + End Try - Try - ' Connecting... - m_printerConnection.Open() - EmitLog("Connessione stampante: APERTA") - ' Sending Data... - Dim LabelFile As String = File.ReadAllText(FilePath) - For Each Variable In m_Values - LabelFile = LabelFile.Replace(Variable.Key, Variable.Value) - Next - Dim LabelBytes As Byte() = Encoding.UTF8.GetBytes(LabelFile) - Await Task.Delay(200) - ' stampo etichetta - m_printerConnection.Write(LabelBytes) - m_Waiting = False - EmitLog("Etichetta pronta") - Catch __unusedConnectionException1__ As ConnectionException - EmitLog(__unusedConnectionException1__.ToString) - ' Communications Error - Catch __unusedZebraPrinterLanguageUnknownException2__ As ZebraPrinterLanguageUnknownException - EmitLog(__unusedZebraPrinterLanguageUnknownException2__.ToString) - End Try - - ' Chiudo la connessione - Try - 'Threading.Thread.Sleep(500) - Threading.Thread.Sleep(200) - ' Disconnecting... - If m_printerConnection IsNot Nothing Then - m_printerConnection.Close() - EmitLog("Connessione stampante: CHIUSA") - Threading.Thread.Sleep(1000) - End If - ' Not Connected - Catch __unusedConnectionException1__ As ConnectionException - EmitLog(__unusedConnectionException1__.ToString) - End Try - - End Function) + ' Chiudo la connessione + Try + 'Threading.Thread.Sleep(500) + Threading.Thread.Sleep(200) + ' Disconnecting... + If Not IsNothing(m_printerConnection) Then + m_printerConnection.Close() + EmitLog("Connessione stampante: CHIUSA") + Threading.Thread.Sleep(1000) + End If + ' Not Connected + Catch __unusedConnectionException1__ As ConnectionException + EmitLog(__unusedConnectionException1__.ToString) + Catch ex As Exception + EmitLog(ex.ToString) + End Try End Sub @@ -183,16 +183,14 @@ Class ZebraPrinter Print(args(0)) ' metto il programmma in attesa - Dim nCiclo As Integer = 0 - While m_Waiting And nCiclo < 6 - Threading.Thread.Sleep(1000) - nCiclo += 1 - End While + Threading.Thread.Sleep(1000) + ' elimino il file dei dati Try File.Delete(args(1)) EmitLog("Eliminato file " & args(1)) Catch ex As Exception + EmitLog(ex.ToString) End Try End Sub diff --git a/ZebraPrinterUtilities.vbproj.user b/ZebraPrinterUtilities.vbproj.user index 8df751f..48448b1 100644 --- a/ZebraPrinterUtilities.vbproj.user +++ b/ZebraPrinterUtilities.vbproj.user @@ -1,7 +1,7 @@  - Project + Program C:\EgtProg\OmagVIEW\ZebraPrinterUtilitiesD32.exe