Merge commit '4357ad16c09a6503a0e2d727f76fcafee2c39853'
This commit is contained in:
@@ -55,5 +55,5 @@ Imports System.Windows
|
||||
' usando l'asterisco '*' come illustrato di seguito:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("2.3.8.1")>
|
||||
<Assembly: AssemblyFileVersion("2.3.8.1")>
|
||||
<Assembly: AssemblyVersion("2.4.4.1")>
|
||||
<Assembly: AssemblyFileVersion("2.4.4.1")>
|
||||
|
||||
+49
-14
@@ -14,6 +14,9 @@ Class ZebraPrinter
|
||||
Private m_sDataRoot As String
|
||||
Private m_Waiting As Boolean = True
|
||||
|
||||
Private m_sError As String = String.Empty
|
||||
Private m_FileError As String
|
||||
|
||||
' dichiarazione funzione per lettura file ini
|
||||
Private Declare Auto Function GetPrivateProfileString Lib "kernel32" (
|
||||
ByVal lpAppName As String,
|
||||
@@ -34,7 +37,8 @@ Class ZebraPrinter
|
||||
Else
|
||||
m_sDataRoot = sb.ToString
|
||||
End If
|
||||
m_FileLog = m_sDataRoot & "\Temp\ZebraPrinterUtilityLog.txt"
|
||||
Dim ThisMoment As Date = Now
|
||||
m_FileLog = m_sDataRoot & "\Temp\ZebraPrinterUtilityLog " & ThisMoment.Day.ToString & "_" & ThisMoment.Month & "_" & ThisMoment.Year & ".txt"
|
||||
If Not File.Exists(m_FileLog) Then
|
||||
Try
|
||||
File.Create(m_FileLog).Close()
|
||||
@@ -50,6 +54,11 @@ Class ZebraPrinter
|
||||
|
||||
End Sub
|
||||
|
||||
' creazio del file di errori
|
||||
Sub InitErrorFile()
|
||||
m_FileError = m_sDataRoot & "\Temp\" & "Error.txt"
|
||||
End Sub
|
||||
|
||||
' Funzione per scrivere nel file di Log
|
||||
Sub EmitLog(sLine As String)
|
||||
Dim sMessage As StreamWriter = File.AppendText(m_FileLog)
|
||||
@@ -57,7 +66,20 @@ Class ZebraPrinter
|
||||
sMessage.Close()
|
||||
End Sub
|
||||
|
||||
' collego la stampante
|
||||
' Scrivo solamente il primo errore che si verifica
|
||||
Sub EmitError(sIndexError As String)
|
||||
If Not String.IsNullOrEmpty(m_sError) Then Return
|
||||
Try
|
||||
Dim sMessage As StreamWriter = File.CreateText(m_FileError)
|
||||
sMessage.WriteLine("Error=" & sIndexError)
|
||||
sMessage.Close()
|
||||
m_sError = sIndexError
|
||||
Catch ex As Exception
|
||||
EmitLog("Impossible to create file Error.txt: " & ex.Message)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
' collego la stampante -> Error=1
|
||||
Friend Function ConnectPrinter() As Boolean
|
||||
Try
|
||||
Dim discoPrinters As List(Of DiscoveredPrinterDriver) = UsbDiscoverer.GetZebraDriverPrinters()
|
||||
@@ -65,17 +87,17 @@ Class ZebraPrinter
|
||||
Return True
|
||||
Catch ex As ConnectionException
|
||||
EmitLog("Printer connection error: " & ex.Message)
|
||||
EmitError("1")
|
||||
Return False
|
||||
Catch
|
||||
EmitLog("Printer not found error")
|
||||
EmitError("1")
|
||||
Return False
|
||||
End Try
|
||||
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()
|
||||
|
||||
' creo e stampo l'etichetta (ricevo il nome del template da usare) -> Error=3
|
||||
Public Sub Print(FilePath As String)
|
||||
Try
|
||||
' Connecting...
|
||||
m_printerConnection.Open()
|
||||
@@ -86,16 +108,21 @@ Class ZebraPrinter
|
||||
LabelFile = LabelFile.Replace(Variable.Key, Variable.Value)
|
||||
Next
|
||||
Dim LabelBytes As Byte() = Encoding.UTF8.GetBytes(LabelFile)
|
||||
Await Task.Delay(200)
|
||||
Task.Delay(200)
|
||||
' stampo etichetta
|
||||
m_printerConnection.Write(LabelBytes)
|
||||
m_Waiting = False
|
||||
EmitLog("Etichetta pronta")
|
||||
Catch __unusedConnectionException1__ As ConnectionException
|
||||
EmitLog(__unusedConnectionException1__.ToString)
|
||||
EmitError("3")
|
||||
' Communications Error
|
||||
Catch __unusedZebraPrinterLanguageUnknownException2__ As ZebraPrinterLanguageUnknownException
|
||||
EmitLog(__unusedZebraPrinterLanguageUnknownException2__.ToString)
|
||||
EmitError("3")
|
||||
Catch ex As Exception
|
||||
EmitLog(ex.ToString)
|
||||
EmitError("3")
|
||||
End Try
|
||||
|
||||
' Chiudo la connessione
|
||||
@@ -103,7 +130,7 @@ Class ZebraPrinter
|
||||
'Threading.Thread.Sleep(500)
|
||||
Threading.Thread.Sleep(200)
|
||||
' Disconnecting...
|
||||
If m_printerConnection IsNot Nothing Then
|
||||
If Not IsNothing(m_printerConnection) Then
|
||||
m_printerConnection.Close()
|
||||
EmitLog("Connessione stampante: CHIUSA")
|
||||
Threading.Thread.Sleep(1000)
|
||||
@@ -111,9 +138,11 @@ Class ZebraPrinter
|
||||
' Not Connected
|
||||
Catch __unusedConnectionException1__ As ConnectionException
|
||||
EmitLog(__unusedConnectionException1__.ToString)
|
||||
EmitError("3")
|
||||
Catch ex As Exception
|
||||
EmitLog(ex.ToString)
|
||||
EmitError("3")
|
||||
End Try
|
||||
|
||||
End Function)
|
||||
End Sub
|
||||
|
||||
|
||||
@@ -151,11 +180,13 @@ Class ZebraPrinter
|
||||
Sub New(args As String())
|
||||
|
||||
InitLog()
|
||||
InitErrorFile()
|
||||
ConnectPrinter()
|
||||
|
||||
' verifico che il numero di argomenti sia superiore a 2 (migliorare l'interpretazione dell'errore)
|
||||
If args.Length < 2 Then
|
||||
EmitLog("Non sono stati esplicictati tutti i file")
|
||||
EmitError("2")
|
||||
Return
|
||||
End If
|
||||
|
||||
@@ -163,17 +194,20 @@ Class ZebraPrinter
|
||||
' verifico che l'estensione del file sia corretta
|
||||
If Path.GetExtension(args(0)) <> ".prn" Then
|
||||
EmitLog("Estensione file template non corretta, diversa da .prn")
|
||||
EmitError("2")
|
||||
Return
|
||||
End If
|
||||
' verifico che il file esiste
|
||||
If Not File.Exists(args(0)) Then
|
||||
EmitLog("File '" & args(0) & "' non esiste.")
|
||||
EmitError("2")
|
||||
End If
|
||||
|
||||
EmitLog("File dati: " & args(1))
|
||||
' verifico che l'estensione del file sia corretta
|
||||
If Path.GetExtension(args(1)) <> ".ini" Then
|
||||
EmitLog("Estensione file dati non corretta, diversa da .ini")
|
||||
EmitError("2")
|
||||
Return
|
||||
End If
|
||||
|
||||
@@ -183,16 +217,17 @@ 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
|
||||
' se sono arrivato fino a qui provo a impostare che non ci sono stati errori
|
||||
' se ci fossero degli errori questo comando viene ignorato
|
||||
EmitError("0")
|
||||
|
||||
' 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
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<StartAction>Project</StartAction>
|
||||
<StartAction>Program</StartAction>
|
||||
<StartProgram>C:\EgtProg\OmagVIEW\ZebraPrinterUtilitiesD32.exe</StartProgram>
|
||||
<StartArguments>
|
||||
</StartArguments>
|
||||
|
||||
Reference in New Issue
Block a user