G
Guest
Here is the short story of what i'm trying to do. I have a 4 sided case
labeling printer setting out on one of our production lines. Now then i have
a vb.net application that sends data to this printer using a RawPrinterHelper
class that i found I believe in the msdn. the class works wonderfully when I
send stright text data (in the correctly formated string that the sato
printer requires.) but when i go to send a image nothing is happening. The
sato book that came with the printer shows me examples how to send a image to
this printer but the only problem is that the examples are in Qbasic. Here
is the example that the book gives me on how to send the job.
OPEN "WIZ.PCX" FOR INPUT AS #2
DA$ = INPUT$(15706,#2)
C$ = chr(27)
WIDTH "LPT1:", 255
LPRINT C$; "A";
LPRINT C$ "V150"; C$; "H100"; C$; "GP15706,"; DA$
LPRINT C$; "Q1"; C$; "Z";
CLOSE #2
so basicly it opens up a pcx image file, and reads its contents into the var
DA and sends it to the printer. all great and fine. but now onward to
converting it to vb.net code. Here is what i have done with it so far.
Dim fs As FileStream = New FileStream("C:\Kosher.pcx", FileMode.Open)
Dim imgData(fs.Length) As Byte
Dim pos As Integer
Dim b As Byte
Dim fileLen As String 'used because file size has to be 5 chars long
my pcx file size occurding to dos is 15464 which is 5 char in len so no
problems
len = fs.Length.ToString
While fs.Length > pos
b = fs.ReadByte
imgData(pos) = b
pos = pos + 1
End While
fs.Close()
'my file is now loaded as a byte array because i can not send a byte array
stright to the printer i have to convert it to a string so i can appened it
to my header information.
'problems start here. I have tried these subs and none seem to work.
Private Function ByteArrayToStringa(ByVal arrInput() As Byte) As String
Dim i As Integer
Dim sOutput As New System.Text.StringBuilder(arrInput.Length)
For i = 0 To arrInput.Length - 1
sOutput.Append(arrInput(i).ToString("X2"))
Next
Return sOutput.ToString()
End Function
Private Function BinaryToString(ByVal bNumber As Byte()) As String
Dim enc As System.Text.ASCIIEncoding
' Have also tried System.Text.UTF8Encoding and UnicodeEncoding
Return enc.GetEncoding("iso-8859-1").GetString(bNumber)
End Function
Public Function ByteArrayToString(ByVal bytArray() As Byte) As String
Dim UTF8 As New System.Text.UTF8Encoding
Return UTF8.GetString(bytArray)
End Function
'after the conversion has taken place create my string to send to the
printer class
dim satoPrintData as string
satoPrintData = Chr(27) & "A" & Chr(27) & "%3" & Chr(27) & _
"H0500" & Chr(27) & "V0500" & Chr(27) & _
"GP" & len & "," & sT & Chr(27) & "Q999999" & Chr(27) & "Z" 'qty to
print and end line
'i get the printer name from a wmi sub when the program first starts up.
RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName,
satoPrintData )
can someone please tell me where i'm going wrong.
cheers.
labeling printer setting out on one of our production lines. Now then i have
a vb.net application that sends data to this printer using a RawPrinterHelper
class that i found I believe in the msdn. the class works wonderfully when I
send stright text data (in the correctly formated string that the sato
printer requires.) but when i go to send a image nothing is happening. The
sato book that came with the printer shows me examples how to send a image to
this printer but the only problem is that the examples are in Qbasic. Here
is the example that the book gives me on how to send the job.
OPEN "WIZ.PCX" FOR INPUT AS #2
DA$ = INPUT$(15706,#2)
C$ = chr(27)
WIDTH "LPT1:", 255
LPRINT C$; "A";
LPRINT C$ "V150"; C$; "H100"; C$; "GP15706,"; DA$
LPRINT C$; "Q1"; C$; "Z";
CLOSE #2
so basicly it opens up a pcx image file, and reads its contents into the var
DA and sends it to the printer. all great and fine. but now onward to
converting it to vb.net code. Here is what i have done with it so far.
Dim fs As FileStream = New FileStream("C:\Kosher.pcx", FileMode.Open)
Dim imgData(fs.Length) As Byte
Dim pos As Integer
Dim b As Byte
Dim fileLen As String 'used because file size has to be 5 chars long
my pcx file size occurding to dos is 15464 which is 5 char in len so no
problems
len = fs.Length.ToString
While fs.Length > pos
b = fs.ReadByte
imgData(pos) = b
pos = pos + 1
End While
fs.Close()
'my file is now loaded as a byte array because i can not send a byte array
stright to the printer i have to convert it to a string so i can appened it
to my header information.
'problems start here. I have tried these subs and none seem to work.
Private Function ByteArrayToStringa(ByVal arrInput() As Byte) As String
Dim i As Integer
Dim sOutput As New System.Text.StringBuilder(arrInput.Length)
For i = 0 To arrInput.Length - 1
sOutput.Append(arrInput(i).ToString("X2"))
Next
Return sOutput.ToString()
End Function
Private Function BinaryToString(ByVal bNumber As Byte()) As String
Dim enc As System.Text.ASCIIEncoding
' Have also tried System.Text.UTF8Encoding and UnicodeEncoding
Return enc.GetEncoding("iso-8859-1").GetString(bNumber)
End Function
Public Function ByteArrayToString(ByVal bytArray() As Byte) As String
Dim UTF8 As New System.Text.UTF8Encoding
Return UTF8.GetString(bytArray)
End Function
'after the conversion has taken place create my string to send to the
printer class
dim satoPrintData as string
satoPrintData = Chr(27) & "A" & Chr(27) & "%3" & Chr(27) & _
"H0500" & Chr(27) & "V0500" & Chr(27) & _
"GP" & len & "," & sT & Chr(27) & "Q999999" & Chr(27) & "Z" 'qty to
print and end line
'i get the printer name from a wmi sub when the program first starts up.
RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName,
satoPrintData )
can someone please tell me where i'm going wrong.
cheers.