Recent

Author Topic: Print  (Read 11525 times)

DesJardins

  • New Member
  • *
  • Posts: 26
Print
« on: April 29, 2017, 06:55:22 pm »
Looking for simple text to printer.  LST does not seem to work like it did in old Turbo 4.  I don't need a canvas or buttons- just text print.
Python has a quick way to print to a file on disk, then send the file to a printer--open a file, write to it, close the file, then use operating system "startfile" to print it instantly.  Seems to work with all printers
Like this:

import sys
import os
print('check your printer')
sys.stdout = open('log.txt','w')
print('hey')
print( 'this is a test')
print('12356')
sys.stdout. close()

os.startfile("log.txt", "print")

Does FPC have something like this that I have not yet found?

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Print
« Reply #1 on: April 29, 2017, 07:11:41 pm »
Well, what are your problems with LST? .... because it is still supported:
Code: Pascal  [Select][+][-]
  1. program testprint;
  2. uses printer;
  3. begin
  4. writeln(LST, 'Hello world');
  5. end.

Specialize a type, not a var.

DesJardins

  • New Member
  • *
  • Posts: 26
Re: Print
« Reply #2 on: April 29, 2017, 09:25:07 pm »
I got the following:

Debugger Exception Notification
Project testprint raised exception class 'RunError(103)'
in file 'testprint.lpr' at line 4

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Print
« Reply #3 on: April 29, 2017, 09:35:17 pm »
On Windows it should include apptype:
Code: Pascal  [Select][+][-]
  1. program testprint;
  2. {$APPTYPE CONSOLE}
  3. uses printer;
  4. begin
  5. writeln(LST, 'Hello world');
  6. end.
Specialize a type, not a var.

DesJardins

  • New Member
  • *
  • Posts: 26
Re: Print
« Reply #4 on: April 29, 2017, 09:56:04 pm »
Project testprint raised exception class 'unknown'

at line 5

The printer is working.  I can use ctrl "P" and the printer prints out a copy of the whole program.

is there something that needs to be set in the "project options"?
« Last Edit: April 29, 2017, 10:10:44 pm by DesJardins »

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Print
« Reply #5 on: April 29, 2017, 10:06:47 pm »
That should be impossible, because that code does not even rely on object pascal modes. Which is necessary for "Exception class".....
I tested this code....
Maybe try this, because if there isn't any printer...:
Code: Pascal  [Select][+][-]
  1. program testprint;
  2. {$APPTYPE CONSOLE}
  3. uses printer;
  4. begin
  5.   if IsLstAvailable then
  6.      writeln(LST, 'Hello world')
  7.   else
  8.      writeln('There is no printer associated with the default PRN printer device');
  9. end.

If you have a Windows printer this may fail, but these cheapo printers are rare nowadays (because it was a bad idea).

Also note that TP4 executables would crash if there wasn't a printer.... Hence the check.
« Last Edit: April 29, 2017, 10:16:05 pm by Thaddy »
Specialize a type, not a var.

DesJardins

  • New Member
  • *
  • Posts: 26
Re: Print
« Reply #6 on: April 29, 2017, 10:18:03 pm »
the 'else' kicked in.

It's a modern, high-quality Brother printer.  How about some option that needs to be turned on? or off?

I'm using Windows 10
« Last Edit: April 29, 2017, 10:30:55 pm by DesJardins »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11382
  • FPC developer.
Re: Print
« Reply #7 on: April 29, 2017, 10:56:03 pm »
Did you check if the driver supports old dos compatibility devices?

Are you absolutely sure this setup works with TP4 ?

DesJardins

  • New Member
  • *
  • Posts: 26
Re: Print
« Reply #8 on: April 30, 2017, 05:00:21 am »
You can't run TP4 on 32 bit machine, but it worked on 16 bit for the last 25 years.  I'm trying to re-write for modern computer.

printer is working from computer, so it is in the compile.  How do I get it to recognize the printer?  Is there a test I can run?  What needs to change?

