Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

need some add-on to interface BarCode Printer with SAP B1 2005B

hi all,

its very urgent, is there any addon to make interface of Barcode Printer with SAP B12005B. we need to print the barcode(in our case item number), MRP price and AP invoice. is there any possibility to do that with SAP B1. here the barcode Printer understand onlu EPL coding, which should be run in DOS mode. for example :- here EPL code should run in .bat format . kaindly give me some solution, i gave the needfull details.

its very urgent our SAP implementation si over only this BarCode Printer interface needed with SAP. kindly revert back soon.

Barcode Printer print the Barcode in Sticker format so that they can stick it to the items, it consist of name of the company,barcode number(item number),MRP price, AP invoice.

regards

sandip

Former Member
Former Member replied

hi sandip

I had to integrate to a zebra printer and although I did not print a barcode I did print text onto a label.

First of all I had to create a raw print class, this will send a string to the printer:

Imports System.IO

Imports System.Drawing.Printing

Imports System.Runtime.InteropServices

Public Class RawPrinterHelper

Inherits UIEvent

Public Sub New(ByRef Formuid As String)

MyBase.New(formuid)

End Sub

' Structure and API declarions:

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _

Structure DOCINFOW

<MarshalAs(UnmanagedType.LPWStr)> Public pDocName As String

<MarshalAs(UnmanagedType.LPWStr)> Public pOutputFile As String

<MarshalAs(UnmanagedType.LPWStr)> Public pDataType As String

End Structure

