Migliorata scrittura codice per stampa
This commit is contained in:
+43
-45
@@ -73,47 +73,47 @@ Class ZebraPrinter
|
|||||||
End Function
|
End Function
|
||||||
|
|
||||||
' creo e stampo l'etichetta (ricevo il nome del template da usare)
|
' creo e stampo l'etichetta (ricevo il nome del template da usare)
|
||||||
Public Async Sub Print(FilePath As String)
|
Public Sub Print(FilePath As String)
|
||||||
Await Task.Run(Async Function()
|
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
|
' Chiudo la connessione
|
||||||
' Connecting...
|
Try
|
||||||
m_printerConnection.Open()
|
'Threading.Thread.Sleep(500)
|
||||||
EmitLog("Connessione stampante: APERTA")
|
Threading.Thread.Sleep(200)
|
||||||
' Sending Data...
|
' Disconnecting...
|
||||||
Dim LabelFile As String = File.ReadAllText(FilePath)
|
If Not IsNothing(m_printerConnection) Then
|
||||||
For Each Variable In m_Values
|
m_printerConnection.Close()
|
||||||
LabelFile = LabelFile.Replace(Variable.Key, Variable.Value)
|
EmitLog("Connessione stampante: CHIUSA")
|
||||||
Next
|
Threading.Thread.Sleep(1000)
|
||||||
Dim LabelBytes As Byte() = Encoding.UTF8.GetBytes(LabelFile)
|
End If
|
||||||
Await Task.Delay(200)
|
' Not Connected
|
||||||
' stampo etichetta
|
Catch __unusedConnectionException1__ As ConnectionException
|
||||||
m_printerConnection.Write(LabelBytes)
|
EmitLog(__unusedConnectionException1__.ToString)
|
||||||
m_Waiting = False
|
Catch ex As Exception
|
||||||
EmitLog("Etichetta pronta")
|
EmitLog(ex.ToString)
|
||||||
Catch __unusedConnectionException1__ As ConnectionException
|
End Try
|
||||||
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)
|
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
|
||||||
@@ -183,16 +183,14 @@ Class ZebraPrinter
|
|||||||
Print(args(0))
|
Print(args(0))
|
||||||
|
|
||||||
' metto il programmma in attesa
|
' metto il programmma in attesa
|
||||||
Dim nCiclo As Integer = 0
|
Threading.Thread.Sleep(1000)
|
||||||
While m_Waiting And nCiclo < 6
|
|
||||||
Threading.Thread.Sleep(1000)
|
|
||||||
nCiclo += 1
|
|
||||||
End While
|
|
||||||
' elimino il file dei dati
|
' elimino il file dei dati
|
||||||
Try
|
Try
|
||||||
File.Delete(args(1))
|
File.Delete(args(1))
|
||||||
EmitLog("Eliminato file " & args(1))
|
EmitLog("Eliminato file " & args(1))
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
|
EmitLog(ex.ToString)
|
||||||
End Try
|
End Try
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||||
<StartAction>Project</StartAction>
|
<StartAction>Program</StartAction>
|
||||||
<StartProgram>C:\EgtProg\OmagVIEW\ZebraPrinterUtilitiesD32.exe</StartProgram>
|
<StartProgram>C:\EgtProg\OmagVIEW\ZebraPrinterUtilitiesD32.exe</StartProgram>
|
||||||
<StartArguments>
|
<StartArguments>
|
||||||
</StartArguments>
|
</StartArguments>
|
||||||
|
|||||||
Reference in New Issue
Block a user