Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Abrir el puerto LPT1 y mandarle imprimir

200 views
Skip to first unread message

Jesus Ramon Lopez Dominguez

unread,
Feb 6, 2007, 12:52:00 PM2/6/07
to
grupo
 
    como abro el puerto lpt1 y le mando imprimir directamente
 
 
    en el visual basic 6 lo hacia asi
 
    vlimp as integer
    vlimp = freefile
    open "lpt1" for output as vlimp
    print #vlimp, "Hola mundo"
    close (vlimp)
 
 
    y listo pero
 
    pero en vb.net como se hace?

--
Jesús Ramón López
e Soft del Pacífico S.C.
jrlo...@esoft.com.mx
www.esoft.com.mx
Tel: +52 (667) 712 2820

Alberto Poblacion

unread,
Feb 6, 2007, 1:09:41 PM2/6/07
to
"Jesus Ramon Lopez Dominguez" <jrlo...@hotmail.com> wrote in message

> como abro el puerto lpt1 y le mando imprimir directamente
> en el visual basic 6 lo hacia asi
> [...]

> open "lpt1" for output as vlimp
> print #vlimp, "Hola mundo"
> [...] pero en vb.net como se hace?


Imports System.IO
...
Dim sw as New StreamWriter("lpt1")
sw.WriteLine("Hola, mundo")
sw.Close()

Jesus Ramon Lopez Dominguez

unread,
Feb 6, 2007, 4:42:37 PM2/6/07
to
al tratar de abrir el puerto lpt1 me marca error,

FileStream will not open win32 devices such as disk partitions and tape
drives. avoid use of "\\.\" in the path


como locorrijo?


JRLD

"Alberto Poblacion" <earthling-quitae...@poblacion.org>
escribió en el mensaje news:%23JcI8nh...@TK2MSFTNGP03.phx.gbl...

Jesus Ramon Lopez Dominguez

unread,
Feb 6, 2007, 6:02:20 PM2/6/07
to
me marco error en el path
 
con "lpt1:"
 
 
que sera?, el control de visal basic  de CommendDialog por cual fue cambiado en el .net?
 
 
JRLD
"Jesus Ramon Lopez Dominguez" <jrlo...@hotmail.com> escribió en el mensaje news:uXi5EehS...@TK2MSFTNGP05.phx.gbl...

Armin Saez

unread,
Feb 7, 2007, 9:46:21 AM2/7/07
to
Hola
Para preguntas sobre visual.net dirigete a el grupo microsoft.public.vb.dotnet
Este grupo es para vb 6 e inferiores
 
En el otro grupo te pueden orientar mejor

--
-----------------------------
Sin mas, saluda atte. a Uds.
Armin Saez
 
PD: Me da flojera escribir los tildes.
"Jesus Ramon Lopez Dominguez" <jrlo...@hotmail.com> escribió en el mensaje news:OdimfLkS...@TK2MSFTNGP04.phx.gbl...

Jesus Ramon Lopez Dominguez

unread,
Feb 7, 2007, 9:25:06 PM2/7/07
to
Alberto el ejemplo que me mandaste no me funsiona
me dice que no puede abrir el path, a ti si te jalo?


JRLD

"Alberto Poblacion" <earthling-quitae...@poblacion.org>
escribió en el mensaje news:%23JcI8nh...@TK2MSFTNGP03.phx.gbl...

Alberto Poblacion

unread,
Feb 8, 2007, 3:01:08 AM2/8/07
to
"Jesus Ramon Lopez Dominguez" <jrlo...@hotmail.com> wrote in message
news:el7ochyS...@TK2MSFTNGP03.phx.gbl...

> Alberto el ejemplo que me mandaste no me funsiona
> me dice que no puede abrir el path, a ti si te jalo?

No. Acabo de probarlo, y funciona con ficheros normales pero no funciona
con "lpt1" ni con "lpt1:" ni con "lpt1.dos". Me temo que no va a haber mas
remedio que usar P/Invoke para llamar a las APIs de Windows, tales como
CreateFile. En el primero de los enlaces que te indico a continuación viene
la forma de declarar las llamadas en VB, y el texto indica que el "handle"
que te devuelve el CreateFile se puede usar en .Net para inicializar un
FileStream, y menciona expresamente que esto vale para abrir "lpt1:".

http://www.pinvoke.net/default.aspx/kernel32/CreateFile.html
http://msdn2.microsoft.com/en-us/library/aa363858.aspx


Jesus Ramon Lopez Dominguez

unread,
Feb 8, 2007, 3:12:11 AM2/8/07
to
ya lo hice asi usando la api y me marca este error "Invalid Handle"
 
te anexo el codigo para que lo analises, gracias...
 
 

Imports System

Imports Microsoft.VisualBasic

Imports System.IO

Imports Microsoft.Win32

Public Class Form1

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

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

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)

Dim fileWriter As New StreamWriter(outFile)

fileWriter.WriteLine(Chr(27) & Chr(112) & 0) 'abrir cajón

fileWriter.WriteLine(" " & " Empresa")

fileWriter.WriteLine(" " & "Articulo " & " Precio " & " Cantidad " & " Total ")

fileWriter.WriteLine(" " & "---------------------------------------")

fileWriter.Close()

End Sub

End Class

"Alberto Poblacion" <earthling-quitae...@poblacion.org> escribió en el mensaje news:OWAJPd1S...@TK2MSFTNGP05.phx.gbl...

Alberto Poblacion

unread,
Feb 8, 2007, 5:13:27 AM2/8/07
to
"Jesus Ramon Lopez Dominguez" <jrlo...@hotmail.com> wrote in message
news:%23zP4Yj1...@TK2MSFTNGP03.phx.gbl...

> ya lo hice asi usando la api y me marca este error "Invalid Handle"

Fíjate que tienes el CreateFile declarado como "As Integer", y que tal
como te advierten en
http://www.pinvoke.net/default.aspx/kernel32/CreateFile.html, eso solo
funciona con VB2003. Con el 2005 hay que usar un SafeFileHandle en lugar del
Integer.

0 new messages