Connecting to printer via TCP/IP

From QB64 Wiki
Jump to navigation Jump to search

Although you cannot use LPRINT if you are not using Windows, you can still send raw data to a printer by connecting to it using TCP/IP. The code below showcases how to do so.


'TCP/IP Printing '******************************** 'this explains how to connect to a printer and send raw text to the printer 'this is very useful to linux users who cant use the LPRINT command. '******************************** DIM PrinterConnect AS LONG DIM CRLF AS STRING DIM CRFF AS STRING DIM LinePrint AS STRING CRLF$ = CHR$(13) + CHR$(10) ' end current print line and starts new line FF$ = CHR$(12) ' end current print line and finish printing CLS PrinterConnect = _OPENCLIENT("TCP/IP:9100:***.***.***.***") 'Replace asterisks with your printer's IP address. Opens a connection to your printer IF PrinterConnect THEN PRINT "[Connected to " + _CONNECTIONADDRESS(PrinterConnect) + "]" ELSE PRINT "[Connection Failed!]" END IF printstring1$ = "this is a printed line" + CRLF$ PRINT INPUT "please enter the name of the file you want to print>", FileName$ OPEN FileName$ FOR INPUT AS #1 DO LINE INPUT #1, LinePrint$ PrintString$ = LinePrint$ + CRLF$ PUT #PrinterConnect, , PrintString$: LOOP UNTIL EOF(1) PUT #PrinterConnect, , FF$

Thanks to SpriggsySpriggs and Atomic Kevin for the code above