QB64.org Forum

Active Forums => Programs => Topic started by: AtomicSlaughter on February 04, 2021, 02:29:52 pm

Title: TCP/IP Printer
Post by: AtomicSlaughter on February 04, 2021, 02:29:52 pm
So i wrote a program that will print a file to printer in raw text.

I needed this as the LPRINT command is unavailable on LINUX.

I hope this file is helpful to you all.

Code: QB64: [Select]
  1. DIM PrinterConnect AS LONG
  2. DIM LinePrint AS STRING
  3. CRLF$ = CHR$(13) + CHR$(10) ' end current print line and starts new line
  4. FF$ = CHR$(12) ' end current print line and finish printing
  5. ESC$ = CHR$(27)
  6. PrinterConnect = _OPENCLIENT("TCP/IP:9100:***.***.***.***") 'replace astrix with your printers IP address. opens a connection to your printer
  7. IF PrinterConnect THEN
  8.     PRINT "[Connected to " + _CONNECTIONADDRESS(PrinterConnect) + "]"
  9. ELSE PRINT "[Connection Failed!]"
  10.  
  11. printstring1$ = "this is a printed line" + CRLF$
  12.  
  13. INPUT "please enter the name of the file you want to print>", FileName$
  14. OPEN FileName$ FOR INPUT AS #1
  15.     LINE INPUT #1, LinePrint$
  16.     PrintString$ = LinePrint$ + CRLF$
  17.     PUT #PrinterConnect, , PrintString$:
  18. PUT #PrinterConnect, , FF$
Title: Re: TCP/IP Printer
Post by: FellippeHeitor on February 04, 2021, 02:40:28 pm
That's very useful! Thanks for sharing, this definitely needs to have a mention in the Wiki for non-Windows users.

Also, thanks @SpriggsySpriggs for pointing it out in the chat at Discord (http://discord.qb64.org).
Title: Re: TCP/IP Printer
Post by: Pete on February 04, 2021, 03:14:56 pm
I'll have to assume Fell checked it out on his Linux system, so it works, as advertised. This would be a great addition to the Wiki. I was thinking of how to work something similar to this into my WP, for non-Windows users. Adding this might be the ticket.

Pete

Title: Re: TCP/IP Printer
Post by: FellippeHeitor on February 04, 2021, 03:45:31 pm
I didn't test it myself, but I followed Atomic as he tested and tweaked this until it worked in this final form he published.
Title: Re: TCP/IP Printer
Post by: SpriggsySpriggs on February 04, 2021, 06:17:38 pm
That's very useful! Thanks for sharing, this definitely needs to have a mention in the Wiki for non-Windows users.

Also, thanks @SpriggsySpriggs for pointing it out in the chat at Discord (http://discord.qb64.org).

No problem. Glad Atomic got to make use of something I used at work.
Title: Re: TCP/IP Printer
Post by: AtomicSlaughter on February 04, 2021, 06:25:57 pm
Thank you for your help with this SpriggsySpriggs