como abrir el puerto LPT1

17/08/2006 - 17:55 por Miguel Arenas | Informe spam
antes en vb 6 podia abrir el puerto LPT1 utilizando la instruccion
Open "\\Computadora\LPT1" For Output As #1

alguien sabe como se puede hacer esto eb VB.Net
 

Leer las respuestas

#1 Roberto
22/08/2006 - 18:01 | Informe spam
Yo utilizo este método para enviar códigos de escape a la impresora, a ver si
te sirve.

Necesitas estas declaraciones:
Public Const GENERIC_WRITE = &H40000000
Public Const OPEN_EXISTING = 3
Public Const FILE_SHARE_WRITE = &H2
Public LPTPORT As String
Public hPort As Integer
Public 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

Por ejemplo con este abro un cajón portamonedas conectado a una Epson:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim SA As SECURITY_ATTRIBUTES
Dim outFile As System.IO.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)
'hPortP, IO.FileAccess.Write, False)
Dim fileWriter As New System.IO.StreamWriter(outFile)
fileWriter.Flush()
fileWriter.WriteLine(Chr(27) & Chr(112) & 0) 'abrir cajón
fileWriter.Flush()
fileWriter.Close()
CloseHandle(hPort)
End Sub


"Miguel Arenas" wrote:

antes en vb 6 podia abrir el puerto LPT1 utilizando la instruccion
Open "\\Computadora\LPT1" For Output As #1

alguien sabe como se puede hacer esto eb VB.Net

Preguntas similares