Primero declaras esto:
Public Const GENERIC_WRITE = &H40000000
Public Const OPEN_EXISTING = 3
Public Const FILE_SHARE_WRITE = &H2
Public LPTPORT As String
Public hPort As Integer, hPortP As IntPtr
Public retval As Integer
Public Declare Function CreateFile Lib "kernel32" Alias
"CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As
Integer, _
ByVal dwShareMode As Integer, ByRef lpSecurityAttributes As
SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Integer, _
ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As
Integer) As Integer
Public Declare Function CloseHandle Lib "kernel32" Alias
"CloseHandle" (ByVal hObject As Integer) _
As Integer
Public Structure SECURITY_ATTRIBUTES
Private nLength As Integer
Private lpSecurityDescriptor As Integer
Private bInheritHandle As Integer
End Structure
luego haces esto :
Dim SA As SECURITY_ATTRIBUTES
Dim outFile As FileStream
LPTPORT = "LPT1"
hPort = CreateFile(LPTPORT, GENERIC_WRITE, FILE_SHARE_WRITE,
SA, OPEN_EXISTING, 0, 0)
hPortP = New IntPtr(hPort) 'convert Integer to IntPtr
outFile = New FileStream(hPortP, FileAccess.Write, False)
Dim fileWriter As New StreamWriter(outFile)
fileWriter.WriteLine(Chr(27) & Chr(112) & 0) 'abrir cajón
fileWriter.WriteLine(" " & " Empresa")
fileWriter.WriteLine(" " & " se dedica a ")
fileWriter.WriteLine(" " & " CIF :111111111")
fileWriter.WriteLine(" " & " Fecha : " & Today)
fileWriter.WriteLine(" " &
"---------------------------------------")
fileWriter.WriteLine(" " & "Articulo " & " Precio " & "
Cantidad " & " Total ")
fileWriter.WriteLine(" " &
"---------------------------------------")
Es para imprimir tickets directamente a travez de impresoras con caja
registradora.
Espero que te sirva, a mi me sirvió.Saludos
Fernando
He añadido el SafeFileHandle y funciona bien, y si fuera necesario nos
permite cambiar el tamaño del buffer.
Dim SA As SECURITY_ATTRIBUTES
Dim outFile As FileStream
LPTPORT = "LPT1"
hPort = CreateFile(LPTPORT, GENERIC_WRITE, FILE_SHARE_WRITE, SA,
OPEN_EXISTING, 0, 0)
hPortP = New IntPtr(hPort) 'convert Integer to IntPtr
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim Safe As New Microsoft.Win32.SafeHandles.SafeFileHandle(hPortP,
True)
outFile = New System.IO.FileStream(Safe, IO.FileAccess.Write) 'Aquí
podemos cambiar el tamaño del buffer.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim fileWriter As New StreamWriter(outFile)
fileWriter.WriteLine(Chr(27) & Chr(112) & 0) 'abrir cajón
fileWriter.WriteLine(" " & " Empresa")
fileWriter.WriteLine(" " & " se dedica a ")
.....