I couldn't get it to run on a Canon dot matrix printer either (both direct wired. )


Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Print
« Reply #9 on: April 30, 2017, 07:20:58 am »
Has nothing to do with TP4. It has to do with the fact that your printer is probably not connected to LPT1 (which is aliased PRN by definition) , but to another USB LPT. LPT3, maybe?
Check in the device manager. If that is the case, you can use InitPrinter to set the printer to a different name. In DOS days, there usually was just 1 printer device connected to the parallel port, not through a USB layer.

Example that prints to LPT3:
Code: Pascal  [Select][+][-]
  1. program testprint;
  2. {$APPTYPE CONSOLE}
  3. uses printer;
  4. begin
  5.   InitPrinter('LPT3');
  6.   if IsLstAvailable then
  7.      writeln(LST, 'Hello world')
  8.   else
  9.      writeln('There is no printer associated with the default PRN printer device');
  10.   readln;
  11. end.

You must use WMI (WBem object) to list, connect printers and ports.
The printer needs to support the LPR protocol, not just RAW.
It is by definition a lot more work than in the olden days if you do not manually set up the printer for every computer you run your software on...
« Last Edit: April 30, 2017, 09:02:52 am by Thaddy »
Specialize a type, not a var.

DesJardins

  • New Member
  • *
  • Posts: 26
Re: Print
« Reply #10 on: April 30, 2017, 05:05:34 pm »
Thaddy, Thanks for the help.  I don't have time to check it out this morning, but I do have a couple of other questions.

I want to write this to be and executable program that has a chance of running on almost anybody's modern printer.  It seems to me that not everybody will be using the same ports.  It seems like I need be getting to a USB port.  I don't think that is happening. 

That is one reason I was originally looking for code that would direct printing from a results file that I had just sent to the disk. Like I was doing in Python as described in my first post. (I save a file to the disk anyway because I use it be available to reload if somebody makes a mistake typing and they don't want to re-enter a lot of data to run it again -- saves them a lot of time). 
Now I am concerned that I don't have a "path" set to get from FPC or Lazarus to my printer.  Is "path" a problem?

So maybe the proper code for me is to not use the LST function.  Now what?  What is the simple way to send text output to any printer?

If you want to see the first program I am updating, check my web page www.rjdesjardins.com and look at the bottom for Psychrometric program.  Right now I am not even trying to use objects like buttons.  Just get it running.

thanks again, Richard

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Print
« Reply #11 on: April 30, 2017, 05:18:24 pm »
Last first: You don't need TButton etc objects..., you will need a COM object under windows (easy. There are already .vbs scripts on windows 10 that show you how)
Then:
- Yes, on a modern computer the default printer is obtainable, but not always where it used to be.
- A more modern approach, which will do much of the hard work, is using the printers unit (with an s, not printer without s that is needed just for LPT) and use the printer canvas. I will see if I can come up with an example for both.
Specialize a type, not a var.

DesJardins

  • New Member
  • *
  • Posts: 26
Re: Print
« Reply #12 on: May 01, 2017, 05:42:54 pm »
I sent an email to Brother printer people.  No response, yet.

I have been trying to use printer4lazarus, but can't that to work either. 

Seems there has to be an easy way to use FPC to tell the computer to print a text file that is on disk.

Is there a way to get FPC to search for a printer?

What is in the Printer and Printers codes?  What is in the printer4lazarus code? Are there any parameters that can be transmitted that will get things started?

Frustration

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Print
« Reply #13 on: May 01, 2017, 06:12:09 pm »
You think on the one hand too lazy (try to get things working the dos way without effort) and too complex.. Printing is harder than with DOS, but not THAT hard...
Again, if I have some time (left) I will give you two examples (one old skool, one printer canvas) . Can take two days, because it is busy here.
Specialize a type, not a var.

sky_khan

  • Guest
Re: Print
« Reply #14 on: May 01, 2017, 11:20:22 pm »
I wrote a proprietary text-mode reporting library long years ago for a company I worked for, using this approach
https://support.microsoft.com/en-us/help/138594/howto-send-raw-data-to-a-printer-by-using-the-win32-api
So, you can use "raw" mode to bypass processing and send whatever you like to printer, still using windows spooler.
But I have no experience on Linux or other OSes.

 

TinyPortal © 2005-2018