Option Strict Off
Option Explicit On
Imports System
Imports System.IO
Imports Microsoft.VisualBasic
Module ReadBarCodes
Sub Main()
If My.Application.CommandLineArgs.Count > 0 Then
'MsgBox(My.Application.CommandLineArgs(0))
OpenCom(My.Application.CommandLineArgs(0))
'Environment.ExitCode = 0
If Environment.ExitCode = 0 Then
ReadBarCode()
Else
Environment.ExitCode = 1
End If
Else
MsgBox("Inga argument angivna")
Environment.ExitCode = 1
End If
End Sub
Sub OpenCom(ByVal port)
Dim dwRC As Long
Dim dwComPort As Long
dwComPort = port
'Open the com port
dwRC = csp2Init(dwComPort)
If dwRC <> STATUS_OK Then
MsgBox("Kunde inte ansluta till läsaren. Felkod: (Com - " & CStr(dwComPort + 1) & ")")
Environment.ExitCode = 1
Else
Environment.ExitCode = 0
End If
End Sub
Sub ReadBarCode()
Dim nRC As Integer
Dim nNumOfBarcodes As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim CDir As String
Dim arrbyteBarcode(99) As Byte '100 elements
Dim nBytesRead As Integer
Dim bstrBarcode As String
Dim bstrTmp As String
CDir = CurDir()
'Determine if we can read the data
nRC = csp2ReadData
If nRC > 0 Then
Dim LogFile As String = CDir & "\bc"
If File.Exists(LogFile) Then
File.Delete(LogFile)
End If
Dim objWriter As New StreamWriter(LogFile)
'cs1504 has barcodes!
nNumOfBarcodes = nRC
objWriter.WriteLine(nNumOfBarcodes)
Dim aryText(nNumOfBarcodes) As String
'k = 1
k = 0
'aryText(0) = "Reading " & CStr(nRC) & " Barcodes at " & TimeOfDay
'MsgBox("Reading " & CStr(nRC) & " Barcodes at " & TimeOfDay)
'Check to see that we are in ascii mode...
If csp2GetASCIIMode = PARAM_ON Then
For i = 0 To (nNumOfBarcodes - 1)
nBytesRead = csp2GetPacket(arrbyteBarcode(0), i, 100)
If nBytesRead > 0 Then
'bstrBarcode = "Rcvd: "
'Display the Barcode type
nRC = csp2GetCodeType(arrbyteBarcode(1), bstrTmp, Len(bstrTmp))
'DisplayInBCWindow(bstrTmp)
bstrBarcode = " "
' display the barcode is ascii
' skip the length, type, .... timestamp
For j = 2 To (nBytesRead - 5)
bstrBarcode = bstrBarcode & Chr(arrbyteBarcode(j))
'DisplayInBCWindow Chr(arrbyteBarcode(j))
Next j
'Display the timestamp
nRC = csp2TimeStamp2Str(arrbyteBarcode(nBytesRead - 4), bstrTmp, Len(bstrTmp))
aryText(k) = bstrBarcode & " " & Left(bstrTmp, 20)
k = k + 1
End If
Next i
For l = 0 To (k - 1)
objWriter.WriteLine(aryText(l))
Next l
Else
'Add binary mode packets handling here..
MsgBox("Binary Mode är PÅ")
End If
objWriter.Close()
ClearAndPowerDown()
Environment.ExitCode = 0
Else
MsgBox("Det fanns inga streckoder i läsaren")
Environment.ExitCode = 1
End If
End Sub
Sub ClearAndPowerDown()
Dim nRC2 As Integer
nRC2 = csp2ClearData()
If nRC2 <> STATUS_OK Then
End If
End Sub
End Module