Interfacing the LPT port...

I have a small 3-line LCD display that is connected via an LPT port. Just curious, but has anybody ever worked with something similar via RB/Xojo… or even sent data directly to an LPT port via RB/Xojo or even Visual Basic (that could be adapted and moved over)?

I haven’t seen a computer with an LPT port in 10 years or so.

Maybe an LPT to USB adapter would allow you to accessing it using the Serial class?

Xojo has no facility for working with the LPT port. You can use declares, I believe. I think there were some in the WFS.

Aaron once wrote a post on his now defunct blog.
I dont think he incorporated that one into the book though.
Not sure if the example made it into the internet way back machine

Appreciate the feedback, gentlemen. I got a solution to work by writing the text to a temp text file, then using shell to run a DOS command such as “copy temp.txt lpt1:” which worked just fine.

Maybe this information can be useful: http://forums.realsoftware.com/viewtopic.php?f=1&t=36609&hilit=printer+port

And the archive link: http://web.archive.org/web/20090708071141/http://www.aaronballman.com/programming/REALbasic/InpOut32RB.php

If someone with a PC and some time to translate it from VB6 to Xojo and test it, using Win32 were something like this:


Const GENERIC_WRITE = &H40000000
Const GENERIC_READ = &H80000000
Const FILE_ATTRIBUTE_NORMAL = &H80
Const OPEN_EXISTING = 3
Const INVALID_HANDLE_VALUE= -1

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Function WriteFile Lib "kernel32" ( _
        ByVal hFile As Long, lpBuffer As Any, _
        ByVal nNumberOfBytesToWrite As Long, _
        lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long

Private Declare Function CreateFile Lib "kernel32" _
        Alias "CreateFileA" (ByVal lpFileName As String, _
        ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, _
        ByVal lpSecurityAttributes As Long,  _
        ByVal dwCreationDisposition As Long, _
        ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) _
        As Long


Sub SendDataToLPT1(s As String)
      Dim myHandle As Long
      Dim BytesSent As Long
      myHandle=CreateFile("LPT1", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
      WriteFile myHandle, s, len(s), BytesSent, 0
      CloseHandle myHandle
End Sub