Jump to content




Peripheral Scanner

utility

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

#1 tommyroyall

  • Members
  • 136 posts

Posted 20 February 2013 - 10:18 AM

Peripheral Scanner


I have created a program of which will scan all 6 sides of your computer and then print what the peripheral types are. I encountered a need for this program when I was attempting to write something to find and register all modems and iron note blocks from Miscperiphals. I refined the program a little bit and decided that it is just good enough to be put up on the forums :). I didn't put any screenshots up because all it does is print out whatever is there, so lets say you have a disk drive below and a modem on the right of your computer, this would be the output:

Bottom: drive
Right: modem


Code: http://pastebin.com/kRXtZ95X



#2 masterdisasterHD

  • Members
  • 172 posts
  • LocationThe Netherlands

Posted 18 June 2013 - 01:57 AM

function getType(side)
 if peripheral.isPresent(side) then
  print(side..": "..peripheral.getType(side))
 else
  print(side..": none")
 end
end

function getMethods(side)
 if peripheral.isPresent(side) then
  A = peripheral.getMethods(side)
  if type(A) == "table" then
   for i,v in ipairs(A) do print(v) end
  elseif type(A) ~= "table" and A ~= nil then
   print(A)
  else
   print("Error")
  end
 else
  print("No peripheral to check on "..side)
 end
end

this should improve it a bit

#3 jesusthekiller

  • Banned
  • 562 posts
  • LocationWrocław, Poland

Posted 18 June 2013 - 07:56 AM

Just FYI you could do it In 3-5 lines...
for k, v in ipairs ({'top', 'bottom', 'left', 'right', 'front', 'back'}) do
print(v..": "..(peripheral.getType(v) or 'empty'))
end
Untested tho

#4 masterdisasterHD

  • Members
  • 172 posts
  • LocationThe Netherlands

Posted 18 June 2013 - 08:20 AM

View Postjesusthekiller, on 18 June 2013 - 07:56 AM, said:

Just FYI you could do it In 3-5 lines...
for k, v in ipairs ({'top', 'bottom', 'left', 'right', 'front', 'back'}) do
print(v..(peripheral.getType(v) or 'empty'))
end
Untested tho

ya can even make it shorter:

for k, v in pairs (rs.getSides()) do
print(v..(peripheral.getType(v) or 'empty'))
end


#5 jesusthekiller

  • Banned
  • 562 posts
  • LocationWrocław, Poland

Posted 18 June 2013 - 09:16 AM

Typed it using my tablet during break, sorry :P

#6 masterdisasterHD

  • Members
  • 172 posts
  • LocationThe Netherlands

Posted 18 June 2013 - 11:57 AM

me too :P but it works

#7 jesusthekiller

  • Banned
  • 562 posts
  • LocationWrocław, Poland

Posted 18 June 2013 - 01:06 PM

Good! :-)





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users