<DllImport("winspool.Drv", EntryPoint:="OpenPrinterW", _

SetLastError:=True, CharSet:=CharSet.Unicode, _

ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function OpenPrinter(ByVal src As String, ByRef hPrinter As IntPtr, ByVal pd As IntPtr) As Boolean

End Function

<DllImport("winspool.Drv", EntryPoint:="ClosePrinter", _

SetLastError:=True, CharSet:=CharSet.Unicode, _

ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function ClosePrinter(ByVal hPrinter As IntPtr) As Boolean

End Function

<DllImport("winspool.Drv", EntryPoint:="StartDocPrinterW", _

SetLastError:=True, CharSet:=CharSet.Unicode, _

ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function StartDocPrinter(ByVal hPrinter As IntPtr, ByVal level As Int32, ByRef pDI As DOCINFOW) As Boolean

End Function

<DllImport("winspool.Drv", EntryPoint:="EndDocPrinter", _

SetLastError:=True, CharSet:=CharSet.Unicode, _

ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function EndDocPrinter(ByVal hPrinter As IntPtr) As Boolean

End Function

<DllImport("winspool.Drv", EntryPoint:="StartPagePrinter", _

SetLastError:=True, CharSet:=CharSet.Unicode, _

ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function StartPagePrinter(ByVal hPrinter As IntPtr) As Boolean

End Function

<DllImport("winspool.Drv", EntryPoint:="EndPagePrinter", _

SetLastError:=True, CharSet:=CharSet.Unicode, _

ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function EndPagePrinter(ByVal hPrinter As IntPtr) As Boolean

End Function

<DllImport("winspool.Drv", EntryPoint:="WritePrinter", _

SetLastError:=True, CharSet:=CharSet.Unicode, _

ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function WritePrinter(ByVal hPrinter As IntPtr, ByVal pBytes As IntPtr, ByVal dwCount As Int32, ByRef dwWritten As Int32) As Boolean

End Function

' SendBytesToPrinter()

' When the function is given a printer name and an unmanaged array of

' bytes, the function sends those bytes to the print queue.

' Returns True on success or False on failure.

Public Function SendBytesToPrinter(ByVal szPrinterName As String, ByVal pBytes As IntPtr, ByVal dwCount As Int32) As Boolean

Dim hPrinter As New IntPtr ' The printer handle.

Dim dwError As Int32 ' Last error - in case there was trouble.

Dim di As New DOCINFOW ' Describes your document (name, port, data type).

Dim dwWritten As Int32 ' The number of bytes written by WritePrinter().

Dim bSuccess As Boolean ' Your success code.

' Set up the DOCINFO structure.

With di

.pDocName = "EMON Serial Number Label"

.pDataType = "RAW"

End With

' Assume failure unless you specifically succeed.

bSuccess = False

If OpenPrinter(szPrinterName, hPrinter, 0) Then

If StartDocPrinter(hPrinter, 1, di) Then

If StartPagePrinter(hPrinter) Then

' Write your printer-specific bytes to the printer.

bSuccess = WritePrinter(hPrinter, pBytes, dwCount, dwWritten)

EndPagePrinter(hPrinter)

End If

EndDocPrinter(hPrinter)

End If

ClosePrinter(hPrinter)

End If

' If you did not succeed, GetLastError may give more information

' about why not.

If bSuccess = False Then

dwError = Marshal.GetLastWin32Error()

MyBase.Displayerror("Print error : " & Convert.ToString(dwError))

End If

Return bSuccess

End Function ' SendBytesToPrinter()

' SendFileToPrinter()

' When the function is given a file name and a printer name,

' the function reads the contents of the file and sends the

' contents to the printer.

' Presumes that the file contains printer-ready data.

' Shows how to use the SendBytesToPrinter function.

' Returns True on success or False on failure.

Public Function SendFileToPrinter(ByVal szPrinterName As String, ByVal szFileName As String) As Boolean

' Open the file.

Dim fs As New FileStream(szFileName, FileMode.Open)

' Create a BinaryReader on the file.

Dim br As New BinaryReader(fs)

' Dim an array of bytes large enough to hold the file's contents.

Dim bytes(fs.Length) As Byte

Dim bSuccess As Boolean

' Your unmanaged pointer.

Dim pUnmanagedBytes As IntPtr

' Read the contents of the file into the array.

bytes = br.ReadBytes(fs.Length)

' Allocate some unmanaged memory for those bytes.

pUnmanagedBytes = Marshal.AllocCoTaskMem(fs.Length)

' Copy the managed byte array into the unmanaged array.

Marshal.Copy(bytes, 0, pUnmanagedBytes, fs.Length)

' Send the unmanaged bytes to the printer.

bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, fs.Length)

' Free the unmanaged memory that you allocated earlier.

Marshal.FreeCoTaskMem(pUnmanagedBytes)

Return bSuccess

End Function ' SendFileToPrinter()

' When the function is given a string and a printer name,

' the function sends the string to the printer as raw bytes.

Public Sub SendStringToPrinter(ByVal szPrinterName As String, ByVal szString As String)

Dim pBytes As IntPtr

Dim dwCount As Int32

' How many characters are in the string?

dwCount = szString.Length()

' Assume that the printer is expecting ANSI text, and then convert

' the string to ANSI text.

pBytes = Marshal.StringToCoTaskMemAnsi(szString)

' Send the converted ANSI string to the printer.

SendBytesToPrinter(szPrinterName, pBytes, dwCount)

Marshal.FreeCoTaskMem(pBytes)

End Sub

End Class

Then I used the ZPL programming format to create a label and pass it the printer...

Public Sub printlabeltoprinter(ByRef printer As String)

Dim strsql As String = "Select U_XX_PLOC from [@OPRT] where " & _

"code = '" & printer & "' "

Dim PrinterName As String = MyBase.ReturnValueSQLQuery(strsql)

Dim s As String

Dim hdrcon As String = "A0,45,36"

Dim hdrstart As Integer = 390

Dim subhdrstart As Integer = 290

'Dim staticstart As Integer = 202

Dim varstart As Integer = 380

'Dim linecon1 As String = "A0,37,28,1"

Dim linecon As String = "A0,37,30"

Dim subhdrcon As String = "A0,37,32"

Dim srlcon As String = "A0,42,42"

Dim linestart As Integer = 95

Dim lineheight As Integer = 38

Dim linespacer As Integer = 2

' You need a string to send.

s = "^XA" & _

"FO" & hdrstart & ",50" & hdrcon & "FD" & Labelname & "FS" & _

"FO" & subhdrstart & "," & Convert.ToString(linestart) & "" & subhdrcon & "FD" & ItemDesc & "FS" & _

"FO202," & Convert.ToString(linestart + lineheight + linespacer) & "" & linecon & "FDModel No:FS" & _

"FO" & varstart & "," & Convert.ToString(linestart + lineheight + linespacer) & "" & linecon & "FD" & ItemNo & "FS" & _

"FO158," & Convert.ToString(linestart + ((lineheight + linespacer) * 2)) & "" & linecon & "FDConfiguration:FS" & _

"FO" & varstart & "," & Convert.ToString(linestart + ((lineheight + linespacer) * 2)) & "" & linecon & "FD" & Configuration & "FS" & _

"FO229," & Convert.ToString(linestart + ((lineheight + linespacer) * 3)) & "" & linecon & "FDVoltage:FS" & _

"FO" & varstart & "," & Convert.ToString(linestart + ((lineheight + linespacer) * 3)) & "" & linecon & "FD" & Voltage & " : " & MHZ & "FS" & _

"FO86," & Convert.ToString(linestart + ((lineheight + linespacer) * 4)) & "" & linecon & "FDInput Power Rating:FS" & _

"FO" & varstart & "," & Convert.ToString(linestart + ((lineheight + linespacer) * 4)) & "" & linecon & "FD" & InputPowerRating & "FS" & _

"FO53," & Convert.ToString(linestart + ((lineheight + linespacer) * 5)) & "" & linecon & "FDCurrent Sensor Rating:FS " & _

"FO" & varstart & "," & Convert.ToString(linestart + ((lineheight + linespacer) * 5)) & "" & linecon & "FD" & CurrentSensorRating & "FS" & _

"FO209," & Convert.ToString(linestart + ((lineheight + linespacer) * 6)) & "" & linecon & "FDSerial No:FS" & _

"FO" & varstart & "," & Convert.ToString(linestart + ((lineheight + linespacer) * 6)) & "" & linecon & "FD" & SerialNo & "FS" & _

"FO156," & Convert.ToString(linestart + ((lineheight + linespacer) * 7)) & "" & linecon & "FDMfg. Location:FS" & _

"FO" & varstart & "," & Convert.ToString(linestart + ((lineheight + linespacer) * 7)) & "" & linecon & "FDPAFS" & _

"FO130,525" & srlcon & "FD" & SerialNo & "FS" & _

"FO697,525" & srlcon & "FD" & SerialNo & "FS" & _

"^XZ"

' Open the printer dialog box, and then allow the user to select a printer.

Dim ConnecttoPrinter As New RawPrinterHelper(MyBase.form.UniqueID)

ConnecttoPrinter.SendStringToPrinter(PrinterName, s)

ConnecttoPrinter.release()

End Sub

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question