This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Wobbo's profile picture

Netprint, An Api For Easier Printing While Using Network Cables

Started by Wobbo, 02 November 2013 - 01:37 PM
Wobbo #1
Posted 02 November 2013 - 02:37 PM
Hello everybody,

I have written an API for easier printing when you have multiple printers in a network. It is not entirely done yet, but it should be useable.

It works by having one printer designated as the active printer, and it will forward all the print functions you call to this printer. The API supports all the functions of the native printer API. It is possible to manually or automatically select a printer as active printer. By default, it selects the printer that can print the most pages.

The API also allows the user to give labels to printers. This way, you can easily access printers, since you can give them a meaningful name.

The code can be found on pastebin: http://pastebin.com/Sg10An9P

The API selects a printer as active printer using the function comp. It takes two printers. It is possible to override this method if you want a different way to select printers. You can also set the active printer with setActivePrinter.

Labels are set using the setPrinterLabel, this function first takes the name of the printer in the network, followed by the label. The labels get stored in print.conf on your computer. If you want to change this, you can edit the variable config in the API.

Before you can use the API, you have to call the function init(). This function looks for printers in the network and makes sure one of them is designated as active printer. If you have used the API before, he will use the one you used last time. Otherwise, he will automatically select a printer among the network.

It is also possible to get a table with all the printers in the network, including the ink and paper levels. This can be done by using getPrinterTable for a table, and getPrinterTableString for a badly formatted string.

In combination with the standard printer API functions, a function called wrapWrite was added that prints the string it gets and makes sure it doesn't run of the page.

The API is not entirely done yet, I would like to add more comments in the code and do some minor improvements, but it should be useable. If you find any bugs or have any question on how to use it, please reply to this tread.
civilwargeeky #2
Posted 03 November 2013 - 04:04 PM
Neat API!
I tried it out and used it to make a leaflet maker. Just hooked up three printers and just looped init and start/print/end to make a bunch of papers. Cool API.
Wobbo #3
Posted 04 November 2013 - 01:39 PM
Good to hear that it worked for you ;)/>

I have updated the API, you don't have to call init() before you can use it anymore. I also added version(), print() and wrapPrint().
print() and wrapPrint() do the same as write() and wrapWrite() but set the cursor position at the first position in the new line.