Computer Science Canada

[Tutorial] How to make your turing programs use the printer.

Author:  Dan [ Wed Aug 21, 2002 1:54 pm ]
Post subject:  [Tutorial] How to make your turing programs use the printer.

How to uses to a printer in Turing


It a simple code but you have to have a printer that is on LPT1 or on another LPT port.


The code:


code:

var dataout :int %the var can have any name you want

open: dataout, "LPT1", put %set the file name to the port of your printer
put:dataout, "STRING TO SEND TO PRINTER" %string to print
close: dataout %close the connection to the printer


Ex.

code:

var dataout :int
var name, address, age, phone :string

put "Address book maker 3000"
put ""
put ""
put "Name: "..
get name
put "Age: "..
get age
put "Phone Number: "..
get phone
put "Address: "..
get address

cls
open: dataout, "LPT1", put
put:dataout, name, "      ", age
put:dataout, " "
put:dataout, address
put:dataout, phone
close: dataout %close the connection to the printer




if you have any questions or coments about this tutorial RE and let us know.

Author:  Blindmelon_53 [ Wed Apr 21, 2004 9:16 am ]
Post subject: 

I know this is an old topic but I was going to ask if anyone knows if there is any way that you could set it up so that you could use a network printer when you have the ip of the printer. Thanks

Author:  Dan [ Wed Apr 21, 2004 12:31 pm ]
Post subject: 

humm intresting question. in windows u can make a netwrok printer maped to a priter port and it whould work then, but this whould have to be done out side of turing and could not be done by turing.

you could try puting in the network path to the priter but i do not think that will work for some reason. also the net comands may make it posable if u whont to try to figger out the protcal used to send network print jobs.

Author:  Blindmelon_53 [ Wed Apr 21, 2004 1:24 pm ]
Post subject: 

Im going to try and figure out what you said about the protocol and mapping idea through windows. Ill post my progress.

The reason I origonally posted the question is because at school we use a network printer which has an ip address. Now if I had any rights what so ever on the computers I might be able to try to map the printer or find the protocol used for printing on a network but that is all blocked, we cant even right click in anything except a word processor Laughing lol which is why I was wondering about the command through turing but like I said I'll try to figure out the above at home and ill post my progress.

Thanks Hacker Dan

Author:  Dan [ Wed Apr 21, 2004 5:21 pm ]
Post subject: 

ya my shcool has the same no rights system. u probly will not be able to get it to print over the netwrok unless there is some new turing comand or seting to 4.x or 4.0.5 that i am unaware of. to figger out the proticals u will ether have to look them up on some site or get a packsniffer and see how it all works.

Author:  Delos [ Wed Apr 21, 2004 7:07 pm ]
Post subject: 

I remember something like this from my compSci class. We had a network printer, and just using the usual LPT worked fine printing to that printer.

However, I doubt that answers your question. To print to a seperate IP, i.e. a printer in a room to which your computer is not currently associated with...you'd probably have to outsource it. I don't think Turing can handle that...

Author:  Tony [ Wed Apr 21, 2004 7:24 pm ]
Post subject: 

well you could sent data directly to the IP using Net. stream but I have no idea how that would be interprited on the other side Confused maybe if you had a server side app that would recieve the file, buffer it and print it locally Laughing

Author:  Blindmelon_53 [ Thu Apr 22, 2004 7:32 am ]
Post subject: 

I havn't been able to work on the ip address printing since I havent been at school but I decided to look at USB printing. I havnt seen anyone get it to work yet but what I've been trying to do is to sub where Dan's program says LPT1 with the direct command to my USB printer but I was unsuccessful with that, so I figured I would just link it to the USB port since all the LPT1 is is a port, but still no go. Does anyone have any suggestions for this? Thanks

This is one example of what I have been doing:
code:

var dataout :int %the var can have any name you want

open: dataout,"C:/windows/system32/drivers/USBPRINT.SYS ", put

put:dataout, "STRING TO SEND TO PRINTER" %string to print
close: dataout %close the connection to the printer

Author:  Blindmelon_53 [ Thu Apr 22, 2004 8:09 am ]
Post subject: 

