Repository navigation
Open Lpt
Home › File I/O Functions › Open Lpt
Opens a printer on a file number, so Print # and Put # send data to it.
Open Lpt ["[LPT[x]:][Printer_Name][,TITLE=Doc_Title][,EMU=TTY]"] [For Input|Output] As #filenumberxPrinter_NameTITLE=Doc_TitleEMU=TTYfilenumber
Open Lpt opens a connection to a printer device. The connection is treated like a file, so data may be written to the printer using Print and Put # commands.
Any printer attached to the system may be opened with Open Lpt
Open Lpt "LPT:" ... will try to open the default printer on Windows and Linux, and "LPT1:" on DOS.
LPrint will automatically try to open the default printer on Windows and Linux, and "LPT1:" on DOS.
The error code returned by Open Lpt can be checked using Err in the next line. The function version of Open Lpt returns directly the error code as a 32 bit Long.
Platform specific notes:
Windows
The argument EMU=TTY assumes printable ASCII or Unicode text, and applies printer driver text imaging to the input. EMU=TTY also allows the usage of CR, LF, BS, TAB, FF, etc., for virtual print-head movement...even when the printer is a GDI printer and therefore doesn't itself understand these special characters. If ",EMU=TTY" is omitted, the data must be sent in the printer's language (ESC/P, HPGL, PostScript, etc...). Other useful emulation modes aren't supported yet.
Linux
A printer spooler available through lp must be installed to access printers by name or a default printer. Spooler access was tested only with CUPS, but other spoolers may work that are invoked through lp. Port are zero-based on Linux. "LPT1:" corresponds with "/dev/lp0".
The data must be sent in the printer's language (ESC/P, HPGL, PostScript, etc...). Emulation modes aren't supported yet.
DOS
FreeBASIC does not support print spoolers on DOS. Printers must be accessible through "LPTx:".
The data must be sent in the printer's language (ESC/P, HPGL, PostScript, etc...). Emulation modes aren't supported yet.
A 32 bit Long: 0 is returned if Open Lpt() completed successfully, otherwise a non-zero value is returned to indicate failure.
Open Lpt "LPT..." As [#]filenumber
or
result = Open Lpt( "LPT..."[,] As [#]filenumber )- In the -lang qb dialect the old syntax is supported OPEN "LPT:..." . This syntax used in the other dialects will open a regular file.
' Send some text to the Windows printer on LPT1:, using driver text imaging.
Open Lpt "LPT1:EMU=TTY" For Output As #1
Print #1, "Testing!"
Close' Sends contents of text file test.txt to Windows printer named "ReceiptPrinter"
Dim RptInput As String
Dim PrintFileNum As Long, RptFileFileNum As Long
RptFileFileNum = FreeFile
Open "test.txt" For Input As #RptFileFileNum
PrintFileNum = FreeFile
Open Lpt "LPT:ReceiptPrinter,TITLE=ReceiptWinTitle,EMU=TTY" As _
#PrintFilenum
While (EOF(RptFileFileNum) = 0)
Line Input #RptFileFileNum, RptInput
Print #PrintFileNum, RptInput
Wend
Close #PrintFileNum ' Interestingly, does not require CHR(12). But if pagination is desired, CHR(12) is the way.
Close #RptFileFileNum
Print "Press any key to end program..."
GetKey
End'This simple program will print a PostScript file to a PostScript compatible printer.
Dim As Long FFI, PPO
Dim As String temp
FFI = FreeFile()
Open "sample.ps" For Input Access Read As #FFI
PPO = FreeFile()
Open Lpt "LPT1:" For Output As #PPO
While (EOF(FFI) = 0)
Line Input #FFI, temp
Print #PPO, temp
Wend
Close #FFI
Close #PPO
Print "Printing Completed!"Category: File I/O Functions
Kind: keyword
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing