Jump to content




Multiple Peripherals via Network Cable


  • You cannot reply to this topic
4 replies to this topic

#1 Left

  • Members
  • 88 posts

Posted 22 March 2013 - 08:50 PM

Hi,
I just had a crazy idea. I want to make a VERY basic program that can mass print a file you create. I just need to know if you can make a computer be assigned to multiple peripherals via a network cable. Thanks, Lin

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 22 March 2013 - 10:48 PM

Yes.

If you prefer to do it on your own, it's not that hard either:

local names = peripheral.call('sideYourModemIsOn', 'getNamesRemote')

for i=1, #names do
  if peripheral.getType(names[i]) == 'printer' then
    local printer = peripheral.wrap(names[i])
    printer.newPage()
    printer.setPageTitle('boop')
    printer.write('booooooooooooop')
    printer.endPage()
  end
end


#3 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 23 March 2013 - 01:04 AM

Why do people insist on making things difficult for themselves?

Do NOT call any modem functions directly. Just call peripheral.getNames().

#4 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 23 March 2013 - 03:04 AM

Well, cloudy, I used to do that, but the problem with that, is that it returns any and all usable peripherals, including those not connected through wired modems. You could get a table of names that looks like this if iterated and printed:

back
monitor_0
monitor_1
monitor_2
right
printer_0
printer_1
left
bottom
computer_5
computer_6

And I prefer just having more control over which peripherals I'm using. Just using getNames can become problematic if I have other peripherals connected on a different wired network for other purposes.

#5 MindenCucc

  • Members
  • 179 posts
  • Location/home/marcus/

Posted 23 March 2013 - 03:20 AM

I just wrote in 5 minutes a function for this :D

function getTypes(sType)
local fancyCrap = {}
local net = {}
local ret = {}
if sType == nil or type(sType) ~= "string" then
  error("Cannot parse input.", 1)
else
  net = peripheral.getNames()
  for asdX, valX in ipairs(net) do
   for netX = 1, #net do
    if peripheral.getType(valX) == sType then
	 retval=true
    else
	 retval=false
    end
   end
   if retval then
    table.insert(ret, valX)
   end
  end
  return ret
end
end

Usage: printers={}
printers=getTypes(string Type)

Example: {"printer_1", "left", "bottom"}





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users