OK guys progress on USB printing made. The way my printer works it will turn on when data is sent to it which is what is happening now when I run the program however it still will not print anything. The way you have to call your printer is
1. You have to share your printer (like you would on a network)
2. You need to know your computer name (put Sys.GetComputerName works)
3.you call it like a network printer (ie. //ATHLONXP/Lexmark )
ATHLONXP being the computer name of course and Lexmark the printer
EXAMPLE

code:

var dataout :int %the var can have any name you want

open: dataout,"//ATHLONXP/Lexmark ", put %set the file name to the port of your printer

put:dataout, "STRING TO SEND TO PRINTER" %string to print
close: dataout %close the connection to the printer


That all there is to getting your programs to recognize a USB printer.
Now as far as printing I'm not sure. It seems like the document to be printed is so small that it cant even print for some reason.

When I run the program it spools and everything and the printer makes the noise like when you turn it on but it wont print. Ill keep working on it any way.

As for using a network printer at school, I think if you could get the share name of the printer you could easily call the printer the same way we did here. Another posibility could be that you type a line like this //RM-213/IP ADDRESS HERE . Anyways gonna go eat.

IDEAS ALWAYS WELCOME

Author:  Jas [ Tue May 10, 2005 9:42 am ]
Post subject: 

wat if u want to print out the output that is on the screen? Can u somehow save the output on a variable and put it in the "STRING TO SEND TO PRINTER" part?

Author:  Andy [ Tue May 10, 2005 6:38 pm ]
Post subject: 

if its on the screen, then why not just click the print button in the gui bar?

Author:  Jas [ Tue May 10, 2005 9:23 pm ]
Post subject: 

ya i know about that, but my teacher said the program should give the user an option if he wants to print the output. (in this case a customer bill).

Author:  Tony [ Wed May 11, 2005 1:55 pm ]
Post subject: 

Jas wrote:
the program should give the user an option if he wants to print the output. (in this case a customer bill).

well the user has an option to press that print button Wink

anyways, a bill is all text, there are no loaded .jpg images (well not supposed to be), so just send that string to the printer.

And by that I ofcourse mean all your data should be in variables and you're supposed to be able to put the text together again. Or just keep a vertual buffer somewhere and add info to it every time you add something new to the screen.

Author:  beard0 [ Mon Sep 19, 2005 12:24 pm ]
Post subject:  Re: [Tutorial] How to make your turing programs use the prin

This code allows you to print to any printer installed (user's choice). It pops up the normal dialogue with # of copies, print range, etc.
code:

var dataout :int %the var can have any name you want

open: dataout, "printer", put %yes, litterally the string "printer"
put:dataout, "STRING TO SEND TO PRINTER" %string to print
close: dataout %close the connection to the printer

Author:  jamonathin [ Tue Feb 21, 2006 12:57 pm ]
Post subject: 

I know this is an old topic, but I have a question.

I know you cannot print images in turing without using the print button located at the top of the page. But if you compile your program into .exe format, the print button doesn't work. I'm guessing Turing doesn't throw that info in when compliling. Anyone know a way around this?

Author:  Dan [ Tue Feb 21, 2006 2:29 pm ]
Post subject: 

jamonathin wrote:
I know you cannot print images in turing without using the print button located at the top of the page. But if you compile your program into .exe format, the print button doesn't work. I'm guessing Turing doesn't throw that info in when compliling. Anyone know a way around this?


The 1st thing that comes to mind whould be calling a progame not made in turing threw turing to do the job. Tho when turing gets complied odd things start happening and even that may not work.

Another idea whould be to use turings ablity to save images from it's drawing screen. You could save the screen to a bmp file and then maybe there is a way to call paint where it will print the file. Tho this whould be largery dependtent on ms paint and that is never good.

My recomendation whould be to just save the screen using turings pics comands and tell the user where it is or let them pic where to put it.

Author:  jamonathin [ Thu Feb 23, 2006 4:06 pm ]
Post subject: 

Ok Dan, sounds good. Thanks Smile

Author:  efan41 [ Tue Dec 08, 2009 2:37 pm ]
Post subject:  Re: [Tutorial] How to make your turing programs use the printer.

is it possible to use a flexible array : string instead of actual text to send to printer, because I'm trying and it's giving me the header but not the text it's supposed to be printed.

code:
[syntax="Turing"]
open : dataout, "printer", put
    for c : 1 .. t - 1
        put : dataout, character (t)
    end for
    close : dataout
[/syntax]


Please help ASAP it's part of a project due next friday

Author:  mirhagk [ Tue Dec 08, 2009 2:48 pm ]
Post subject:  RE:[Tutorial] How to make your turing programs use the printer.

the problem does not lie in the printing code, but is there anything in character?? please post more code so I can see the problem.

Author:  Superskull85 [ Tue Dec 08, 2009 3:04 pm ]
Post subject:  Re: [Tutorial] How to make your turing programs use the printer.

efan41 @ Tue Dec 08, 2009 2:37 pm wrote:
is it possible to use a flexible array : string instead of actual text to send to printer, because I'm trying and it's giving me the header but not the text it's supposed to be printed.

code:
[syntax="Turing"]
open : dataout, "printer", put
    for c : 1 .. t - 1
        put : dataout, character (t)
    end for
    close : dataout
[/syntax]


Please help ASAP it's part of a project due next friday

In your code t is the upper index of your array, and c is the incremental value. Just swap those two and you should be fine.

Author:  mirhagk [ Tue Dec 08, 2009 3:07 pm ]
Post subject:  RE:[Tutorial] How to make your turing programs use the printer.

oh yeah sorry I didn't even catch that, lol sorry long night yeah right now all your code does is print the last variable over and over


: