Jump to content




Network Printing with more than 1 Printer

networking peripheral lua

2 replies to this topic

#1 Asrothear

  • New Members
  • 2 posts

Posted 23 May 2017 - 08:06 AM

I work on a program which allows to choose one Printer in a network with multiple printers.
Works fine til the print process, there are no errors. Any Ideas?
--Beta Program for Network Printing for ComputerCraft
print("Choose Printer 10-13")
Nr=read()
local Prin = "printer_"
local printer = Prin..Nr
print(" "..printer.." ")
sleep(2)
local modem = printer
printer.newPage()
printer.write("Test")
printer.endPage()

Edited by Asrothear, 23 May 2017 - 01:36 PM.


#2 Asrothear

  • New Members
  • 2 posts

Posted 23 May 2017 - 11:05 AM

Found the sulution myself
--Beta Program for Network Printing for ComputerCraft

print("Choose Printer 10-13") -- 10-13 as example
  nr=read()

local prin = "printer_"
 local pri = prin..nr

printer = peripheral.wrap(""..pri.."")

printer.newPage()
printer.write("Test")
printer.endPage()

term.clear()
print("Printing finished")
sleep(2)

Any suggetions how to make this better and create a code which allows me to define the printet text as variable with a automatic line switch ?
Like this:
local msg = "Hello"
letters = string.len(msg)
msg:len()
if letters =< 16
printer.setCusorPos(1,2+1)
end
Sometihng like this

#3 Bambel Boar

  • Members
  • 8 posts
  • LocationUnited States

Posted 11 June 2017 - 03:56 PM

I think you're over-complicating. Can you not just wrap individual printers on a wired network in individual variables:
pZero=peripheral.wrap("printer_0")
pOne=peripheral.wrap("printer_1")

Then do the print functions:
pZero.newPage()
pZero.write("This is printer_0")
pZero.endPage()

pOne.newPage()
pOne.write("This is printer_1")
pOne.endPage()

EDIT: Also rather than doing:
print(" "..printer.." ")

It's more efficient to do:
print(printer)

You don't need to concatenate a string with a space unless you were experimenting with screen size or something.

If this isn't what you were looking for sorry I don't understand lol

Edited by Weashoo, 11 June 2017 - 04:02 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users