send text to printer via LPT1

MasterX

New member
Joined
Jul 12, 2012
Messages
4
Programming Experience
1-3
hi, i'm italian.
sorry for the English is not prefect. I'm writing an application in VB.NET
I print to a printer epson tm 220 with escape commands or in other mode, without driver
you can help me to write "hello world" ?
I maybe a simple link

thanks
wave.gif
 
and I don't get what you mean by "escape commands" xd
I don't think you can print; it's a lpt1 printer; if you go pippo.txt > lpt1: , it's print without driver; to escape commands are commands that some printers have. you how print ?
 
italian:
non penso che non si possa stampare. è una stampante su lpt1. se tu da dos fai pippo.txt > lpt1: stampa senza driver ; per comandi escape ci sono dei comandi che alcune stampanti hanno. tu come stamperesti

english:
I don't think you can print; it's a lpt1 printer; if you go pippo.txt > lpt1: , it's print without driver; to escape commands are commands that some printers have. you how print ?

you answered yourself. Create a batch file (*.bat) that executes your command and run it from vb with the Shell function :)
 
Or you can use the well-known InpOut32 library... I have written a basic wrapper class for it a little while ago to communicate with a development board:

Imports System.Runtime.InteropServices

Public NotInheritable Class clsParPortControl
    Private m_bX64 As Boolean = False
    Private dwLastError As Int32
    Private tmp As Boolean = False

    Public Sub New()
        MyBase.New()
    End Sub

    Public ReadOnly Property LastError As Int32
        Get
            Return dwLastError
        End Get
    End Property

    Public ReadOnly Property Opened As Boolean
        Get
            tmp = IsParPortDriverOpen()
            Return tmp
        End Get
    End Property

    Public Function ReadByte(ByVal PortAddress As Short) As Byte                        ' ### Read a byte.
        Dim Value As Byte = Nothing
        dwLastError = Nothing
        If IsParPortDriverOpen() = True Then                                            ' Check if InpOut32 is installed and hooked
            Try                                                                         ' and set 64-bits flag if necessary.
                If m_bX64 = False Then
                    Value = Convert.ToByte(NativeMethods.Inp32(PortAddress))                          ' Read with 32-bits lib.
                Else
                    Value = Convert.ToByte(NativeMethods.Inp32_x64(PortAddress))                      ' Read with 64-bits lib.
                End If
            Catch ex As System.OverflowException                                        ' Handle the overflow exception from conversion.
            Catch ex As Exception                                                       ' Any other exception set the error code.
                dwLastError = System.Runtime.InteropServices.Marshal.GetLastWin32Error
            End Try
        End If
        Return Value                                                                    ' Return the byte. (0 if there was an error)
    End Function

    Public Function WriteByte(ByVal PortAddress As Short, ByVal Value As Byte) As Boolean
        Dim nResult As Boolean = True
        dwLastError = Nothing
        If IsParPortDriverOpen() = True Then
            Try
                If m_bX64 = False Then
                    NativeMethods.Out32(PortAddress, CShort(Value))
                Else
                    NativeMethods.Out32_x64(PortAddress, CShort(Value))
                End If
            Catch ex As Exception
                dwLastError = System.Runtime.InteropServices.Marshal.GetLastWin32Error
                nResult = False
            End Try
        End If
        Return nResult
    End Function

    Public Function ReadWord(ByVal PortAddress As Short) As UInt16                      ' ### Read a word.
        Dim Value As UInt16 = Nothing
        dwLastError = Nothing
        If IsParPortDriverOpen() = True Then                                            ' Check if InpOut32 is installed and hooked
            Try                                                                         ' and set 64-bits flag if necessary.
                If m_bX64 = False Then
                    Value = Convert.ToUInt16(NativeMethods.Inp32(PortAddress))                        ' Read with 32-bits lib.
                Else
                    Value = Convert.ToUInt16(NativeMethods.Inp32_x64(PortAddress))                    ' Read with 64-bits lib.
                End If
            Catch ex As Exception                                                       ' Any exception set the error code.
                dwLastError = System.Runtime.InteropServices.Marshal.GetLastWin32Error
            End Try
        End If
        Return Value                                                                    ' Return the word. (0 if there was an error)
    End Function

    Public Function WriteWord(ByVal PortAddress As Short, ByVal Value As Short) As Boolean
        Dim nResult As Boolean = True
        dwLastError = Nothing
        If IsParPortDriverOpen() = True Then
            Try
                If m_bX64 = False Then
                    NativeMethods.Out32(PortAddress, Value)
                Else
                    NativeMethods.Out32_x64(PortAddress, Value)
                End If
            Catch ex As Exception
                dwLastError = System.Runtime.InteropServices.Marshal.GetLastWin32Error
                nResult = False
            End Try
        End If
        Return nResult
    End Function

    Private Function IsParPortDriverOpen() As Boolean
        Dim nResult As UInt32
        dwLastError = Nothing
        Try
            nResult = NativeMethods.IsInpOutDriverOpen()
        Catch ex As Exception
            nResult = NativeMethods.IsInpOutDriverOpen_x64()
            If (nResult <> 0) Then
                m_bX64 = True
            End If
        End Try
        If nResult = 0 Then
            dwLastError = System.Runtime.InteropServices.Marshal.GetLastWin32Error
        End If
        Return CBool(nResult)
    End Function
End Class


NativeMethods.vb:

Imports System.Runtime.InteropServices

Friend NotInheritable Class NativeMethods
    <DllImport("InpOut32.dll", CharSet:=CharSet.Auto, EntryPoint:="Inp32")> _
    Friend Shared Function Inp32(ByVal PortAddress As Short) As Short
    End Function

    <DllImport("InpOut32.dll", CharSet:=CharSet.Auto, EntryPoint:="Out32")> _
    Friend Shared Sub Out32(ByVal PortAddress As Short, ByVal Data As Short)
    End Sub

    <DllImport("InpOut32.dll", CharSet:=CharSet.Auto, EntryPoint:="IsInpOutDriverOpen")> _
    Friend Shared Function IsInpOutDriverOpen() As UInt32
    End Function

    <DllImport("InpOutx64.dll", CharSet:=CharSet.Auto, EntryPoint:="Inp32")> _
    Friend Shared Function Inp32_x64(ByVal PortAddress As Short) As Short
    End Function

    <DllImport("InpOutx64.dll", CharSet:=CharSet.Auto, EntryPoint:="Out32")> _
    Friend Shared Sub Out32_x64(ByVal PortAddress As Short, ByVal Data As Short)
    End Sub

    <DllImport("InpOutx64.dll", CharSet:=CharSet.Auto, EntryPoint:="IsInpOutDriverOpen")> _
    Friend Shared Function IsInpOutDriverOpen_x64() As UInt32
    End Function

End Class
 
Last edited:
Also, be aware that most receipt printers come with Windows drivers nowadays, and if a driver is installed you will not be able to hook with the printer via InpOut32.
 
Back
Top